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>
#define MAX 100

int n, m;
int books[MAX];

int check(mid){
	//	巻号
	int pos = 0;

	//	本棚の段数だけループ
	for (int i = 0; i < n; i++){
		//		printf("i: %d  book : %d\n", i, books[pos]);
		int width = mid;
		for (; pos < m; pos++){
			//	空き幅が本の幅より大きければ格納
			if (width >= books[pos]){
				width -= books[pos];
			}
			else{
				break;
			}
		}
		if (pos >= m){ break; }
	}
	return pos;
}

int bs(left, right){
	int mid = (left + right) / 2;
//	printf("left mid right : %d %d %d\n", left, mid, right);
	if (left >= right){
		return mid;
	}

	//	本棚に収まるか？
	int pos = check(mid);

	//	本棚に全部収まった
	if (pos >= m){
		return bs(left, mid);
	}
	else{
		return bs(mid + 1, right);
	}
}

int main(){
	int i;
//	int books[100];
	int left, right, mid;
	int sum_width;
	
	while (scanf("%d %d",&n,&m), n || m){
		sum_width = 0;
//		printf("%d %d", n, m);
		for (i = 0; i < m; i++){
			scanf("%d", &books[i]);
			sum_width += books[i];
		}

//		printf("%d", books[0]);
		//	二分探索
		//	ただし、本棚の幅は 1500000 を超えないものとします。
		//	-> 最悪値 = すべて1段に収めた場合 = 本の幅の合計
		left = 1; right = sum_width;
		
		printf("%d\n",bs(left, right));
	}
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	books
	.align 32
	.type	books, @object
	.size	books, 400
books:
	.zero	400
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L10:
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	jmp	.L3
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L12
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	%eax, -4(%rbp)
	addl	$1, -12(%rbp)
.L3:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L7
	jmp	.L6
.L12:
	nop
.L6:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L13
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L10
	jmp	.L9
.L13:
	nop
.L9:
	movl	-12(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.globl	bs
	.type	bs, @function
bs:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -8(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L15
	movl	-8(%rbp), %eax
	jmp	.L16
.L15:
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	movl	$0, %eax
	call	check
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L17
	movl	-8(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	jmp	.L16
.L17:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	movl	%edx, %edi
	movl	$0, %eax
	call	bs
.L16:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	bs, .-bs
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	jmp	.L19
.L25:
	movl	$0, -12(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L20
.L21:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	addl	$1, -16(%rbp)
.L20:
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L21
	movl	$1, -8(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L19:
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L22
	movl	m(%rip), %eax
	testl	%eax, %eax
	je	.L23
.L22:
	movl	$1, %eax
	jmp	.L24
.L23:
	movl	$0, %eax
.L24:
	testl	%eax, %eax
	jne	.L25
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	check
	.type	check, @function
check:
.LFB23:
	.cfi_startproc
	endbr64
	movl	n(%rip), %r10d
	xorl	%r8d, %r8d
	testl	%r10d, %r10d
	jle	.L1
	movl	m(%rip), %r8d
	xorl	%r9d, %r9d
	xorl	%eax, %eax
	leaq	books(%rip), %r11
	.p2align 4,,10
	.p2align 3
.L7:
	cmpl	%eax, %r8d
	jle	.L10
	movslq	%eax, %rdx
	leaq	(%r11,%rdx,4), %rcx
	movl	%edi, %edx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L12:
	addl	$1, %eax
	subl	%esi, %edx
	addq	$4, %rcx
	cmpl	%eax, %r8d
	je	.L1
.L5:
	movl	(%rcx), %esi
	cmpl	%edx, %esi
	jle	.L12
	addl	$1, %r9d
	cmpl	%r10d, %r9d
	jne	.L7
.L10:
	movl	%eax, %r8d
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	check, .-check
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	n(%rip), %r11d
	movl	%esi, %r12d
	leaq	books(%rip), %r8
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edi, %ebp
	movl	m(%rip), %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	.p2align 4,,10
	.p2align 3
.L25:
	leal	0(%rbp,%r12), %eax
	movl	%r12d, %ebx
	movl	%eax, %r10d
	shrl	$31, %r10d
	addl	%eax, %r10d
	sarl	%r10d
	movl	%r10d, %r12d
	cmpl	%ebx, %ebp
	jge	.L28
	xorl	%esi, %esi
	testl	%r11d, %r11d
	jle	.L18
	xorl	%r9d, %r9d
	.p2align 4,,10
	.p2align 3
.L21:
	cmpl	%edi, %esi
	jge	.L25
	movslq	%esi, %rax
	movl	%r10d, %edx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L29:
	addq	$1, %rax
	subl	%ecx, %edx
	cmpl	%eax, %edi
	jle	.L25
.L16:
	movl	(%r8,%rax,4), %ecx
	movl	%eax, %esi
	cmpl	%edx, %ecx
	jle	.L29
	addl	$1, %r9d
	cmpl	%r9d, %r11d
	jne	.L21
.L18:
	cmpl	%edi, %esi
	jge	.L25
	leal	1(%r10), %ebp
	movl	%ebx, %r12d
	jmp	.L25
.L28:
	popq	%rbx
	.cfi_def_cfa_offset 24
	movl	%r10d, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	bs, .-bs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.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
	leaq	books(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	m(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
.L31:
	xorl	%eax, %eax
	movq	%r12, %rdx
	leaq	n(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	m(%rip), %eax
	movl	%eax, %ebx
	orl	n(%rip), %ebx
	je	.L46
	leaq	books(%rip), %rbp
	xorl	%r15d, %r15d
	xorl	%ebx, %ebx
	xorl	%edx, %edx
	leaq	.LC0(%rip), %r14
	testl	%eax, %eax
	jle	.L33
.L32:
	movq	%rbp, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	m(%rip), %edi
	addl	0(%rbp), %r15d
	addq	$4, %rbp
	cmpl	%ebx, %edi
	jg	.L32
	movl	n(%rip), %r9d
	movl	$1, %r8d
.L41:
	leal	(%r8,%r15), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%eax, %edx
	sarl	%edx
	movl	%edx, %esi
	cmpl	%r15d, %r8d
	jge	.L33
	.p2align 4,,10
	.p2align 3
.L34:
	xorl	%ecx, %ecx
	xorl	%r11d, %r11d
	testl	%r9d, %r9d
	jle	.L36
	.p2align 4,,10
	.p2align 3
.L35:
	cmpl	%ecx, %edi
	jle	.L39
	movslq	%ecx, %rax
	movl	%esi, %edx
	jmp	.L38
	.p2align 4,,10
	.p2align 3
.L52:
	addq	$1, %rax
	subl	%r10d, %edx
	cmpl	%eax, %edi
	jle	.L39
.L38:
	movl	0(%r13,%rax,4), %r10d
	movl	%eax, %ecx
	cmpl	%edx, %r10d
	jle	.L52
	addl	$1, %r11d
	cmpl	%r11d, %r9d
	jne	.L35
.L36:
	cmpl	%ecx, %edi
	jg	.L53
	.p2align 4,,10
	.p2align 3
.L39:
	leal	(%rsi,%r8), %edx
	movl	%esi, %r15d
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	cmpl	%r8d, %esi
	jle	.L33
	movl	%eax, %esi
	jmp	.L34
.L53:
	leal	1(%rsi), %r8d
	jmp	.L41
.L33:
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L31
.L46:
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	books
	.bss
	.align 32
	.type	books, @object
	.size	books, 400
books:
	.zero	400
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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	check
	.type	check, @function
check:
.LFB23:
	.cfi_startproc
	endbr64
	movl	n(%rip), %r10d
	xorl	%r8d, %r8d
	testl	%r10d, %r10d
	jle	.L1
	movl	m(%rip), %r8d
	xorl	%r9d, %r9d
	xorl	%eax, %eax
	leaq	books(%rip), %r11
	.p2align 4,,10
	.p2align 3
.L7:
	cmpl	%eax, %r8d
	jle	.L10
	movslq	%eax, %rdx
	leaq	(%r11,%rdx,4), %rcx
	movl	%edi, %edx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L12:
	addl	$1, %eax
	subl	%esi, %edx
	addq	$4, %rcx
	cmpl	%eax, %r8d
	je	.L1
.L5:
	movl	(%rcx), %esi
	cmpl	%edx, %esi
	jle	.L12
	addl	$1, %r9d
	cmpl	%r10d, %r9d
	jne	.L7
.L10:
	movl	%eax, %r8d
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	check, .-check
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	n(%rip), %r11d
	movl	%esi, %r12d
	leaq	books(%rip), %r8
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edi, %ebp
	movl	m(%rip), %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	.p2align 4,,10
	.p2align 3
.L25:
	leal	0(%rbp,%r12), %eax
	movl	%r12d, %ebx
	movl	%eax, %r10d
	shrl	$31, %r10d
	addl	%eax, %r10d
	sarl	%r10d
	movl	%r10d, %r12d
	cmpl	%ebx, %ebp
	jge	.L28
	xorl	%esi, %esi
	testl	%r11d, %r11d
	jle	.L18
	xorl	%r9d, %r9d
	.p2align 4,,10
	.p2align 3
.L21:
	cmpl	%edi, %esi
	jge	.L25
	movslq	%esi, %rax
	movl	%r10d, %edx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L29:
	addq	$1, %rax
	subl	%ecx, %edx
	cmpl	%eax, %edi
	jle	.L25
.L16:
	movl	(%r8,%rax,4), %ecx
	movl	%eax, %esi
	cmpl	%edx, %ecx
	jle	.L29
	addl	$1, %r9d
	cmpl	%r9d, %r11d
	jne	.L21
.L18:
	cmpl	%edi, %esi
	jge	.L25
	leal	1(%r10), %ebp
	movl	%ebx, %r12d
	jmp	.L25
.L28:
	popq	%rbx
	.cfi_def_cfa_offset 24
	movl	%r10d, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	bs, .-bs
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.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
	leaq	books(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	m(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
.L31:
	xorl	%eax, %eax
	movq	%r12, %rdx
	leaq	n(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	m(%rip), %eax
	movl	%eax, %ebx
	orl	n(%rip), %ebx
	je	.L46
	leaq	books(%rip), %rbp
	xorl	%r15d, %r15d
	xorl	%ebx, %ebx
	xorl	%edx, %edx
	leaq	.LC0(%rip), %r14
	testl	%eax, %eax
	jle	.L33
.L32:
	movq	%rbp, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	m(%rip), %edi
	addl	0(%rbp), %r15d
	addq	$4, %rbp
	cmpl	%ebx, %edi
	jg	.L32
	movl	n(%rip), %r9d
	movl	$1, %r8d
.L41:
	leal	(%r8,%r15), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%eax, %edx
	sarl	%edx
	movl	%edx, %esi
	cmpl	%r15d, %r8d
	jge	.L33
	.p2align 4,,10
	.p2align 3
.L34:
	xorl	%ecx, %ecx
	xorl	%r11d, %r11d
	testl	%r9d, %r9d
	jle	.L36
	.p2align 4,,10
	.p2align 3
.L35:
	cmpl	%ecx, %edi
	jle	.L39
	movslq	%ecx, %rax
	movl	%esi, %edx
	jmp	.L38
	.p2align 4,,10
	.p2align 3
.L52:
	addq	$1, %rax
	subl	%r10d, %edx
	cmpl	%eax, %edi
	jle	.L39
.L38:
	movl	0(%r13,%rax,4), %r10d
	movl	%eax, %ecx
	cmpl	%edx, %r10d
	jle	.L52
	addl	$1, %r11d
	cmpl	%r11d, %r9d
	jne	.L35
.L36:
	cmpl	%ecx, %edi
	jg	.L53
	.p2align 4,,10
	.p2align 3
.L39:
	leal	(%rsi,%r8), %edx
	movl	%esi, %r15d
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	cmpl	%r8d, %esi
	jle	.L33
	movl	%eax, %esi
	jmp	.L34
.L53:
	leal	1(%rsi), %r8d
	jmp	.L41
.L33:
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L31
.L46:
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	books
	.bss
	.align 32
	.type	books, @object
	.size	books, 400
books:
	.zero	400
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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>
#define MAX 100

int n, m;
int books[MAX];

int check(mid){
	//	巻号
	int pos = 0;

	//	本棚の段数だけループ
	for (int i = 0; i < n; i++){
		//		printf("i: %d  book : %d\n", i, books[pos]);
		int width = mid;
		for (; pos < m; pos++){
			//	空き幅が本の幅より大きければ格納
			if (width >= books[pos]){
				width -= books[pos];
			}
			else{
				break;
			}
		}
		if (pos >= m){ break; }
	}
	return pos;
}

int bs(left, right){
	int mid = (left + right) / 2;
//	printf("left mid right : %d %d %d\n", left, mid, right);
	if (left >= right){
		return mid;
	}

	//	本棚に収まるか？
	int pos = check(mid);

	//	本棚に全部収まった
	if (pos >= m){
		return bs(left, mid);
	}
	else{
		return bs(mid + 1, right);
	}
}

int main(){
	int i;
//	int books[100];
	int left, right, mid;
	int sum_width;
	
	while (scanf("%d %d",&n,&m), n || m){
		sum_width = 0;
//		printf("%d %d", n, m);
		for (i = 0; i < m; i++){
			scanf("%d", &books[i]);
			sum_width += books[i];
		}

//		printf("%d", books[0]);
		//	二分探索
		//	ただし、本棚の幅は 1500000 を超えないものとします。
		//	-> 最悪値 = すべて1段に収めた場合 = 本の幅の合計
		left = 1; right = sum_width;
		
		printf("%d\n",bs(left, right));
	}
}

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>
#define MAX 100

int n, m;
int books[MAX];

int check(mid){
	//	巻号
	int pos = 0;

	//	本棚の段数だけループ
	for (int i = 0; i < n; i++){
		//		printf("i: %d  book : %d\n", i, books[pos]);
		int width = mid;
		for (; pos < m; pos++){
			//	空き幅が本の幅より大きければ格納
			if (width >= books[pos]){
				width -= books[pos];
			}
			else{
				break;
			}
		}
		if (pos >= m){ break; }
	}
	return pos;
}

int bs(left, right){
	int mid = (left + right) / 2;
//	printf("left mid right : %d %d %d\n", left, mid, right);
	if (left >= right){
		return mid;
	}

	//	本棚に収まるか？
	int pos = check(mid);

	//	本棚に全部収まった
	if (pos >= m){
		return bs(left, mid);
	}
	else{
		return bs(mid + 1, right);
	}
}

int main(){
	int i;
//	int books[100];
	int left, right, mid;
	int sum_width;
	
	while (scanf("%d %d",&n,&m), n || m){
		sum_width = 0;
//		printf("%d %d", n, m);
		for (i = 0; i < m; i++){
			scanf("%d", &books[i]);
			sum_width += books[i];
		}

//		printf("%d", books[0]);
		//	二分探索
		//	ただし、本棚の幅は 1500000 を超えないものとします。
		//	-> 最悪値 = すべて1段に収めた場合 = 本の幅の合計
		left = 1; right = sum_width;
		
		printf("%d\n",bs(left, right));
	}
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	books
	.align 32
	.type	books, @object
	.size	books, 400
books:
	.zero	400
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L10:
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	jmp	.L3
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L12
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	%eax, -4(%rbp)
	addl	$1, -12(%rbp)
.L3:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L7
	jmp	.L6
.L12:
	nop
.L6:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L13
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L10
	jmp	.L9
.L13:
	nop
.L9:
	movl	-12(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.globl	bs
	.type	bs, @function
bs:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -8(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L15
	movl	-8(%rbp), %eax
	jmp	.L16
.L15:
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	movl	$0, %eax
	call	check
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L17
	movl	-8(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	jmp	.L16
.L17:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	movl	%edx, %edi
	movl	$0, %eax
	call	bs
.L16:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	bs, .-bs
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	jmp	.L19
.L25:
	movl	$0, -12(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L20
.L21:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	addl	$1, -16(%rbp)
.L20:
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L21
	movl	$1, -8(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L19:
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L22
	movl	m(%rip), %eax
	testl	%eax, %eax
	je	.L23
.L22:
	movl	$1, %eax
	jmp	.L24
.L23:
	movl	$0, %eax
.L24:
	testl	%eax, %eax
	jne	.L25
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	books
	.align 32
	.type	books, @object
	.size	books, 400
books:
	.zero	400
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -12(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L10:
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	jmp	.L3
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L12
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	%eax, -4(%rbp)
	addl	$1, -12(%rbp)
.L3:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L7
	jmp	.L6
.L12:
	nop
.L6:
	movl	m(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L13
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L10
	jmp	.L9
.L13:
	nop
.L9:
	movl	-12(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.globl	bs
	.type	bs, @function
bs:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -8(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L15
	movl	-8(%rbp), %eax
	jmp	.L16
.L15:
	movl	-8(%rbp), %eax
	movl	%eax, %edi
	movl	$0, %eax
	call	check
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L17
	movl	-8(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	jmp	.L16
.L17:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	-24(%rbp), %eax
	movl	%eax, %esi
	movl	%edx, %edi
	movl	$0, %eax
	call	bs
.L16:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	bs, .-bs
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	jmp	.L19
.L25:
	movl	$0, -12(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L20
.L21:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	books(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	addl	$1, -16(%rbp)
.L20:
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jl	.L21
	movl	$1, -8(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	bs
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L19:
	leaq	m(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L22
	movl	m(%rip), %eax
	testl	%eax, %eax
	je	.L23
.L22:
	movl	$1, %eax
	jmp	.L24
.L23:
	movl	$0, %eax
.L24:
	testl	%eax, %eax
	jne	.L25
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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:
