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

```c
#include <math.h>
#include <stdio.h>
#include <string.h>
int d, n, h[10001], ans = 0;
int main(void) {
    scanf("%d %d", &d, &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < n; i++) {
        ans = ans + h[i];
    }
    if (ans <= d) {
        printf("%d\n", d - ans);
    } else {
        printf("-1\n");
    }
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	h
	.align 32
	.type	h, @object
	.size	h, 40004
h:
	.zero	40004
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.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
	leaq	n(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -8(%rbp)
	jmp	.L2
.L3:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	movl	$0, -4(%rbp)
	jmp	.L4
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	ans(%rip), %eax
	addl	%edx, %eax
	movl	%eax, ans(%rip)
	addl	$1, -4(%rbp)
.L4:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L5
	movl	ans(%rip), %edx
	movl	d(%rip), %eax
	cmpl	%eax, %edx
	jg	.L6
	movl	d(%rip), %eax
	movl	ans(%rip), %edx
	subl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L7
.L6:
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"-1"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	n(%rip), %rdx
	leaq	d(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	movl	ans(%rip), %ecx
	testl	%eax, %eax
	jle	.L3
	leaq	h(%rip), %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r14
	movq	%r12, %r13
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L4
	movl	ans(%rip), %ecx
	testl	%eax, %eax
	jle	.L3
	leal	-1(%rax), %edx
	cmpl	$2, %edx
	jbe	.L10
	movl	%eax, %edx
	leaq	16+h(%rip), %rsi
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	addq	%rsi, %rdx
	.p2align 4,,10
	.p2align 3
.L6:
	paddd	(%r12), %xmm0
	addq	$16, %r12
	cmpq	%rdx, %r12
	jne	.L6
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %edx
	addl	%edx, %ecx
	movl	%eax, %edx
	andl	$-4, %edx
	testb	$3, %al
	je	.L7
.L5:
	movslq	%edx, %rsi
	addl	0(%r13,%rsi,4), %ecx
	leal	1(%rdx), %esi
	cmpl	%esi, %eax
	jle	.L7
	movslq	%esi, %rsi
	addl	$2, %edx
	addl	0(%r13,%rsi,4), %ecx
	cmpl	%edx, %eax
	jle	.L7
	movslq	%edx, %rdx
	addl	0(%r13,%rdx,4), %ecx
.L7:
	movl	%ecx, ans(%rip)
.L3:
	movl	d(%rip), %edx
	cmpl	%ecx, %edx
	jl	.L8
	subl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L9:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore_state
	leaq	.LC3(%rip), %rdi
	call	puts@PLT
	jmp	.L9
.L10:
	xorl	%edx, %edx
	jmp	.L5
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	ans
	.bss
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.globl	h
	.align 32
	.type	h, @object
	.size	h, 40004
h:
	.zero	40004
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"-1"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	n(%rip), %rdx
	leaq	d(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	movl	ans(%rip), %ecx
	testl	%eax, %eax
	jle	.L3
	leaq	h(%rip), %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r14
	movq	%r12, %r13
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L4
	movl	ans(%rip), %ecx
	testl	%eax, %eax
	jle	.L3
	leal	-1(%rax), %edx
	cmpl	$2, %edx
	jbe	.L10
	movl	%eax, %edx
	leaq	16+h(%rip), %rsi
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	addq	%rsi, %rdx
	.p2align 4,,10
	.p2align 3
.L6:
	paddd	(%r12), %xmm0
	addq	$16, %r12
	cmpq	%rdx, %r12
	jne	.L6
	movdqa	%xmm0, %xmm1
	psrldq	$8, %xmm1
	paddd	%xmm1, %xmm0
	movdqa	%xmm0, %xmm1
	psrldq	$4, %xmm1
	paddd	%xmm1, %xmm0
	movd	%xmm0, %edx
	addl	%edx, %ecx
	movl	%eax, %edx
	andl	$-4, %edx
	testb	$3, %al
	je	.L7
.L5:
	movslq	%edx, %rsi
	addl	0(%r13,%rsi,4), %ecx
	leal	1(%rdx), %esi
	cmpl	%esi, %eax
	jle	.L7
	movslq	%esi, %rsi
	addl	$2, %edx
	addl	0(%r13,%rsi,4), %ecx
	cmpl	%edx, %eax
	jle	.L7
	movslq	%edx, %rdx
	addl	0(%r13,%rdx,4), %ecx
.L7:
	movl	%ecx, ans(%rip)
.L3:
	movl	d(%rip), %edx
	cmpl	%ecx, %edx
	jl	.L8
	subl	%ecx, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L9:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore_state
	leaq	.LC3(%rip), %rdi
	call	puts@PLT
	jmp	.L9
.L10:
	xorl	%edx, %edx
	jmp	.L5
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	ans
	.bss
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.globl	h
	.align 32
	.type	h, @object
	.size	h, 40004
h:
	.zero	40004
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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 <math.h>
#include <stdio.h>
#include <string.h>
int d, n, h[10001], ans = 0;
int main(void) {
    scanf("%d %d", &d, &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < n; i++) {
        ans = ans + h[i];
    }
    if (ans <= d) {
        printf("%d\n", d - ans);
    } else {
        printf("-1\n");
    }
}
10 2
6 6
 314 15
9 24 5 35 8 9 79 3 23 8 46 2 6 43 3
 41 2
9 6
 11 2
5 2
 20 2
5 2
 20 2
7 4
 41 2
5 12
 41 2
9 9
 11 2
5 0
 14 2
3 6

-1
 11
 26
 4
 13
 9
 24
 23
 6
 5

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

```c
#include <math.h>
#include <stdio.h>
#include <string.h>
int d, n, h[10001], ans = 0;
int main(void) {
    scanf("%d %d", &d, &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < n; i++) {
        ans = ans + h[i];
    }
    if (ans <= d) {
        printf("%d\n", d - ans);
    } else {
        printf("-1\n");
    }
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	h
	.align 32
	.type	h, @object
	.size	h, 40004
h:
	.zero	40004
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.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
	leaq	n(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -8(%rbp)
	jmp	.L2
.L3:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	movl	$0, -4(%rbp)
	jmp	.L4
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	ans(%rip), %eax
	addl	%edx, %eax
	movl	%eax, ans(%rip)
	addl	$1, -4(%rbp)
.L4:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L5
	movl	ans(%rip), %edx
	movl	d(%rip), %eax
	cmpl	%eax, %edx
	jg	.L6
	movl	d(%rip), %eax
	movl	ans(%rip), %edx
	subl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L7
.L6:
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	h
	.align 32
	.type	h, @object
	.size	h, 40004
h:
	.zero	40004
	.globl	ans
	.align 4
	.type	ans, @object
	.size	ans, 4
ans:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.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
	leaq	n(%rip), %rax
	movq	%rax, %rdx
	leaq	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -8(%rbp)
	jmp	.L2
.L3:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -8(%rbp)
.L2:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	movl	$0, -4(%rbp)
	jmp	.L4
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	h(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	ans(%rip), %eax
	addl	%edx, %eax
	movl	%eax, ans(%rip)
	addl	$1, -4(%rbp)
.L4:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L5
	movl	ans(%rip), %edx
	movl	d(%rip), %eax
	cmpl	%eax, %edx
	jg	.L6
	movl	d(%rip), %eax
	movl	ans(%rip), %edx
	subl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L7
.L6:
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
