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 argc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int p[100000];
  int ans = 0, l;
  for(int i = 0; i < n; i++){
    scanf("%d", &p[i]);
    if(p[i] == i + 1) l++;
    else{
      ans += l / 2 + l % 2;
      l = 0;
    }
  }
  ans += l / 2 + l % 2;
  printf("%d\n", ans);

  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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movl	%edi, -400036(%rbp)
	movq	%rsi, -400048(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L2
.L5:
	leaq	-400016(%rbp), %rdx
	movl	-400020(%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
	movl	-400020(%rbp), %eax
	cltq
	movl	-400016(%rbp,%rax,4), %eax
	movl	-400020(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	jne	.L3
	addl	$1, -400024(%rbp)
	jmp	.L4
.L3:
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	$0, -400024(%rbp)
.L4:
	addl	$1, -400020(%rbp)
.L2:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L5
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	-400028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	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
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397360
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2720, %rsp
	.cfi_def_cfa_offset 400080
	leaq	.LC0(%rip), %r12
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L7
	leaq	16(%rsp), %r13
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	cmpl	%r14d, 0(%r13)
	je	.L11
	movl	%ebx, %eax
	movl	%ebx, %edx
	addq	$4, %r13
	shrl	$31, %edx
	shrl	$31, %eax
	addl	%ebx, %eax
	addl	%edx, %ebx
	andl	$1, %ebx
	sarl	%eax
	subl	%edx, %ebx
	addl	%eax, %ebx
	addl	%ebx, %ebp
	xorl	%ebx, %ebx
	cmpl	12(%rsp), %r14d
	jl	.L5
.L2:
	movl	%ebx, %edx
	movl	%ebx, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	shrl	$31, %eax
	shrl	$31, %edx
	addl	%ebx, %edx
	addl	%eax, %ebx
	andl	$1, %ebx
	sarl	%edx
	subl	%eax, %ebx
	xorl	%eax, %eax
	addl	%ebx, %edx
	addl	%ebp, %edx
	call	__printf_chk@PLT
	movq	400024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$400032, %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
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	addl	$1, %ebx
	addq	$4, %r13
	cmpl	12(%rsp), %r14d
	jl	.L5
	jmp	.L2
.L7:
	xorl	%ebp, %ebp
	jmp	.L2
.L12:
	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
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	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
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397360
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2720, %rsp
	.cfi_def_cfa_offset 400080
	leaq	.LC0(%rip), %r12
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L7
	leaq	16(%rsp), %r13
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	cmpl	%r14d, 0(%r13)
	je	.L11
	movl	%ebx, %eax
	movl	%ebx, %edx
	addq	$4, %r13
	shrl	$31, %edx
	shrl	$31, %eax
	addl	%ebx, %eax
	addl	%edx, %ebx
	andl	$1, %ebx
	sarl	%eax
	subl	%edx, %ebx
	addl	%eax, %ebx
	addl	%ebx, %ebp
	xorl	%ebx, %ebx
	cmpl	12(%rsp), %r14d
	jl	.L5
.L2:
	movl	%ebx, %edx
	movl	%ebx, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	shrl	$31, %eax
	shrl	$31, %edx
	addl	%ebx, %edx
	addl	%eax, %ebx
	andl	$1, %ebx
	sarl	%edx
	subl	%eax, %ebx
	xorl	%eax, %eax
	addl	%ebx, %edx
	addl	%ebp, %edx
	call	__printf_chk@PLT
	movq	400024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$400032, %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
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	addl	$1, %ebx
	addq	$4, %r13
	cmpl	12(%rsp), %r14d
	jl	.L5
	jmp	.L2
.L7:
	xorl	%ebp, %ebp
	jmp	.L2
.L12:
	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 argc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int p[100000];
  int ans = 0, l;
  for(int i = 0; i < n; i++){
    scanf("%d", &p[i]);
    if(p[i] == i + 1) l++;
    else{
      ans += l / 2 + l % 2;
      l = 0;
    }
  }
  ans += l / 2 + l % 2;
  printf("%d\n", ans);

  return 0;
}

5
1 4 4 5 2
 9
1 2 4 9 5 8 7 6 6
 9
1 2 4 9 5 8 4 6 6
 5
0 4 4 5 1
 2
1 0
 2
1 1
 5
1 4 4 5 1
 2
1 -1
 2
0 2
 9
2 2 4 9 5 8 4 6 6

1
 3
 2
 0
 1
 1
 1
 1
 1
 2

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 argc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int p[100000];
  int ans = 0, l;
  for(int i = 0; i < n; i++){
    scanf("%d", &p[i]);
    if(p[i] == i + 1) l++;
    else{
      ans += l / 2 + l % 2;
      l = 0;
    }
  }
  ans += l / 2 + l % 2;
  printf("%d\n", ans);

  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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movl	%edi, -400036(%rbp)
	movq	%rsi, -400048(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L2
.L5:
	leaq	-400016(%rbp), %rdx
	movl	-400020(%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
	movl	-400020(%rbp), %eax
	cltq
	movl	-400016(%rbp,%rax,4), %eax
	movl	-400020(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	jne	.L3
	addl	$1, -400024(%rbp)
	jmp	.L4
.L3:
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	$0, -400024(%rbp)
.L4:
	addl	$1, -400020(%rbp)
.L2:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L5
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	-400028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2736, %rsp
	movl	%edi, -400036(%rbp)
	movq	%rsi, -400048(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	movl	$0, -400020(%rbp)
	jmp	.L2
.L5:
	leaq	-400016(%rbp), %rdx
	movl	-400020(%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
	movl	-400020(%rbp), %eax
	cltq
	movl	-400016(%rbp,%rax,4), %eax
	movl	-400020(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	jne	.L3
	addl	$1, -400024(%rbp)
	jmp	.L4
.L3:
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	$0, -400024(%rbp)
.L4:
	addl	$1, -400020(%rbp)
.L2:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400020(%rbp)
	jl	.L5
	movl	-400024(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400024(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	addl	%ecx, %eax
	addl	%eax, -400028(%rbp)
	movl	-400028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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:
