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>

int main()
{
	int i, N, h[102] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(h[i]));
	
	int sum = 0, flag, count;
	while (1) {
		flag = 0;
		count = 0;
		for (i = 0; i <= N + 1; i++) {
			if (h[i] > 0) {
				h[i]--;
				if (flag == 0) {
					count++;
					flag = 1;
				}
			} else flag = 0;
		}
		sum += count;
		if (count == 0) break;
	}
	
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-416(%rbp), %rdx
	movl	$0, %eax
	movl	$51, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jle	.L3
	movl	$0, -428(%rbp)
.L10:
	movl	$0, -424(%rbp)
	movl	$0, -420(%rbp)
	movl	$0, -432(%rbp)
	jmp	.L4
.L7:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	leal	-1(%rax), %edx
	movl	-432(%rbp), %eax
	cltq
	movl	%edx, -416(%rbp,%rax,4)
	cmpl	$0, -424(%rbp)
	jne	.L6
	addl	$1, -420(%rbp)
	movl	$1, -424(%rbp)
	jmp	.L6
.L5:
	movl	$0, -424(%rbp)
.L6:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jle	.L7
	movl	-420(%rbp), %eax
	addl	%eax, -428(%rbp)
	cmpl	$0, -420(%rbp)
	je	.L14
	jmp	.L10
.L14:
	nop
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$51, %ecx
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	$1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$432, %rsp
	.cfi_def_cfa_offset 480
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	leaq	12(%rsp), %rsi
	movq	%rbx, %rdi
	leaq	20(%rsp), %r14
	movq	%r14, %r12
	rep stosq
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	addq	$4, %r12
	cmpl	%ebp, %r8d
	jge	.L3
.L2:
	leal	1(%r8), %eax
	xorl	%r9d, %r9d
	leaq	(%r14,%rax,4), %rsi
	.p2align 4,,10
	.p2align 3
.L7:
	cmpl	$-1, %r8d
	jl	.L4
	movq	%rbx, %rax
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L18:
	subl	$1, %edx
	movl	%edx, (%rax)
	testl	%ecx, %ecx
	jne	.L5
	addl	$1, %edi
	movl	$1, %ecx
.L5:
	addq	$4, %rax
	cmpq	%rsi, %rax
	je	.L17
.L6:
	movl	(%rax), %edx
	testl	%edx, %edx
	jg	.L18
	addq	$4, %rax
	xorl	%ecx, %ecx
	cmpq	%rsi, %rax
	jne	.L6
.L17:
	addl	%edi, %r9d
	testl	%edi, %edi
	jne	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	movl	$1, %edi
	xorl	%eax, %eax
	movl	%r9d, %edx
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$432, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	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
.L19:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$51, %ecx
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	$1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$432, %rsp
	.cfi_def_cfa_offset 480
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	leaq	12(%rsp), %rsi
	movq	%rbx, %rdi
	leaq	20(%rsp), %r14
	movq	%r14, %r12
	rep stosq
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	addq	$4, %r12
	cmpl	%ebp, %r8d
	jge	.L3
.L2:
	leal	1(%r8), %eax
	xorl	%r9d, %r9d
	leaq	(%r14,%rax,4), %rsi
	.p2align 4,,10
	.p2align 3
.L7:
	cmpl	$-1, %r8d
	jl	.L4
	movq	%rbx, %rax
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L18:
	subl	$1, %edx
	movl	%edx, (%rax)
	testl	%ecx, %ecx
	jne	.L5
	addl	$1, %edi
	movl	$1, %ecx
.L5:
	addq	$4, %rax
	cmpq	%rsi, %rax
	je	.L17
.L6:
	movl	(%rax), %edx
	testl	%edx, %edx
	jg	.L18
	addq	$4, %rax
	xorl	%ecx, %ecx
	cmpq	%rsi, %rax
	jne	.L6
.L17:
	addl	%edi, %r9d
	testl	%edi, %edi
	jne	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	movl	$1, %edi
	xorl	%eax, %eax
	movl	%r9d, %edx
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$432, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	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
.L19:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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>

int main()
{
	int i, N, h[102] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(h[i]));
	
	int sum = 0, flag, count;
	while (1) {
		flag = 0;
		count = 0;
		for (i = 0; i <= N + 1; i++) {
			if (h[i] > 0) {
				h[i]--;
				if (flag == 0) {
					count++;
					flag = 1;
				}
			} else flag = 0;
		}
		sum += count;
		if (count == 0) break;
	}
	
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}
4
1 4 2 1
 8
4 23 75 1 23 96 50 100
 5
1 1 2 3 1
 4
1 8 2 1
 8
4 23 75 0 23 97 50 100
 4
1 12 2 1
 8
4 23 136 0 23 97 50 100
 4
1 12 0 2
 8
4 39 136 0 23 97 50 101
 8
4 39 136 0 23 108 50 101

4
 220
 3
 8
 222
 12
 283
 14
 284
 295

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>

int main()
{
	int i, N, h[102] = {};
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(h[i]));
	
	int sum = 0, flag, count;
	while (1) {
		flag = 0;
		count = 0;
		for (i = 0; i <= N + 1; i++) {
			if (h[i] > 0) {
				h[i]--;
				if (flag == 0) {
					count++;
					flag = 1;
				}
			} else flag = 0;
		}
		sum += count;
		if (count == 0) break;
	}
	
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-416(%rbp), %rdx
	movl	$0, %eax
	movl	$51, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jle	.L3
	movl	$0, -428(%rbp)
.L10:
	movl	$0, -424(%rbp)
	movl	$0, -420(%rbp)
	movl	$0, -432(%rbp)
	jmp	.L4
.L7:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	leal	-1(%rax), %edx
	movl	-432(%rbp), %eax
	cltq
	movl	%edx, -416(%rbp,%rax,4)
	cmpl	$0, -424(%rbp)
	jne	.L6
	addl	$1, -420(%rbp)
	movl	$1, -424(%rbp)
	jmp	.L6
.L5:
	movl	$0, -424(%rbp)
.L6:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jle	.L7
	movl	-420(%rbp), %eax
	addl	%eax, -428(%rbp)
	cmpl	$0, -420(%rbp)
	je	.L14
	jmp	.L10
.L14:
	nop
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-416(%rbp), %rdx
	movl	$0, %eax
	movl	$51, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jle	.L3
	movl	$0, -428(%rbp)
.L10:
	movl	$0, -424(%rbp)
	movl	$0, -420(%rbp)
	movl	$0, -432(%rbp)
	jmp	.L4
.L7:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	leal	-1(%rax), %edx
	movl	-432(%rbp), %eax
	cltq
	movl	%edx, -416(%rbp,%rax,4)
	cmpl	$0, -424(%rbp)
	jne	.L6
	addl	$1, -420(%rbp)
	movl	$1, -424(%rbp)
	jmp	.L6
.L5:
	movl	$0, -424(%rbp)
.L6:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jle	.L7
	movl	-420(%rbp), %eax
	addl	%eax, -428(%rbp)
	cmpl	$0, -420(%rbp)
	je	.L14
	jmp	.L10
.L14:
	nop
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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:
