Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
#include <stdlib.h>
#define SHORT 1
#define LONG 0

long hyouka(long n,long m,long book[101],long bookcase){
	long length,count = 0,i,j;
	for(i = 0 ;i < m ;i++){
		length = 0;
		for(j = 0;;j++){
			length = length + book[count];
			if(bookcase < length){
				break;
			}
			count++;
			
		}
	}
	
	if(count < n){
		return SHORT;
	}else{
		return LONG;
		}
}


long nibutan(long n,long m,long book[101]){
	long left = 0,right = 1500000,half,a;
	while(1){
		half = (right + left) / 2;
		//printf("%ld\t",half);
		
		a = hyouka(n,m,book,half);
		
		if(a == SHORT){
			left = half;
		}else if(a == LONG){
			right = half;
		}if(right == left || right == left + 1){
			break;
		}
		//printf("%ld %ld\n",left,right);
	}
	return right;
}


int main(void)
{
	long  n,m,book[101],answer,i;
	
	while(1){
		scanf("%ld %ld",&m,&n);
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(i = 0;i < n;i++){
			scanf("%ld",&book[i]);
		}
		
		answer = nibutan(n,m,book);
		
		printf("%ld\n",answer);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	hyouka
	.type	hyouka, @function
hyouka:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	%rcx, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L6:
	movq	$0, -32(%rbp)
	movq	$0, -8(%rbp)
.L5:
	movq	-24(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	addq	%rax, -32(%rbp)
	movq	-64(%rbp), %rax
	cmpq	-32(%rbp), %rax
	jl	.L10
	addq	$1, -24(%rbp)
	addq	$1, -8(%rbp)
	jmp	.L5
.L10:
	nop
	addq	$1, -16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	cmpq	-48(%rbp), %rax
	jl	.L6
	movq	-24(%rbp), %rax
	cmpq	-40(%rbp), %rax
	jge	.L7
	movl	$1, %eax
	jmp	.L8
.L7:
	movl	$0, %eax
.L8:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	hyouka, .-hyouka
	.globl	nibutan
	.type	nibutan, @function
nibutan:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$56, %rsp
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	$0, -32(%rbp)
	movq	$1500000, -24(%rbp)
.L15:
	movq	-24(%rbp), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rcx
	movq	-56(%rbp), %rdx
	movq	-48(%rbp), %rsi
	movq	-40(%rbp), %rax
	movq	%rax, %rdi
	call	hyouka
	movq	%rax, -8(%rbp)
	cmpq	$1, -8(%rbp)
	jne	.L12
	movq	-16(%rbp), %rax
	movq	%rax, -32(%rbp)
	jmp	.L13
.L12:
	cmpq	$0, -8(%rbp)
	jne	.L13
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L13:
	movq	-24(%rbp), %rax
	cmpq	-32(%rbp), %rax
	je	.L14
	movq	-32(%rbp), %rax
	addq	$1, %rax
	cmpq	%rax, -24(%rbp)
	je	.L14
	jmp	.L15
.L14:
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	nibutan, .-nibutan
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L22:
	leaq	-848(%rbp), %rdx
	leaq	-840(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-848(%rbp), %rax
	testq	%rax, %rax
	jne	.L18
	movq	-840(%rbp), %rax
	testq	%rax, %rax
	je	.L26
.L18:
	movq	$0, -832(%rbp)
	jmp	.L20
.L21:
	leaq	-816(%rbp), %rdx
	movq	-832(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -832(%rbp)
.L20:
	movq	-848(%rbp), %rax
	cmpq	%rax, -832(%rbp)
	jl	.L21
	movq	-840(%rbp), %rcx
	movq	-848(%rbp), %rax
	leaq	-816(%rbp), %rdx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	nibutan
	movq	%rax, -824(%rbp)
	movq	-824(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L26:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	hyouka
	.type	hyouka, @function
hyouka:
.LFB39:
	.cfi_startproc
	endbr64
	testq	%rsi, %rsi
	jle	.L6
	movq	(%rdx), %rax
	xorl	%r10d, %r10d
	xorl	%r8d, %r8d
	cmpq	%rax, %rcx
	jl	.L2
	.p2align 4,,10
	.p2align 3
.L5:
	addq	$1, %r8
	movq	(%rdx,%r8,8), %r9
	addq	%r9, %rax
	cmpq	%rcx, %rax
	jle	.L5
	addq	$1, %r10
	cmpq	%r10, %rsi
	je	.L2
	movq	%r9, %rax
	cmpq	%rax, %rcx
	jge	.L5
.L2:
	xorl	%eax, %eax
	cmpq	%r8, %rdi
	setg	%al
	ret
.L6:
	xorl	%r8d, %r8d
	xorl	%eax, %eax
	cmpq	%r8, %rdi
	setg	%al
	ret
	.cfi_endproc
.LFE39:
	.size	hyouka, .-hyouka
	.p2align 4
	.globl	nibutan
	.type	nibutan, @function
nibutan:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %r9
	movq	%rdi, %rbx
	movl	$1500000, %r10d
	movq	%rdx, %rdi
	xorl	%r11d, %r11d
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	(%r11,%r10), %rax
	movq	%rax, %rsi
	shrq	$63, %rsi
	addq	%rax, %rsi
	sarq	%rsi
	testq	%r9, %r9
	jle	.L19
	movq	(%rdi), %rax
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	cmpq	%rax, %rsi
	jl	.L12
	.p2align 4,,10
	.p2align 3
.L15:
	addq	$1, %rdx
	movq	(%rdi,%rdx,8), %rcx
	addq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L15
	addq	$1, %r8
	cmpq	%r8, %r9
	je	.L12
	movq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L15
.L12:
	cmpq	%rdx, %rbx
	cmovle	%rsi, %r10
	cmovg	%rsi, %r11
	cmpq	%r10, %r11
	je	.L11
	leaq	1(%r11), %rax
	cmpq	%r10, %rax
	jne	.L18
.L11:
	movq	%r10, %rax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L19:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L12
	.cfi_endproc
.LFE40:
	.size	nibutan, .-nibutan
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$840, %rsp
	.cfi_def_cfa_offset 896
	movq	%fs:40, %rax
	movq	%rax, 824(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r13
	leaq	8(%rsp), %r12
	leaq	16(%rsp), %r14
.L39:
	movq	%r13, %rdx
	movq	%r12, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	(%rsp), %r10
	testq	%r10, %r10
	jne	.L53
	movq	8(%rsp), %rdi
	testq	%rdi, %rdi
	je	.L54
.L30:
	movq	16(%rsp), %r11
	movl	$1500000, %r8d
	xorl	%r9d, %r9d
	.p2align 4,,10
	.p2align 3
.L38:
	leaq	(%r9,%r8), %rax
	xorl	%edx, %edx
	xorl	%ebp, %ebp
	movq	%rax, %rsi
	shrq	$63, %rsi
	addq	%rax, %rsi
	movq	%r11, %rax
	sarq	%rsi
	testq	%rdi, %rdi
	jle	.L33
	cmpq	%rax, %rsi
	jl	.L33
	.p2align 4,,10
	.p2align 3
.L35:
	addq	$1, %rdx
	movq	(%r14,%rdx,8), %rcx
	addq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L35
	addq	$1, %rbp
	cmpq	%rbp, %rdi
	je	.L33
	movq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L35
.L33:
	cmpq	%rdx, %r10
	cmovle	%rsi, %r8
	cmovg	%rsi, %r9
	cmpq	%r8, %r9
	je	.L37
	leaq	1(%r9), %rax
	cmpq	%rax, %r8
	jne	.L38
.L37:
	movq	%r8, %rdx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L39
.L53:
	jle	.L48
	movq	%r14, %r15
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L31:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	movq	(%rsp), %r10
	addq	$8, %r15
	cmpq	%rbp, %r10
	jg	.L31
.L48:
	movq	8(%rsp), %rdi
	jmp	.L30
.L54:
	movq	824(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L55
	addq	$840, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L55:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	hyouka
	.type	hyouka, @function
hyouka:
.LFB39:
	.cfi_startproc
	endbr64
	testq	%rsi, %rsi
	jle	.L6
	movq	(%rdx), %rax
	xorl	%r10d, %r10d
	xorl	%r8d, %r8d
	cmpq	%rax, %rcx
	jl	.L2
	.p2align 4,,10
	.p2align 3
.L5:
	addq	$1, %r8
	movq	(%rdx,%r8,8), %r9
	addq	%r9, %rax
	cmpq	%rcx, %rax
	jle	.L5
	addq	$1, %r10
	cmpq	%r10, %rsi
	je	.L2
	movq	%r9, %rax
	cmpq	%rax, %rcx
	jge	.L5
.L2:
	xorl	%eax, %eax
	cmpq	%r8, %rdi
	setg	%al
	ret
.L6:
	xorl	%r8d, %r8d
	xorl	%eax, %eax
	cmpq	%r8, %rdi
	setg	%al
	ret
	.cfi_endproc
.LFE39:
	.size	hyouka, .-hyouka
	.p2align 4
	.globl	nibutan
	.type	nibutan, @function
nibutan:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %r9
	movq	%rdi, %rbx
	movl	$1500000, %r10d
	movq	%rdx, %rdi
	xorl	%r11d, %r11d
	.p2align 4,,10
	.p2align 3
.L18:
	leaq	(%r11,%r10), %rax
	movq	%rax, %rsi
	shrq	$63, %rsi
	addq	%rax, %rsi
	sarq	%rsi
	testq	%r9, %r9
	jle	.L19
	movq	(%rdi), %rax
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	cmpq	%rax, %rsi
	jl	.L12
	.p2align 4,,10
	.p2align 3
.L15:
	addq	$1, %rdx
	movq	(%rdi,%rdx,8), %rcx
	addq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L15
	addq	$1, %r8
	cmpq	%r8, %r9
	je	.L12
	movq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L15
.L12:
	cmpq	%rdx, %rbx
	cmovle	%rsi, %r10
	cmovg	%rsi, %r11
	cmpq	%r10, %r11
	je	.L11
	leaq	1(%r11), %rax
	cmpq	%r10, %rax
	jne	.L18
.L11:
	movq	%r10, %rax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L19:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L12
	.cfi_endproc
.LFE40:
	.size	nibutan, .-nibutan
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC1(%rip), %rbx
	subq	$840, %rsp
	.cfi_def_cfa_offset 896
	movq	%fs:40, %rax
	movq	%rax, 824(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r13
	leaq	8(%rsp), %r12
	leaq	16(%rsp), %r14
.L39:
	movq	%r13, %rdx
	movq	%r12, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	(%rsp), %r10
	testq	%r10, %r10
	jne	.L53
	movq	8(%rsp), %rdi
	testq	%rdi, %rdi
	je	.L54
.L30:
	movq	16(%rsp), %r11
	movl	$1500000, %r8d
	xorl	%r9d, %r9d
	.p2align 4,,10
	.p2align 3
.L38:
	leaq	(%r9,%r8), %rax
	xorl	%edx, %edx
	xorl	%ebp, %ebp
	movq	%rax, %rsi
	shrq	$63, %rsi
	addq	%rax, %rsi
	movq	%r11, %rax
	sarq	%rsi
	testq	%rdi, %rdi
	jle	.L33
	cmpq	%rax, %rsi
	jl	.L33
	.p2align 4,,10
	.p2align 3
.L35:
	addq	$1, %rdx
	movq	(%r14,%rdx,8), %rcx
	addq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L35
	addq	$1, %rbp
	cmpq	%rbp, %rdi
	je	.L33
	movq	%rcx, %rax
	cmpq	%rax, %rsi
	jge	.L35
.L33:
	cmpq	%rdx, %r10
	cmovle	%rsi, %r8
	cmovg	%rsi, %r9
	cmpq	%r8, %r9
	je	.L37
	leaq	1(%r9), %rax
	cmpq	%rax, %r8
	jne	.L38
.L37:
	movq	%r8, %rdx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L39
.L53:
	jle	.L48
	movq	%r14, %r15
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L31:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addq	$1, %rbp
	call	__isoc99_scanf@PLT
	movq	(%rsp), %r10
	addq	$8, %r15
	cmpq	%rbp, %r10
	jg	.L31
.L48:
	movq	8(%rsp), %rdi
	jmp	.L30
.L54:
	movq	824(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L55
	addq	$840, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L55:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#define SHORT 1
#define LONG 0

long hyouka(long n,long m,long book[101],long bookcase){
	long length,count = 0,i,j;
	for(i = 0 ;i < m ;i++){
		length = 0;
		for(j = 0;;j++){
			length = length + book[count];
			if(bookcase < length){
				break;
			}
			count++;
			
		}
	}
	
	if(count < n){
		return SHORT;
	}else{
		return LONG;
		}
}


long nibutan(long n,long m,long book[101]){
	long left = 0,right = 1500000,half,a;
	while(1){
		half = (right + left) / 2;
		//printf("%ld\t",half);
		
		a = hyouka(n,m,book,half);
		
		if(a == SHORT){
			left = half;
		}else if(a == LONG){
			right = half;
		}if(right == left || right == left + 1){
			break;
		}
		//printf("%ld %ld\n",left,right);
	}
	return right;
}


int main(void)
{
	long  n,m,book[101],answer,i;
	
	while(1){
		scanf("%ld %ld",&m,&n);
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(i = 0;i < n;i++){
			scanf("%ld",&book[i]);
		}
		
		answer = nibutan(n,m,book);
		
		printf("%ld\n",answer);
	}
	return 0;
}
3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1010
0 0
 3 9
500
311
800
335
100
600
900
700
400
4 3
1000
1000
1010
0 0
 3 9
559
311
800
335
100
563
900
700
400
4 3
1000
1000
1010
0 0
 3 9
500
300
800
200
100
600
900
1032
400
4 3
1000
1000
1000
0 0
 3 9
500
300
800
200
000
600
900
700
400
4 3
1000
1000
1010
0 0
 3 9
500
253
800
335
100
600
900
700
400
4 3
1000
1000
1010
0 0
 3 9
559
311
800
335
110
600
900
700
400
4 3
1000
1000
1010
0 0
 3 9
559
311
656
335
100
563
900
700
400
4 3
1000
1000
1010
0 0
 3 9
500
300
800
200
100
871
900
1032
400
4 3
1000
1000
1000
0 0
 3 9
500
300
800
200
001
600
900
700
400
4 3
1000
1000
1010
0 0

1800
1010
 1935
1010
 1898
1010
 1800
1000
 1700
1010
 1888
1010
 1945
1010
 1861
1010
 1871
1000
 1701
1010

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
#include <stdlib.h>
#define SHORT 1
#define LONG 0

long hyouka(long n,long m,long book[101],long bookcase){
	long length,count = 0,i,j;
	for(i = 0 ;i < m ;i++){
		length = 0;
		for(j = 0;;j++){
			length = length + book[count];
			if(bookcase < length){
				break;
			}
			count++;
			
		}
	}
	
	if(count < n){
		return SHORT;
	}else{
		return LONG;
		}
}


long nibutan(long n,long m,long book[101]){
	long left = 0,right = 1500000,half,a;
	while(1){
		half = (right + left) / 2;
		//printf("%ld\t",half);
		
		a = hyouka(n,m,book,half);
		
		if(a == SHORT){
			left = half;
		}else if(a == LONG){
			right = half;
		}if(right == left || right == left + 1){
			break;
		}
		//printf("%ld %ld\n",left,right);
	}
	return right;
}


int main(void)
{
	long  n,m,book[101],answer,i;
	
	while(1){
		scanf("%ld %ld",&m,&n);
		
		if(n == 0 && m == 0){
			break;
		}
		
		for(i = 0;i < n;i++){
			scanf("%ld",&book[i]);
		}
		
		answer = nibutan(n,m,book);
		
		printf("%ld\n",answer);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	hyouka
	.type	hyouka, @function
hyouka:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	%rcx, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L6:
	movq	$0, -32(%rbp)
	movq	$0, -8(%rbp)
.L5:
	movq	-24(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	addq	%rax, -32(%rbp)
	movq	-64(%rbp), %rax
	cmpq	-32(%rbp), %rax
	jl	.L10
	addq	$1, -24(%rbp)
	addq	$1, -8(%rbp)
	jmp	.L5
.L10:
	nop
	addq	$1, -16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	cmpq	-48(%rbp), %rax
	jl	.L6
	movq	-24(%rbp), %rax
	cmpq	-40(%rbp), %rax
	jge	.L7
	movl	$1, %eax
	jmp	.L8
.L7:
	movl	$0, %eax
.L8:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	hyouka, .-hyouka
	.globl	nibutan
	.type	nibutan, @function
nibutan:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$56, %rsp
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	$0, -32(%rbp)
	movq	$1500000, -24(%rbp)
.L15:
	movq	-24(%rbp), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rcx
	movq	-56(%rbp), %rdx
	movq	-48(%rbp), %rsi
	movq	-40(%rbp), %rax
	movq	%rax, %rdi
	call	hyouka
	movq	%rax, -8(%rbp)
	cmpq	$1, -8(%rbp)
	jne	.L12
	movq	-16(%rbp), %rax
	movq	%rax, -32(%rbp)
	jmp	.L13
.L12:
	cmpq	$0, -8(%rbp)
	jne	.L13
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L13:
	movq	-24(%rbp), %rax
	cmpq	-32(%rbp), %rax
	je	.L14
	movq	-32(%rbp), %rax
	addq	$1, %rax
	cmpq	%rax, -24(%rbp)
	je	.L14
	jmp	.L15
.L14:
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	nibutan, .-nibutan
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L22:
	leaq	-848(%rbp), %rdx
	leaq	-840(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-848(%rbp), %rax
	testq	%rax, %rax
	jne	.L18
	movq	-840(%rbp), %rax
	testq	%rax, %rax
	je	.L26
.L18:
	movq	$0, -832(%rbp)
	jmp	.L20
.L21:
	leaq	-816(%rbp), %rdx
	movq	-832(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -832(%rbp)
.L20:
	movq	-848(%rbp), %rax
	cmpq	%rax, -832(%rbp)
	jl	.L21
	movq	-840(%rbp), %rcx
	movq	-848(%rbp), %rax
	leaq	-816(%rbp), %rdx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	nibutan
	movq	%rax, -824(%rbp)
	movq	-824(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L26:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	hyouka
	.type	hyouka, @function
hyouka:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	%rcx, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L6:
	movq	$0, -32(%rbp)
	movq	$0, -8(%rbp)
.L5:
	movq	-24(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	addq	%rax, -32(%rbp)
	movq	-64(%rbp), %rax
	cmpq	-32(%rbp), %rax
	jl	.L10
	addq	$1, -24(%rbp)
	addq	$1, -8(%rbp)
	jmp	.L5
.L10:
	nop
	addq	$1, -16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	cmpq	-48(%rbp), %rax
	jl	.L6
	movq	-24(%rbp), %rax
	cmpq	-40(%rbp), %rax
	jge	.L7
	movl	$1, %eax
	jmp	.L8
.L7:
	movl	$0, %eax
.L8:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	hyouka, .-hyouka
	.globl	nibutan
	.type	nibutan, @function
nibutan:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$56, %rsp
	movq	%rdi, -40(%rbp)
	movq	%rsi, -48(%rbp)
	movq	%rdx, -56(%rbp)
	movq	$0, -32(%rbp)
	movq	$1500000, -24(%rbp)
.L15:
	movq	-24(%rbp), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	movq	-16(%rbp), %rcx
	movq	-56(%rbp), %rdx
	movq	-48(%rbp), %rsi
	movq	-40(%rbp), %rax
	movq	%rax, %rdi
	call	hyouka
	movq	%rax, -8(%rbp)
	cmpq	$1, -8(%rbp)
	jne	.L12
	movq	-16(%rbp), %rax
	movq	%rax, -32(%rbp)
	jmp	.L13
.L12:
	cmpq	$0, -8(%rbp)
	jne	.L13
	movq	-16(%rbp), %rax
	movq	%rax, -24(%rbp)
.L13:
	movq	-24(%rbp), %rax
	cmpq	-32(%rbp), %rax
	je	.L14
	movq	-32(%rbp), %rax
	addq	$1, %rax
	cmpq	%rax, -24(%rbp)
	je	.L14
	jmp	.L15
.L14:
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	nibutan, .-nibutan
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$848, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L22:
	leaq	-848(%rbp), %rdx
	leaq	-840(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-848(%rbp), %rax
	testq	%rax, %rax
	jne	.L18
	movq	-840(%rbp), %rax
	testq	%rax, %rax
	je	.L26
.L18:
	movq	$0, -832(%rbp)
	jmp	.L20
.L21:
	leaq	-816(%rbp), %rdx
	movq	-832(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -832(%rbp)
.L20:
	movq	-848(%rbp), %rax
	cmpq	%rax, -832(%rbp)
	jl	.L21
	movq	-840(%rbp), %rcx
	movq	-848(%rbp), %rax
	leaq	-816(%rbp), %rdx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	nibutan
	movq	%rax, -824(%rbp)
	movq	-824(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L26:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
