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 <strings.h>
#include <assert.h>

typedef struct node {
    struct node *prev;
    struct node *next;
    int v;
} Node;

int main()
{
    int i, n, q,x;
    Node *z;
    fscanf(stdin, "%d", &n);
    Node *root = NULL;
    Node END;
    END.next=NULL;
    END.prev=NULL;
    Node *cursor = &END;
    Node *tmp;
    root = &END;

    for (i=0; i<n; i++) {
        fscanf(stdin, "%d", &q);
        switch (q) {
            case 0:  // insert
               fscanf(stdin, "%d", &x);
                z = (Node*)malloc(sizeof(Node));
                z->prev = cursor->prev;
                if (cursor->prev==NULL) {
                    root = z;
                } else {
                    cursor->prev->next = z;
                }
                cursor->prev=z;
                z->next = cursor;
                z->v = x;
                cursor = z;
                break;
            case 1:  // move
                fscanf(stdin, "%d", &x);
                if (x>0)
                    for (int j=0; j<x; j++) {
                        cursor = cursor->next;
                        if (cursor==NULL) break;
                    }
                else
                    for (int j=0; j<-x; j++)
                        cursor = cursor->prev;
                break;
            case 2:  //erase
                cursor->next->prev = cursor->prev;
                if (cursor->prev!=NULL)
                    cursor->prev->next = cursor->next;
                else
                    root = cursor->next;
                tmp = cursor;
                cursor = cursor->next;
                free(tmp);
        }
    }

    tmp = root;
    do {
        printf("%d\n", tmp->v);
        tmp = tmp->next;
    } while (tmp->next);
    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:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	leaq	-88(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movq	$0, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -32(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -56(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -64(%rbp)
	movl	$0, -76(%rbp)
	jmp	.L2
.L19:
	movq	stdin(%rip), %rax
	leaq	-84(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-84(%rbp), %eax
	cmpl	$2, %eax
	je	.L3
	cmpl	$2, %eax
	jg	.L4
	testl	%eax, %eax
	je	.L5
	cmpl	$1, %eax
	je	.L6
	jmp	.L4
.L5:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	$24, %edi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-56(%rbp), %rax
	movq	(%rax), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	jne	.L7
	movq	-40(%rbp), %rax
	movq	%rax, -64(%rbp)
	jmp	.L8
.L7:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, 8(%rax)
.L8:
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, (%rax)
	movq	-40(%rbp), %rax
	movq	-56(%rbp), %rdx
	movq	%rdx, 8(%rax)
	movl	-80(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, 16(%rax)
	movq	-40(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L4
.L6:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-80(%rbp), %eax
	testl	%eax, %eax
	jle	.L9
	movl	$0, -72(%rbp)
	jmp	.L10
.L13:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	cmpq	$0, -56(%rbp)
	je	.L24
	addl	$1, -72(%rbp)
.L10:
	movl	-80(%rbp), %eax
	cmpl	%eax, -72(%rbp)
	jl	.L13
	jmp	.L4
.L9:
	movl	$0, -68(%rbp)
	jmp	.L15
.L16:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -56(%rbp)
	addl	$1, -68(%rbp)
.L15:
	movl	-80(%rbp), %eax
	negl	%eax
	cmpl	%eax, -68(%rbp)
	jl	.L16
	jmp	.L4
.L24:
	nop
	jmp	.L4
.L3:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	(%rdx), %rdx
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L17
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	8(%rdx), %rdx
	movq	%rdx, 8(%rax)
	jmp	.L18
.L17:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -64(%rbp)
.L18:
	movq	-56(%rbp), %rax
	movq	%rax, -48(%rbp)
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
.L4:
	addl	$1, -76(%rbp)
.L2:
	movl	-88(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L19
	movq	-64(%rbp), %rax
	movq	%rax, -48(%rbp)
.L20:
	movq	-48(%rbp), %rax
	movl	16(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -48(%rbp)
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	testq	%rax, %rax
	jne	.L20
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	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"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	stdin(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rdx
	call	__isoc99_fscanf@PLT
	movl	20(%rsp), %eax
	pxor	%xmm0, %xmm0
	movaps	%xmm0, 32(%rsp)
	testl	%eax, %eax
	jle	.L13
	leaq	32(%rsp), %rbp
	xorl	%r12d, %r12d
	leaq	24(%rsp), %r14
	movq	%rbp, %rbx
	leaq	28(%rsp), %r15
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L30:
	testl	%eax, %eax
	je	.L29
.L5:
	addl	$1, %r12d
	cmpl	%r12d, 20(%rsp)
	jle	.L2
.L10:
	movq	stdin(%rip), %rdi
	movq	%r14, %rdx
	movq	%r13, %rsi
	xorl	%eax, %eax
	call	__isoc99_fscanf@PLT
	movl	24(%rsp), %eax
	cmpl	$1, %eax
	je	.L3
	cmpl	$2, %eax
	jne	.L30
	movq	8(%rbp), %rax
	movq	0(%rbp), %rdx
	movq	%rdx, (%rax)
	testq	%rdx, %rdx
	je	.L17
	movq	%rax, 8(%rdx)
	movq	8(%rbp), %rax
.L9:
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	addl	$1, %r12d
	call	free@PLT
	movq	8(%rsp), %rbp
	cmpl	%r12d, 20(%rsp)
	jg	.L10
.L2:
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L11:
	movl	16(%rbx), %edx
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rbx), %rbx
	cmpq	$0, 8(%rbx)
	jne	.L11
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$72, %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
.L3:
	.cfi_restore_state
	movq	stdin(%rip), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	xorl	%eax, %eax
	call	__isoc99_fscanf@PLT
	movl	28(%rsp), %edx
	xorl	%eax, %eax
	testl	%edx, %edx
	jle	.L32
	.p2align 4,,10
	.p2align 3
.L7:
	movq	8(%rbp), %rbp
	testq	%rbp, %rbp
	je	.L5
	addl	$1, %eax
	cmpl	%eax, %edx
	jne	.L7
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L29:
	movq	stdin(%rip), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	call	__isoc99_fscanf@PLT
	movl	$24, %edi
	call	malloc@PLT
	movq	0(%rbp), %rdx
	movq	%rdx, (%rax)
	movq	0(%rbp), %rdx
	testq	%rdx, %rdx
	je	.L14
	movq	%rax, 8(%rdx)
.L6:
	movl	28(%rsp), %edx
	movq	%rax, 0(%rbp)
	movq	%rbp, 8(%rax)
	movq	%rax, %rbp
	movl	%edx, 16(%rax)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L32:
	movl	%edx, %ecx
	negl	%ecx
	testl	%edx, %edx
	je	.L5
	.p2align 4,,10
	.p2align 3
.L8:
	addl	$1, %eax
	movq	0(%rbp), %rbp
	cmpl	%ecx, %eax
	jl	.L8
	jmp	.L5
.L17:
	movq	%rax, %rbx
	jmp	.L9
.L14:
	movq	%rax, %rbx
	jmp	.L6
.L13:
	leaq	32(%rsp), %rbx
	jmp	.L2
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.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:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	stdin(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rdx
	call	__isoc99_fscanf@PLT
	movl	20(%rsp), %eax
	pxor	%xmm0, %xmm0
	movaps	%xmm0, 32(%rsp)
	testl	%eax, %eax
	jle	.L13
	leaq	32(%rsp), %rbp
	xorl	%r12d, %r12d
	leaq	24(%rsp), %r14
	movq	%rbp, %rbx
	leaq	28(%rsp), %r15
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L30:
	testl	%eax, %eax
	je	.L29
.L5:
	addl	$1, %r12d
	cmpl	%r12d, 20(%rsp)
	jle	.L2
.L10:
	movq	stdin(%rip), %rdi
	movq	%r14, %rdx
	movq	%r13, %rsi
	xorl	%eax, %eax
	call	__isoc99_fscanf@PLT
	movl	24(%rsp), %eax
	cmpl	$1, %eax
	je	.L3
	cmpl	$2, %eax
	jne	.L30
	movq	8(%rbp), %rax
	movq	0(%rbp), %rdx
	movq	%rdx, (%rax)
	testq	%rdx, %rdx
	je	.L17
	movq	%rax, 8(%rdx)
	movq	8(%rbp), %rax
.L9:
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	addl	$1, %r12d
	call	free@PLT
	movq	8(%rsp), %rbp
	cmpl	%r12d, 20(%rsp)
	jg	.L10
.L2:
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L11:
	movl	16(%rbx), %edx
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rbx), %rbx
	cmpq	$0, 8(%rbx)
	jne	.L11
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	addq	$72, %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
.L3:
	.cfi_restore_state
	movq	stdin(%rip), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	xorl	%eax, %eax
	call	__isoc99_fscanf@PLT
	movl	28(%rsp), %edx
	xorl	%eax, %eax
	testl	%edx, %edx
	jle	.L32
	.p2align 4,,10
	.p2align 3
.L7:
	movq	8(%rbp), %rbp
	testq	%rbp, %rbp
	je	.L5
	addl	$1, %eax
	cmpl	%eax, %edx
	jne	.L7
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L29:
	movq	stdin(%rip), %rdi
	movq	%r15, %rdx
	movq	%r13, %rsi
	call	__isoc99_fscanf@PLT
	movl	$24, %edi
	call	malloc@PLT
	movq	0(%rbp), %rdx
	movq	%rdx, (%rax)
	movq	0(%rbp), %rdx
	testq	%rdx, %rdx
	je	.L14
	movq	%rax, 8(%rdx)
.L6:
	movl	28(%rsp), %edx
	movq	%rax, 0(%rbp)
	movq	%rbp, 8(%rax)
	movq	%rax, %rbp
	movl	%edx, 16(%rax)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L32:
	movl	%edx, %ecx
	negl	%ecx
	testl	%edx, %edx
	je	.L5
	.p2align 4,,10
	.p2align 3
.L8:
	addl	$1, %eax
	movq	0(%rbp), %rbp
	cmpl	%ecx, %eax
	jl	.L8
	jmp	.L5
.L17:
	movq	%rax, %rbx
	jmp	.L9
.L14:
	movq	%rax, %rbx
	jmp	.L6
.L13:
	leaq	32(%rsp), %rbx
	jmp	.L2
.L31:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE41:
	.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>
#include <stdlib.h>
#include <strings.h>
#include <assert.h>

typedef struct node {
    struct node *prev;
    struct node *next;
    int v;
} Node;

int main()
{
    int i, n, q,x;
    Node *z;
    fscanf(stdin, "%d", &n);
    Node *root = NULL;
    Node END;
    END.next=NULL;
    END.prev=NULL;
    Node *cursor = &END;
    Node *tmp;
    root = &END;

    for (i=0; i<n; i++) {
        fscanf(stdin, "%d", &q);
        switch (q) {
            case 0:  // insert
               fscanf(stdin, "%d", &x);
                z = (Node*)malloc(sizeof(Node));
                z->prev = cursor->prev;
                if (cursor->prev==NULL) {
                    root = z;
                } else {
                    cursor->prev->next = z;
                }
                cursor->prev=z;
                z->next = cursor;
                z->v = x;
                cursor = z;
                break;
            case 1:  // move
                fscanf(stdin, "%d", &x);
                if (x>0)
                    for (int j=0; j<x; j++) {
                        cursor = cursor->next;
                        if (cursor==NULL) break;
                    }
                else
                    for (int j=0; j<-x; j++)
                        cursor = cursor->prev;
                break;
            case 2:  //erase
                cursor->next->prev = cursor->prev;
                if (cursor->prev!=NULL)
                    cursor->prev->next = cursor->next;
                else
                    root = cursor->next;
                tmp = cursor;
                cursor = cursor->next;
                free(tmp);
        }
    }

    tmp = root;
    do {
        printf("%d\n", tmp->v);
        tmp = tmp->next;
    } while (tmp->next);
    return 0;
}

5
0 1
0 2
0 2
1 1
2
 5
0 1
0 2
0 2
0 1
2
 5
0 1
0 2
0 3
0 1
2
 5
0 1
0 2
0 4
1 1
2
 5
0 1
0 2
0 4
0 0
2
 5
0 1
0 0
0 2
0 0
2
 5
0 1
0 0
0 1
0 0
2
 5
0 1
0 0
0 1
1 0
2
 5
0 1
0 -1
0 1
1 0
2

2
1
 2
2
1
 3
2
1
 4
1
 4
2
1
 2
0
1
 1
0
1
 0
1
 -1
1

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 <strings.h>
#include <assert.h>

typedef struct node {
    struct node *prev;
    struct node *next;
    int v;
} Node;

int main()
{
    int i, n, q,x;
    Node *z;
    fscanf(stdin, "%d", &n);
    Node *root = NULL;
    Node END;
    END.next=NULL;
    END.prev=NULL;
    Node *cursor = &END;
    Node *tmp;
    root = &END;

    for (i=0; i<n; i++) {
        fscanf(stdin, "%d", &q);
        switch (q) {
            case 0:  // insert
               fscanf(stdin, "%d", &x);
                z = (Node*)malloc(sizeof(Node));
                z->prev = cursor->prev;
                if (cursor->prev==NULL) {
                    root = z;
                } else {
                    cursor->prev->next = z;
                }
                cursor->prev=z;
                z->next = cursor;
                z->v = x;
                cursor = z;
                break;
            case 1:  // move
                fscanf(stdin, "%d", &x);
                if (x>0)
                    for (int j=0; j<x; j++) {
                        cursor = cursor->next;
                        if (cursor==NULL) break;
                    }
                else
                    for (int j=0; j<-x; j++)
                        cursor = cursor->prev;
                break;
            case 2:  //erase
                cursor->next->prev = cursor->prev;
                if (cursor->prev!=NULL)
                    cursor->prev->next = cursor->next;
                else
                    root = cursor->next;
                tmp = cursor;
                cursor = cursor->next;
                free(tmp);
        }
    }

    tmp = root;
    do {
        printf("%d\n", tmp->v);
        tmp = tmp->next;
    } while (tmp->next);
    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:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	leaq	-88(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movq	$0, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -32(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -56(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -64(%rbp)
	movl	$0, -76(%rbp)
	jmp	.L2
.L19:
	movq	stdin(%rip), %rax
	leaq	-84(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-84(%rbp), %eax
	cmpl	$2, %eax
	je	.L3
	cmpl	$2, %eax
	jg	.L4
	testl	%eax, %eax
	je	.L5
	cmpl	$1, %eax
	je	.L6
	jmp	.L4
.L5:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	$24, %edi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-56(%rbp), %rax
	movq	(%rax), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	jne	.L7
	movq	-40(%rbp), %rax
	movq	%rax, -64(%rbp)
	jmp	.L8
.L7:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, 8(%rax)
.L8:
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, (%rax)
	movq	-40(%rbp), %rax
	movq	-56(%rbp), %rdx
	movq	%rdx, 8(%rax)
	movl	-80(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, 16(%rax)
	movq	-40(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L4
.L6:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-80(%rbp), %eax
	testl	%eax, %eax
	jle	.L9
	movl	$0, -72(%rbp)
	jmp	.L10
.L13:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	cmpq	$0, -56(%rbp)
	je	.L24
	addl	$1, -72(%rbp)
.L10:
	movl	-80(%rbp), %eax
	cmpl	%eax, -72(%rbp)
	jl	.L13
	jmp	.L4
.L9:
	movl	$0, -68(%rbp)
	jmp	.L15
.L16:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -56(%rbp)
	addl	$1, -68(%rbp)
.L15:
	movl	-80(%rbp), %eax
	negl	%eax
	cmpl	%eax, -68(%rbp)
	jl	.L16
	jmp	.L4
.L24:
	nop
	jmp	.L4
.L3:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	(%rdx), %rdx
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L17
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	8(%rdx), %rdx
	movq	%rdx, 8(%rax)
	jmp	.L18
.L17:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -64(%rbp)
.L18:
	movq	-56(%rbp), %rax
	movq	%rax, -48(%rbp)
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
.L4:
	addl	$1, -76(%rbp)
.L2:
	movl	-88(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L19
	movq	-64(%rbp), %rax
	movq	%rax, -48(%rbp)
.L20:
	movq	-48(%rbp), %rax
	movl	16(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -48(%rbp)
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	testq	%rax, %rax
	jne	.L20
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	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	"%d"
.LC1:
	.string	"%d\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	$96, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	leaq	-88(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movq	$0, -64(%rbp)
	movq	$0, -24(%rbp)
	movq	$0, -32(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -56(%rbp)
	leaq	-32(%rbp), %rax
	movq	%rax, -64(%rbp)
	movl	$0, -76(%rbp)
	jmp	.L2
.L19:
	movq	stdin(%rip), %rax
	leaq	-84(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-84(%rbp), %eax
	cmpl	$2, %eax
	je	.L3
	cmpl	$2, %eax
	jg	.L4
	testl	%eax, %eax
	je	.L5
	cmpl	$1, %eax
	je	.L6
	jmp	.L4
.L5:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	$24, %edi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-56(%rbp), %rax
	movq	(%rax), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	jne	.L7
	movq	-40(%rbp), %rax
	movq	%rax, -64(%rbp)
	jmp	.L8
.L7:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, 8(%rax)
.L8:
	movq	-56(%rbp), %rax
	movq	-40(%rbp), %rdx
	movq	%rdx, (%rax)
	movq	-40(%rbp), %rax
	movq	-56(%rbp), %rdx
	movq	%rdx, 8(%rax)
	movl	-80(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%edx, 16(%rax)
	movq	-40(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L4
.L6:
	movq	stdin(%rip), %rax
	leaq	-80(%rbp), %rdx
	leaq	.LC0(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_fscanf@PLT
	movl	-80(%rbp), %eax
	testl	%eax, %eax
	jle	.L9
	movl	$0, -72(%rbp)
	jmp	.L10
.L13:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	cmpq	$0, -56(%rbp)
	je	.L24
	addl	$1, -72(%rbp)
.L10:
	movl	-80(%rbp), %eax
	cmpl	%eax, -72(%rbp)
	jl	.L13
	jmp	.L4
.L9:
	movl	$0, -68(%rbp)
	jmp	.L15
.L16:
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -56(%rbp)
	addl	$1, -68(%rbp)
.L15:
	movl	-80(%rbp), %eax
	negl	%eax
	cmpl	%eax, -68(%rbp)
	jl	.L16
	jmp	.L4
.L24:
	nop
	jmp	.L4
.L3:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	(%rdx), %rdx
	movq	%rdx, (%rax)
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	testq	%rax, %rax
	je	.L17
	movq	-56(%rbp), %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	movq	8(%rdx), %rdx
	movq	%rdx, 8(%rax)
	jmp	.L18
.L17:
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -64(%rbp)
.L18:
	movq	-56(%rbp), %rax
	movq	%rax, -48(%rbp)
	movq	-56(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -56(%rbp)
	movq	-48(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
.L4:
	addl	$1, -76(%rbp)
.L2:
	movl	-88(%rbp), %eax
	cmpl	%eax, -76(%rbp)
	jl	.L19
	movq	-64(%rbp), %rax
	movq	%rax, -48(%rbp)
.L20:
	movq	-48(%rbp), %rax
	movl	16(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	movq	%rax, -48(%rbp)
	movq	-48(%rbp), %rax
	movq	8(%rax), %rax
	testq	%rax, %rax
	jne	.L20
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	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:
