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>
#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);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-806912(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-808112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-404048(%rbp), %rax
	movl	$404040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -808108(%rbp)
	jmp	.L2
.L3:
	movl	-808108(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	leaq	-808096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -808108(%rbp)
.L2:
	movl	-808112(%rbp), %eax
	cmpl	%eax, -808108(%rbp)
	jl	.L3
	movl	$0, -808104(%rbp)
	movl	$1, -808100(%rbp)
	jmp	.L4
.L6:
	movl	-808100(%rbp), %eax
	cltq
	movl	$1, -404048(%rbp,%rax,4)
	addl	$1, -808104(%rbp)
	movl	-808100(%rbp), %eax
	cltq
	movl	-808096(%rbp,%rax,4), %eax
	movl	%eax, -808100(%rbp)
.L4:
	cmpl	$2, -808100(%rbp)
	je	.L5
	movl	-808100(%rbp), %eax
	cltq
	movl	-404048(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L6
.L5:
	cmpl	$2, -808100(%rbp)
	je	.L7
	movl	$-1, -808104(%rbp)
.L7:
	movl	-808104(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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"
	.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
	.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:

#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);
}

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 unoptimized 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);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-806912(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-808112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-404048(%rbp), %rax
	movl	$404040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -808108(%rbp)
	jmp	.L2
.L3:
	movl	-808108(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	leaq	-808096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -808108(%rbp)
.L2:
	movl	-808112(%rbp), %eax
	cmpl	%eax, -808108(%rbp)
	jl	.L3
	movl	$0, -808104(%rbp)
	movl	$1, -808100(%rbp)
	jmp	.L4
.L6:
	movl	-808100(%rbp), %eax
	cltq
	movl	$1, -404048(%rbp,%rax,4)
	addl	$1, -808104(%rbp)
	movl	-808100(%rbp), %eax
	cltq
	movl	-808096(%rbp,%rax,4), %eax
	movl	%eax, -808100(%rbp)
.L4:
	cmpl	$2, -808100(%rbp)
	je	.L5
	movl	-808100(%rbp), %eax
	cltq
	movl	-404048(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L6
.L5:
	cmpl	$2, -808100(%rbp)
	je	.L7
	movl	$-1, -808104(%rbp)
.L7:
	movl	-808104(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	MOD
	.section	.rodata
	.align 8
	.type	MOD, @object
	.size	MOD, 8
MOD:
	.quad	1000000007
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-806912(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-808112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-404048(%rbp), %rax
	movl	$404040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -808108(%rbp)
	jmp	.L2
.L3:
	movl	-808108(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	leaq	-808096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -808108(%rbp)
.L2:
	movl	-808112(%rbp), %eax
	cmpl	%eax, -808108(%rbp)
	jl	.L3
	movl	$0, -808104(%rbp)
	movl	$1, -808100(%rbp)
	jmp	.L4
.L6:
	movl	-808100(%rbp), %eax
	cltq
	movl	$1, -404048(%rbp,%rax,4)
	addl	$1, -808104(%rbp)
	movl	-808100(%rbp), %eax
	cltq
	movl	-808096(%rbp,%rax,4), %eax
	movl	%eax, -808100(%rbp)
.L4:
	cmpl	$2, -808100(%rbp)
	je	.L5
	movl	-808100(%rbp), %eax
	cltq
	movl	-404048(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L6
.L5:
	cmpl	$2, -808100(%rbp)
	je	.L7
	movl	$-1, -808104(%rbp)
.L7:
	movl	-808104(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
