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(void) {

  int n;
  scanf("%d", &n);
  long a[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  int flag = 0;
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (flag == 0) {
      if (a[i] > a[i-1]) {
        flag = 1;
      } else if (a[i] < a[i-1]) {
        flag = -1;
      }
    } else if (flag == 1) {
      if (a[i] < a[i-1]) {
        count++;
        flag = 0;
      }
    } else {
      if (a[i] > a[i-1]) {
        count++;
        flag = 0;
      }
    }
  }
  printf("%d\n", count);

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
.LC2:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-92(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-92(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -88(%rbp)
	jmp	.L5
.L6:
	movl	-88(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -88(%rbp)
.L5:
	movl	-92(%rbp), %eax
	cmpl	%eax, -88(%rbp)
	jl	.L6
	movl	$0, -84(%rbp)
	movl	$1, -80(%rbp)
	movl	$1, -76(%rbp)
	jmp	.L7
.L12:
	cmpl	$0, -84(%rbp)
	jne	.L8
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L9
	movl	$1, -84(%rbp)
	jmp	.L10
.L9:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	movl	$-1, -84(%rbp)
	jmp	.L10
.L8:
	cmpl	$1, -84(%rbp)
	jne	.L11
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
	jmp	.L10
.L11:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
.L10:
	addl	$1, -76(%rbp)
.L7:
	movl	-92(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L12
	movl	-80(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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	"%ld"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r14
	pushq	%r13
	leaq	-44(%rbp), %rsi
	pushq	%r12
	pushq	%rbx
	subq	$16, %rsp
	.cfi_offset 14, -24
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-44(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rcx
	leaq	15(,%rax,8), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rdx
	cmpq	%rsi, %rsp
	je	.L3
.L33:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L33
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L34
.L4:
	movq	%rsp, %r13
	testl	%ecx, %ecx
	jle	.L19
	movq	%r13, %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	addq	$8, %r12
	cmpl	%ebx, %eax
	jg	.L6
	cmpl	$1, %eax
	jle	.L19
	movl	$1, %ecx
	movl	$1, %r9d
.L13:
	movslq	%ecx, %rdx
	leal	1(%rcx), %esi
	salq	$3, %rdx
	movq	-8(%r13,%rdx), %r8
	addq	%r13, %rdx
	movq	(%rdx), %rdi
	cmpq	%r8, %rdi
	jg	.L8
.L35:
	jl	.L9
	addq	$8, %rdx
	cmpl	%esi, %eax
	jle	.L5
	movq	%rdi, %r8
	movq	(%rdx), %rdi
	movl	%esi, %ecx
	leal	1(%rcx), %esi
	cmpq	%r8, %rdi
	jle	.L35
.L8:
	cmpl	%esi, %eax
	jle	.L5
	leal	2(%rcx), %edx
	movl	%eax, %ecx
	movslq	%esi, %rdi
	subl	%esi, %ecx
	movq	-8(%r13,%rdi,8), %r8
	movslq	%edx, %rdx
	subl	$1, %ecx
	leaq	2(%rdi,%rcx), %rdi
.L15:
	movq	-8(%r13,%rdx,8), %rsi
	movl	%edx, %ecx
	cmpq	%r8, %rsi
	jl	.L31
	addq	$1, %rdx
	cmpq	%rdi, %rdx
	je	.L5
	movq	%rsi, %r8
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L9:
	cmpl	%esi, %eax
	jle	.L5
	leal	2(%rcx), %edx
	movslq	%esi, %r8
	movl	%eax, %ecx
	movslq	%edx, %rdx
	subl	%esi, %ecx
	movq	-8(%r13,%r8,8), %rdi
	movq	-8(%r13,%rdx,8), %rsi
	subl	$1, %ecx
	leaq	2(%r8,%rcx), %r8
	movl	%edx, %ecx
	cmpq	%rdi, %rsi
	jg	.L31
.L14:
	addq	$1, %rdx
	cmpq	%r8, %rdx
	je	.L5
	movq	%rsi, %rdi
	movq	-8(%r13,%rdx,8), %rsi
	movl	%edx, %ecx
	cmpq	%rdi, %rsi
	jle	.L14
.L31:
	addl	$1, %r9d
	cmpl	%ecx, %eax
	jg	.L13
.L5:
	xorl	%eax, %eax
	movl	%r9d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	-40(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L36
	leaq	-32(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L34:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L19:
	movl	$1, %r9d
	jmp	.L5
.L36:
	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	"%ld"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r14
	pushq	%r13
	leaq	-44(%rbp), %rsi
	pushq	%r12
	pushq	%rbx
	subq	$16, %rsp
	.cfi_offset 14, -24
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-44(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rcx
	leaq	15(,%rax,8), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rdx
	cmpq	%rsi, %rsp
	je	.L3
.L33:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L33
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L34
.L4:
	movq	%rsp, %r13
	testl	%ecx, %ecx
	jle	.L19
	movq	%r13, %r12
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	addq	$8, %r12
	cmpl	%ebx, %eax
	jg	.L6
	cmpl	$1, %eax
	jle	.L19
	movl	$1, %ecx
	movl	$1, %r9d
.L13:
	movslq	%ecx, %rdx
	leal	1(%rcx), %esi
	salq	$3, %rdx
	movq	-8(%r13,%rdx), %r8
	addq	%r13, %rdx
	movq	(%rdx), %rdi
	cmpq	%r8, %rdi
	jg	.L8
.L35:
	jl	.L9
	addq	$8, %rdx
	cmpl	%esi, %eax
	jle	.L5
	movq	%rdi, %r8
	movq	(%rdx), %rdi
	movl	%esi, %ecx
	leal	1(%rcx), %esi
	cmpq	%r8, %rdi
	jle	.L35
.L8:
	cmpl	%esi, %eax
	jle	.L5
	leal	2(%rcx), %edx
	movl	%eax, %ecx
	movslq	%esi, %rdi
	subl	%esi, %ecx
	movq	-8(%r13,%rdi,8), %r8
	movslq	%edx, %rdx
	subl	$1, %ecx
	leaq	2(%rdi,%rcx), %rdi
.L15:
	movq	-8(%r13,%rdx,8), %rsi
	movl	%edx, %ecx
	cmpq	%r8, %rsi
	jl	.L31
	addq	$1, %rdx
	cmpq	%rdi, %rdx
	je	.L5
	movq	%rsi, %r8
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L9:
	cmpl	%esi, %eax
	jle	.L5
	leal	2(%rcx), %edx
	movslq	%esi, %r8
	movl	%eax, %ecx
	movslq	%edx, %rdx
	subl	%esi, %ecx
	movq	-8(%r13,%r8,8), %rdi
	movq	-8(%r13,%rdx,8), %rsi
	subl	$1, %ecx
	leaq	2(%r8,%rcx), %r8
	movl	%edx, %ecx
	cmpq	%rdi, %rsi
	jg	.L31
.L14:
	addq	$1, %rdx
	cmpq	%r8, %rdx
	je	.L5
	movq	%rsi, %rdi
	movq	-8(%r13,%rdx,8), %rsi
	movl	%edx, %ecx
	cmpq	%rdi, %rsi
	jle	.L14
.L31:
	addl	$1, %r9d
	cmpl	%ecx, %eax
	jg	.L13
.L5:
	xorl	%eax, %eax
	movl	%r9d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	-40(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L36
	leaq	-32(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L34:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L19:
	movl	$1, %r9d
	jmp	.L5
.L36:
	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(void) {

  int n;
  scanf("%d", &n);
  long a[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  int flag = 0;
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (flag == 0) {
      if (a[i] > a[i-1]) {
        flag = 1;
      } else if (a[i] < a[i-1]) {
        flag = -1;
      }
    } else if (flag == 1) {
      if (a[i] < a[i-1]) {
        count++;
        flag = 0;
      }
    } else {
      if (a[i] > a[i-1]) {
        count++;
        flag = 0;
      }
    }
  }
  printf("%d\n", count);

  return 0;
}
6
1 2 3 2 0 1
 9
1 2 1 2 2 2 1 2 1
 6
1 2 3 2 0 0
 9
0 1 0 -1 2 7 2 -1 0
 7
1 2 3 2 1 999999999 1000000100
 9
1 2 1 2 2 2 2 2 1
 7
1 4 3 2 1 999999999 1000000100
 6
0 2 3 2 0 0
 9
1 2 0 2 2 2 2 2 1
 7
1 4 3 4 1 999999999 1000000100

3
 4
 2
 5
 3
 3
 3
 2
 3
 3

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(void) {

  int n;
  scanf("%d", &n);
  long a[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  int flag = 0;
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (flag == 0) {
      if (a[i] > a[i-1]) {
        flag = 1;
      } else if (a[i] < a[i-1]) {
        flag = -1;
      }
    } else if (flag == 1) {
      if (a[i] < a[i-1]) {
        count++;
        flag = 0;
      }
    } else {
      if (a[i] > a[i-1]) {
        count++;
        flag = 0;
      }
    }
  }
  printf("%d\n", count);

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
.LC2:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-92(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-92(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -88(%rbp)
	jmp	.L5
.L6:
	movl	-88(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -88(%rbp)
.L5:
	movl	-92(%rbp), %eax
	cmpl	%eax, -88(%rbp)
	jl	.L6
	movl	$0, -84(%rbp)
	movl	$1, -80(%rbp)
	movl	$1, -76(%rbp)
	jmp	.L7
.L12:
	cmpl	$0, -84(%rbp)
	jne	.L8
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L9
	movl	$1, -84(%rbp)
	jmp	.L10
.L9:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	movl	$-1, -84(%rbp)
	jmp	.L10
.L8:
	cmpl	$1, -84(%rbp)
	jne	.L11
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
	jmp	.L10
.L11:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
.L10:
	addl	$1, -76(%rbp)
.L7:
	movl	-92(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L12
	movl	-80(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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	"%ld"
.LC2:
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-92(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-92(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -72(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movslq	%eax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	cltq
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -64(%rbp)
	movl	$0, -88(%rbp)
	jmp	.L5
.L6:
	movl	-88(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-64(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -88(%rbp)
.L5:
	movl	-92(%rbp), %eax
	cmpl	%eax, -88(%rbp)
	jl	.L6
	movl	$0, -84(%rbp)
	movl	$1, -80(%rbp)
	movl	$1, -76(%rbp)
	jmp	.L7
.L12:
	cmpl	$0, -84(%rbp)
	jne	.L8
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L9
	movl	$1, -84(%rbp)
	jmp	.L10
.L9:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	movl	$-1, -84(%rbp)
	jmp	.L10
.L8:
	cmpl	$1, -84(%rbp)
	jne	.L11
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jge	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
	jmp	.L10
.L11:
	movq	-64(%rbp), %rax
	movl	-76(%rbp), %edx
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rcx
	movl	-76(%rbp), %eax
	leal	-1(%rax), %edx
	movq	-64(%rbp), %rax
	movslq	%edx, %rdx
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, %rcx
	jle	.L10
	addl	$1, -80(%rbp)
	movl	$0, -84(%rbp)
.L10:
	addl	$1, -76(%rbp)
.L7:
	movl	-92(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L12
	movl	-80(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.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:
