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

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int n; scanf("%d", &n);
    int a[101010], ch[101010] = {0};
    rep(i,n) scanf("%d", a+i+1);
    int ans = 0, tmp = 1;
    while(tmp != 2 && ch[tmp] == 0){
        ch[tmp] = 1;
        ans++;
        tmp = a[tmp];
    }
    if(tmp != 2) ans=-1;
    printf("%d", ans);
}
```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-806912(%rsp), %r11
	.cfi_def_cfa 11, 806944
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1200, %rsp
	.cfi_def_cfa_offset 808144
	leaq	.LC0(%rip), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 808104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	20(%rsp), %rbp
	call	__isoc99_scanf@PLT
	xorl	%esi, %esi
	movl	$404040, %edx
	leaq	404064(%rsp), %rdi
	call	memset@PLT
	movl	12(%rsp), %esi
	testl	%esi, %esi
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	%ebx, 12(%rsp)
	jg	.L4
.L5:
	xorl	%edx, %edx
	movl	$1, %eax
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L18:
	movl	404064(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L17
.L3:
	movl	$1, 404064(%rsp,%rax,4)
	movslq	16(%rsp,%rax,4), %rax
	addl	$1, %edx
	cmpl	$2, %eax
	jne	.L18
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	808104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$808112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L17:
	.cfi_restore_state
	orl	$-1, %edx
	jmp	.L6
.L19:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-806912(%rsp), %r11
	.cfi_def_cfa 11, 806944
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1200, %rsp
	.cfi_def_cfa_offset 808144
	leaq	.LC0(%rip), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 808104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	20(%rsp), %rbp
	call	__isoc99_scanf@PLT
	xorl	%esi, %esi
	movl	$404040, %edx
	leaq	404064(%rsp), %rdi
	call	memset@PLT
	movl	12(%rsp), %esi
	testl	%esi, %esi
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	%ebx, 12(%rsp)
	jg	.L4
.L5:
	xorl	%edx, %edx
	movl	$1, %eax
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L18:
	movl	404064(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L17
.L3:
	movl	$1, 404064(%rsp,%rax,4)
	movslq	16(%rsp,%rax,4), %rax
	addl	$1, %edx
	cmpl	$2, %eax
	jne	.L18
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	808104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$808112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L17:
	.cfi_restore_state
	orl	$-1, %edx
	jmp	.L6
.L19:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
	.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
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-806912(%rsp), %r11
	.cfi_def_cfa 11, 806944
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1200, %rsp
	.cfi_def_cfa_offset 808144
	leaq	.LC0(%rip), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 808104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	20(%rsp), %rbp
	call	__isoc99_scanf@PLT
	xorl	%esi, %esi
	movl	$404040, %edx
	leaq	404064(%rsp), %rdi
	call	memset@PLT
	movl	12(%rsp), %esi
	testl	%esi, %esi
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	%ebx, 12(%rsp)
	jg	.L4
.L5:
	xorl	%edx, %edx
	movl	$1, %eax
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L18:
	movl	404064(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L17
.L3:
	movl	$1, 404064(%rsp,%rax,4)
	movslq	16(%rsp,%rax,4), %rax
	addl	$1, %edx
	cmpl	$2, %eax
	jne	.L18
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	808104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$808112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L17:
	.cfi_restore_state
	orl	$-1, %edx
	jmp	.L6
.L19:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
	.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:
```
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int n; scanf("%d", &n);
    int a[101010], ch[101010] = {0};
    rep(i,n) scanf("%d", a+i+1);
    int ans = 0, tmp = 1;
    while(tmp != 2 && ch[tmp] == 0){
        ch[tmp] = 1;
        ans++;
        tmp = a[tmp];
    }
    if(tmp != 2) ans=-1;
    printf("%d", ans);
}
```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int n; scanf("%d", &n);
    int a[101010], ch[101010] = {0};
    rep(i,n) scanf("%d", a+i+1);
    int ans = 0, tmp = 1;
    while(tmp != 2 && ch[tmp] == 0){
        ch[tmp] = 1;
        ans++;
        tmp = a[tmp];
    }
    if(tmp != 2) ans=-1;
    printf("%d", ans);
}
```

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.
Optimized Assembly Code:

3
3
1
3
 5
3
3
5
2
4
 4
4
3
1
2
 3
2
2
1
 5
3
0
4
2
4
 4
3
3
1
2
 3
3
2
3
 4
4
3
0
2
 4
4
4
0
2
 4
4
7
0
2

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

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<stdbool.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define swap(a,b) {ll tp=a;a=b;b=tp;}
const ll MOD = 1000000007;

int main(){
    int n; scanf("%d", &n);
    int a[101010], ch[101010] = {0};
    rep(i,n) scanf("%d", a+i+1);
    int ans = 0, tmp = 1;
    while(tmp != 2 && ch[tmp] == 0){
        ch[tmp] = 1;
        ans++;
        tmp = a[tmp];
    }
    if(tmp != 2) ans=-1;
    printf("%d", ans);
}
```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-806912(%rsp), %r11
	.cfi_def_cfa 11, 806944
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1200, %rsp
	.cfi_def_cfa_offset 808144
	leaq	.LC0(%rip), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 808104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	20(%rsp), %rbp
	call	__isoc99_scanf@PLT
	xorl	%esi, %esi
	movl	$404040, %edx
	leaq	404064(%rsp), %rdi
	call	memset@PLT
	movl	12(%rsp), %esi
	testl	%esi, %esi
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	%ebx, 12(%rsp)
	jg	.L4
.L5:
	xorl	%edx, %edx
	movl	$1, %eax
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L18:
	movl	404064(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L17
.L3:
	movl	$1, 404064(%rsp,%rax,4)
	movslq	16(%rsp,%rax,4), %rax
	addl	$1, %edx
	cmpl	$2, %eax
	jne	.L18
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	808104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$808112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L17:
	.cfi_restore_state
	orl	$-1, %edx
	jmp	.L6
.L19:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-806912(%rsp), %r11
	.cfi_def_cfa 11, 806944
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1200, %rsp
	.cfi_def_cfa_offset 808144
	leaq	.LC0(%rip), %r12
	xorl	%ebx, %ebx
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 808104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	20(%rsp), %rbp
	call	__isoc99_scanf@PLT
	xorl	%esi, %esi
	movl	$404040, %edx
	leaq	404064(%rsp), %rdi
	call	memset@PLT
	movl	12(%rsp), %esi
	testl	%esi, %esi
	jle	.L5
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	%ebx, 12(%rsp)
	jg	.L4
.L5:
	xorl	%edx, %edx
	movl	$1, %eax
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L18:
	movl	404064(%rsp,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L17
.L3:
	movl	$1, 404064(%rsp,%rax,4)
	movslq	16(%rsp,%rax,4), %rax
	addl	$1, %edx
	cmpl	$2, %eax
	jne	.L18
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	808104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$808112, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L17:
	.cfi_restore_state
	orl	$-1, %edx
	jmp	.L6
.L19:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
	.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:
```