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

```c
/*
 * FileName:     D_fix
 * CreatedDate:  2020-07-04 01:20:42 +0900
 * LastModified: 2020-07-04 02:02:44 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    long int n, k;scanf("%ld%ld", &n, &k);
    long int *a = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)scanf("%ld", a+i);
    long int *order = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)order[i]=0;
    long int s = 1, cnt = 0;
    while(order[s]==0){
        order[s]=cnt++;
        s = a[s];
    }
    long int cycle = cnt-order[s];
    long int ini = cnt-cycle;
//    printf("%d,%d\n",ini,cycle);
    if(ini>k){
        for(long int i=0;i<n;i++){
            if(order[i]==k){
                printf("%ld\n",i);
                free(a);
                return 0;
            }
        }
    }
    long int cycle_gun = (k-ini)%cycle+ini;
    for(long int i=0;i<n+1;i++){
        if(order[i]==cycle_gun){
            printf("%ld\n",i);
        }
    }
    free(a);
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.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
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-104(%rbp), %rdx
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	$1, -96(%rbp)
	jmp	.L2
.L3:
	movq	-96(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -96(%rbp)
.L2:
	movq	-112(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jle	.L3
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	$1, -88(%rbp)
	jmp	.L4
.L5:
	movq	-88(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	addq	$1, -88(%rbp)
.L4:
	movq	-112(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jle	.L5
	movq	$1, -80(%rbp)
	movq	$0, -72(%rbp)
	jmp	.L6
.L7:
	movq	-72(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -72(%rbp)
	movq	-80(%rbp), %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, (%rdx)
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -80(%rbp)
.L6:
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L7
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-72(%rbp), %rax
	subq	%rdx, %rax
	movq	%rax, -32(%rbp)
	movq	-72(%rbp), %rax
	subq	-32(%rbp), %rax
	movq	%rax, -24(%rbp)
	movq	-104(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L8
	movq	$0, -64(%rbp)
	jmp	.L9
.L12:
	movq	-64(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-104(%rbp), %rax
	cmpq	%rax, %rdx
	jne	.L10
	movq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	jmp	.L16
.L10:
	addq	$1, -64(%rbp)
.L9:
	movq	-112(%rbp), %rax
	cmpq	%rax, -64(%rbp)
	jl	.L12
.L8:
	movq	-104(%rbp), %rax
	subq	-24(%rbp), %rax
	cqto
	idivq	-32(%rbp)
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -16(%rbp)
	movq	$0, -56(%rbp)
	jmp	.L13
.L15:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L14
	movq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L14:
	addq	$1, -56(%rbp)
.L13:
	movq	-112(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L15
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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	"%ld%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rbx
	leaq	8(,%rbx,8), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rbx, %rbx
	jle	.L2
	leaq	8(%rax), %r13
	movl	$1, %r12d
	leaq	.LC1(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r13, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %r12
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rbx
	addq	$8, %r13
	cmpq	%r12, %rbx
	jge	.L3
	leaq	8(,%rbx,8), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %r13
	testq	%rbx, %rbx
	jle	.L28
	leaq	8(%rax), %rcx
	leaq	-8(%r12), %rdx
	xorl	%esi, %esi
	movq	%rcx, %rdi
	call	memset@PLT
	movq	%rax, %rcx
.L4:
	movq	8(%r13), %rdx
	testq	%rdx, %rdx
	jne	.L18
	movl	$8, %eax
	.p2align 4,,10
	.p2align 3
.L6:
	movq	0(%rbp,%rax), %rax
	movq	%rdx, %rsi
	addq	$1, %rdx
	movq	%rsi, (%rcx)
	salq	$3, %rax
	leaq	0(%r13,%rax), %rcx
	movq	(%rcx), %rsi
	testq	%rsi, %rsi
	je	.L6
.L5:
	movq	16(%rsp), %rax
	movq	%rdx, %rcx
	subq	%rsi, %rcx
	cmpq	%rsi, %rax
	jge	.L7
	testq	%rbx, %rbx
	jle	.L7
	xorl	%edx, %edx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L8:
	addq	$1, %rdx
	cmpq	%rdx, %rbx
	je	.L30
.L10:
	cmpq	0(%r13,%rdx,8), %rax
	jne	.L8
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	jmp	.L9
.L7:
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	leaq	(%rdx,%rsi), %r12
	testq	%rbx, %rbx
	js	.L15
.L12:
	xorl	%r14d, %r14d
	leaq	.LC2(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L16:
	cmpq	0(%r13,%r14,8), %r12
	je	.L31
	addq	$1, %r14
	cmpq	%rbx, %r14
	jle	.L16
.L15:
	movq	%rbp, %rdi
	call	free@PLT
.L9:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	movq	%r14, %rdx
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rbx
	addq	$1, %r14
	cmpq	%rbx, %r14
	jle	.L16
	jmp	.L15
.L30:
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	leaq	(%rdx,%rsi), %r12
	jmp	.L12
.L18:
	movq	%rdx, %rsi
	xorl	%edx, %edx
	jmp	.L5
.L2:
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %r13
.L28:
	leaq	8(%r13), %rcx
	jmp	.L4
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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	"%ld%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rbx
	leaq	8(,%rbx,8), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rbx, %rbx
	jle	.L2
	leaq	8(%rax), %r13
	movl	$1, %r12d
	leaq	.LC1(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r13, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %r12
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rbx
	addq	$8, %r13
	cmpq	%r12, %rbx
	jge	.L3
	leaq	8(,%rbx,8), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %r13
	testq	%rbx, %rbx
	jle	.L28
	leaq	8(%rax), %rcx
	leaq	-8(%r12), %rdx
	xorl	%esi, %esi
	movq	%rcx, %rdi
	call	memset@PLT
	movq	%rax, %rcx
.L4:
	movq	8(%r13), %rdx
	testq	%rdx, %rdx
	jne	.L18
	movl	$8, %eax
	.p2align 4,,10
	.p2align 3
.L6:
	movq	0(%rbp,%rax), %rax
	movq	%rdx, %rsi
	addq	$1, %rdx
	movq	%rsi, (%rcx)
	salq	$3, %rax
	leaq	0(%r13,%rax), %rcx
	movq	(%rcx), %rsi
	testq	%rsi, %rsi
	je	.L6
.L5:
	movq	16(%rsp), %rax
	movq	%rdx, %rcx
	subq	%rsi, %rcx
	cmpq	%rsi, %rax
	jge	.L7
	testq	%rbx, %rbx
	jle	.L7
	xorl	%edx, %edx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L8:
	addq	$1, %rdx
	cmpq	%rdx, %rbx
	je	.L30
.L10:
	cmpq	0(%r13,%rdx,8), %rax
	jne	.L8
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	jmp	.L9
.L7:
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	leaq	(%rdx,%rsi), %r12
	testq	%rbx, %rbx
	js	.L15
.L12:
	xorl	%r14d, %r14d
	leaq	.LC2(%rip), %r15
	.p2align 4,,10
	.p2align 3
.L16:
	cmpq	0(%r13,%r14,8), %r12
	je	.L31
	addq	$1, %r14
	cmpq	%rbx, %r14
	jle	.L16
.L15:
	movq	%rbp, %rdi
	call	free@PLT
.L9:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	movq	%r14, %rdx
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rbx
	addq	$1, %r14
	cmpq	%rbx, %r14
	jle	.L16
	jmp	.L15
.L30:
	subq	%rsi, %rax
	cqto
	idivq	%rcx
	leaq	(%rdx,%rsi), %r12
	jmp	.L12
.L18:
	movq	%rdx, %rsi
	xorl	%edx, %edx
	jmp	.L5
.L2:
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%rax, %r13
.L28:
	leaq	8(%r13), %rcx
	jmp	.L4
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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:

/*
 * FileName:     D_fix
 * CreatedDate:  2020-07-04 01:20:42 +0900
 * LastModified: 2020-07-04 02:02:44 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    long int n, k;scanf("%ld%ld", &n, &k);
    long int *a = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)scanf("%ld", a+i);
    long int *order = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)order[i]=0;
    long int s = 1, cnt = 0;
    while(order[s]==0){
        order[s]=cnt++;
        s = a[s];
    }
    long int cycle = cnt-order[s];
    long int ini = cnt-cycle;
//    printf("%d,%d\n",ini,cycle);
    if(ini>k){
        for(long int i=0;i<n;i++){
            if(order[i]==k){
                printf("%ld\n",i);
                free(a);
                return 0;
            }
        }
    }
    long int cycle_gun = (k-ini)%cycle+ini;
    for(long int i=0;i<n+1;i++){
        if(order[i]==cycle_gun){
            printf("%ld\n",i);
        }
    }
    free(a);
    return 0;
}

6 727202214173249351
6 5 1 5 3 2
 4 9
3 2 4 1
 6 1007784494318310970
6 5 2 5 3 2
 6 237500909755776657
6 4 1 5 3 2
 6 727202214173249351
4 5 2 5 3 2
 6 165759462200935729
4 5 2 5 3 2
 6 727202214173249351
6 4 1 5 3 2
 4 0
3 2 4 1
 6 727202214173249351
6 4 1 1 3 2
 6 237500909755776657
2 4 1 5 3 2

6
 1
 3
 4
 5
 2
 3
 0
 4
 4

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

```c
/*
 * FileName:     D_fix
 * CreatedDate:  2020-07-04 01:20:42 +0900
 * LastModified: 2020-07-04 02:02:44 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    long int n, k;scanf("%ld%ld", &n, &k);
    long int *a = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)scanf("%ld", a+i);
    long int *order = malloc((n+1)*sizeof(long int));
    for(long int i=1;i<n+1;i++)order[i]=0;
    long int s = 1, cnt = 0;
    while(order[s]==0){
        order[s]=cnt++;
        s = a[s];
    }
    long int cycle = cnt-order[s];
    long int ini = cnt-cycle;
//    printf("%d,%d\n",ini,cycle);
    if(ini>k){
        for(long int i=0;i<n;i++){
            if(order[i]==k){
                printf("%ld\n",i);
                free(a);
                return 0;
            }
        }
    }
    long int cycle_gun = (k-ini)%cycle+ini;
    for(long int i=0;i<n+1;i++){
        if(order[i]==cycle_gun){
            printf("%ld\n",i);
        }
    }
    free(a);
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.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
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-104(%rbp), %rdx
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	$1, -96(%rbp)
	jmp	.L2
.L3:
	movq	-96(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -96(%rbp)
.L2:
	movq	-112(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jle	.L3
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	$1, -88(%rbp)
	jmp	.L4
.L5:
	movq	-88(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	addq	$1, -88(%rbp)
.L4:
	movq	-112(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jle	.L5
	movq	$1, -80(%rbp)
	movq	$0, -72(%rbp)
	jmp	.L6
.L7:
	movq	-72(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -72(%rbp)
	movq	-80(%rbp), %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, (%rdx)
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -80(%rbp)
.L6:
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L7
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-72(%rbp), %rax
	subq	%rdx, %rax
	movq	%rax, -32(%rbp)
	movq	-72(%rbp), %rax
	subq	-32(%rbp), %rax
	movq	%rax, -24(%rbp)
	movq	-104(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L8
	movq	$0, -64(%rbp)
	jmp	.L9
.L12:
	movq	-64(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-104(%rbp), %rax
	cmpq	%rax, %rdx
	jne	.L10
	movq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	jmp	.L16
.L10:
	addq	$1, -64(%rbp)
.L9:
	movq	-112(%rbp), %rax
	cmpq	%rax, -64(%rbp)
	jl	.L12
.L8:
	movq	-104(%rbp), %rax
	subq	-24(%rbp), %rax
	cqto
	idivq	-32(%rbp)
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -16(%rbp)
	movq	$0, -56(%rbp)
	jmp	.L13
.L15:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L14
	movq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L14:
	addq	$1, -56(%rbp)
.L13:
	movq	-112(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L15
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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
	.section	.rodata
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
	.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
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-104(%rbp), %rdx
	leaq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	$1, -96(%rbp)
	jmp	.L2
.L3:
	movq	-96(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -96(%rbp)
.L2:
	movq	-112(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jle	.L3
	movq	-112(%rbp), %rax
	addq	$1, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	$1, -88(%rbp)
	jmp	.L4
.L5:
	movq	-88(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	addq	$1, -88(%rbp)
.L4:
	movq	-112(%rbp), %rax
	cmpq	%rax, -88(%rbp)
	jle	.L5
	movq	$1, -80(%rbp)
	movq	$0, -72(%rbp)
	jmp	.L6
.L7:
	movq	-72(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -72(%rbp)
	movq	-80(%rbp), %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-40(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, (%rdx)
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	%rax, -80(%rbp)
.L6:
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L7
	movq	-80(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-72(%rbp), %rax
	subq	%rdx, %rax
	movq	%rax, -32(%rbp)
	movq	-72(%rbp), %rax
	subq	-32(%rbp), %rax
	movq	%rax, -24(%rbp)
	movq	-104(%rbp), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L8
	movq	$0, -64(%rbp)
	jmp	.L9
.L12:
	movq	-64(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movq	-104(%rbp), %rax
	cmpq	%rax, %rdx
	jne	.L10
	movq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	jmp	.L16
.L10:
	addq	$1, -64(%rbp)
.L9:
	movq	-112(%rbp), %rax
	cmpq	%rax, -64(%rbp)
	jl	.L12
.L8:
	movq	-104(%rbp), %rax
	subq	-24(%rbp), %rax
	cqto
	idivq	-32(%rbp)
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -16(%rbp)
	movq	$0, -56(%rbp)
	jmp	.L13
.L15:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	cmpq	%rax, -16(%rbp)
	jne	.L14
	movq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L14:
	addq	$1, -56(%rbp)
.L13:
	movq	-112(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L15
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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:
