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>

#define OVER 2000000000

int main()
{
    int n;
    int *a;
    int *a_ng;
    int q;
    int x;
    int y;
    int ng = 0;
    int tmp;
    int i;
    
    scanf("%d", &n);
    
    a = (int *)malloc(sizeof(int) * (n + 2));
    a_ng = (int *)malloc(sizeof(int) * (n + 2));
    
    a[0] = OVER * (-1);
    a_ng[0] = 0;
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        a_ng[i] = 0;
    }
    a[i] = OVER;
    a_ng[i] = 0;
    
    for(i = 1; i <= n; i++)
    {
        if(a[i] > a[i + 1])
        {
            ng++;
            a_ng[i] = -1;
        }
    }
    
    if(ng == 0)
    {
        puts("0");
    }
    else
    {
        scanf("%d", &q);
        
        for(i = 0; i < q; i++)
        {
            scanf("%d%d", &x, &y);
            
            tmp = a[x];
            a[x] = a[y];
            a[y] = tmp;
            
            if(a[x - 1] <= a[x])
            {
                if(a_ng[x - 1] != 0)
                {
                    ng--;
                    a_ng[x - 1] = 0;
                }
            }
            else
            {
                if(a_ng[x - 1] == 0)
                {
                    ng++;
                    a_ng[x - 1] = -1;
                }
            }

            if(a[x] <= a [x + 1])
            {
                if(a_ng[x] != 0)
                {
                    ng--;
                    a_ng[x] = 0;
                }
            }
            else
            {
                if(a_ng[x] == 0)
                {
                    ng++;
                    a_ng[x] = -1;
                }
            }
            
            if(a[y - 1] <= a [y])
            {
                if(a_ng[y - 1] != 0)
                {
                    ng--;
                    a_ng[y - 1] = 0;
                }
            }
            else
            {
                if(a_ng[y - 1] == 0)
                {
                    ng++;
                    a_ng[y - 1] = -1;
                }
            }
            
            if(a[y] <= a [y + 1])
            {
                if(a_ng[y] != 0)
                {
                    ng--;
                    a_ng[y] = 0;
                }
            }
            else
            {
                if(a_ng[y] == 0)
                {
                    ng++;
                    a_ng[y] = -1;
                }
            }

            if(ng == 0)
            {
                printf("%d\n", i + 1);
                break;
            }
        }
        
        if(ng > 0)
        {
            puts("-1");
        }
    }
    
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"0"
.LC2:
	.string	"%d%d"
.LC3:
	.string	"%d\n"
.LC4:
	.string	"-1"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -36(%rbp)
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movl	$-2000000000, (%rax)
	movq	-16(%rbp), %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L2
.L3:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -32(%rbp)
.L2:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L3
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$2000000000, (%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L4
.L6:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L5
	addl	$1, -36(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L5:
	addl	$1, -32(%rbp)
.L4:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L6
	cmpl	$0, -36(%rbp)
	jne	.L7
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L8
.L7:
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L20:
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-44(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-28(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L10
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L11
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L11
.L10:
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L11
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L11:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L12
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L13
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L13
.L12:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L13
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L13:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L14
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L15
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L15
.L14:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L15
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L15:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L16
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L17
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L17
.L16:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L17
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L17:
	cmpl	$0, -36(%rbp)
	jne	.L18
	movl	-32(%rbp), %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L19
.L18:
	addl	$1, -32(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L20
.L19:
	cmpl	$0, -36(%rbp)
	jle	.L8
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L8:
	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	"0"
.LC2:
	.string	"-1"
.LC3:
	.string	"%d%d"
.LC4:
	.string	"%d\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), %r8
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %rdi
	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	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r12d
	leal	2(%r12), %ebp
	movslq	%ebp, %rbp
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$-2000000000, (%rbx)
	movl	$0, (%rax)
	testl	%r12d, %r12d
	jle	.L2
	movq	%rax, %rbp
	leaq	4(%rbx), %r14
	leaq	4(%rax), %r13
	movl	$1, %r12d
	leaq	.LC0(%rip), %r8
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r14, %rsi
	movq	%r8, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %eax
	movl	$0, 0(%r13)
	addq	$4, %r14
	addq	$4, %r13
	leaq	.LC0(%rip), %r8
	cmpl	%r12d, %eax
	jge	.L3
	movslq	%r12d, %r12
	movl	$2000000000, (%rbx,%r12,4)
	movl	$0, 0(%rbp,%r12,4)
	testl	%eax, %eax
	jle	.L4
	movl	4(%rbx), %edx
	leal	2(%rax), %esi
	xorl	%r15d, %r15d
	movl	$2, %eax
	.p2align 4,,10
	.p2align 3
.L6:
	movl	%edx, %ecx
	movl	(%rbx,%rax,4), %edx
	cmpl	%ecx, %edx
	jge	.L5
	movl	$-1, -4(%rbp,%rax,4)
	addl	$1, %r15d
.L5:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L6
	testl	%r15d, %r15d
	je	.L4
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	movq	%r8, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$0, 12(%rsp)
	jle	.L19
	xorl	%r12d, %r12d
	leaq	20(%rsp), %r14
	leaq	16(%rsp), %r13
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L43:
	testl	%r9d, %r9d
	je	.L13
	movl	$0, (%rcx)
	subl	$1, %r15d
.L13:
	leaq	-4(%rbp,%rax), %rdx
	movl	(%rdx), %ecx
	cmpl	%esi, -4(%rbx,%rax)
	jg	.L14
.L44:
	testl	%ecx, %ecx
	je	.L15
	movl	$0, (%rdx)
	subl	$1, %r15d
.L15:
	leaq	0(%rbp,%rax), %rdx
	movl	(%rdx), %ecx
	cmpl	%esi, 4(%rbx,%rax)
	jl	.L16
.L45:
	testl	%ecx, %ecx
	je	.L17
	movl	$0, (%rdx)
	subl	$1, %r15d
.L17:
	addl	$1, %r12d
	testl	%r15d, %r15d
	je	.L41
.L18:
	cmpl	%r12d, 12(%rsp)
	jle	.L42
.L9:
	movq	%r14, %rdx
	movq	%r13, %rsi
	leaq	.LC3(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	16(%rsp), %rdx
	movslq	20(%rsp), %rax
	salq	$2, %rdx
	salq	$2, %rax
	leaq	(%rbx,%rdx), %rdi
	leaq	(%rbx,%rax), %rcx
	movl	(%rdi), %esi
	movl	(%rcx), %r9d
	movl	%r9d, (%rdi)
	movl	%esi, (%rcx)
	leaq	-4(%rdx), %rcx
	movl	(%rdi), %edi
	addq	%rbp, %rcx
	cmpl	%edi, -4(%rbx,%rdx)
	jg	.L10
	movl	(%rcx), %r9d
	testl	%r9d, %r9d
	je	.L11
	movl	$0, (%rcx)
	subl	$1, %r15d
.L11:
	leaq	0(%rbp,%rdx), %rcx
	movl	(%rcx), %r9d
	cmpl	4(%rbx,%rdx), %edi
	jle	.L43
	testl	%r9d, %r9d
	jne	.L13
	leaq	-4(%rbp,%rax), %rdx
	movl	$-1, (%rcx)
	addl	$1, %r15d
	movl	(%rdx), %ecx
	cmpl	%esi, -4(%rbx,%rax)
	jle	.L44
.L14:
	testl	%ecx, %ecx
	jne	.L15
	movl	$-1, (%rdx)
	leaq	0(%rbp,%rax), %rdx
	addl	$1, %r15d
	movl	(%rdx), %ecx
	cmpl	%esi, 4(%rbx,%rax)
	jge	.L45
.L16:
	testl	%ecx, %ecx
	jne	.L17
	addl	$1, %r15d
	movl	$-1, (%rdx)
	addl	$1, %r12d
	testl	%r15d, %r15d
	jne	.L18
.L41:
	movl	%r12d, %edx
	leaq	.LC4(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L8
.L2:
	movl	$2000000000, 4(%rbx)
.L4:
	leaq	.LC1(%rip), %rdi
	call	puts@PLT
.L8:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L46
	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
.L42:
	.cfi_restore_state
	testl	%r15d, %r15d
	jle	.L8
.L19:
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L10:
	movl	(%rcx), %r8d
	testl	%r8d, %r8d
	jne	.L11
	movl	$-1, (%rcx)
	addl	$1, %r15d
	jmp	.L11
.L46:
	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	"%d"
.LC1:
	.string	"0"
.LC2:
	.string	"-1"
.LC3:
	.string	"%d%d"
.LC4:
	.string	"%d\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), %r8
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %rdi
	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	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r12d
	leal	2(%r12), %ebp
	movslq	%ebp, %rbp
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$-2000000000, (%rbx)
	movl	$0, (%rax)
	testl	%r12d, %r12d
	jle	.L2
	movq	%rax, %rbp
	leaq	4(%rbx), %r14
	leaq	4(%rax), %r13
	movl	$1, %r12d
	leaq	.LC0(%rip), %r8
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r14, %rsi
	movq	%r8, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %eax
	movl	$0, 0(%r13)
	addq	$4, %r14
	addq	$4, %r13
	leaq	.LC0(%rip), %r8
	cmpl	%r12d, %eax
	jge	.L3
	movslq	%r12d, %r12
	movl	$2000000000, (%rbx,%r12,4)
	movl	$0, 0(%rbp,%r12,4)
	testl	%eax, %eax
	jle	.L4
	movl	4(%rbx), %edx
	leal	2(%rax), %esi
	xorl	%r15d, %r15d
	movl	$2, %eax
	.p2align 4,,10
	.p2align 3
.L6:
	movl	%edx, %ecx
	movl	(%rbx,%rax,4), %edx
	cmpl	%ecx, %edx
	jge	.L5
	movl	$-1, -4(%rbp,%rax,4)
	addl	$1, %r15d
.L5:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L6
	testl	%r15d, %r15d
	je	.L4
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	movq	%r8, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$0, 12(%rsp)
	jle	.L19
	xorl	%r12d, %r12d
	leaq	20(%rsp), %r14
	leaq	16(%rsp), %r13
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L43:
	testl	%r9d, %r9d
	je	.L13
	movl	$0, (%rcx)
	subl	$1, %r15d
.L13:
	leaq	-4(%rbp,%rax), %rdx
	movl	(%rdx), %ecx
	cmpl	%esi, -4(%rbx,%rax)
	jg	.L14
.L44:
	testl	%ecx, %ecx
	je	.L15
	movl	$0, (%rdx)
	subl	$1, %r15d
.L15:
	leaq	0(%rbp,%rax), %rdx
	movl	(%rdx), %ecx
	cmpl	%esi, 4(%rbx,%rax)
	jl	.L16
.L45:
	testl	%ecx, %ecx
	je	.L17
	movl	$0, (%rdx)
	subl	$1, %r15d
.L17:
	addl	$1, %r12d
	testl	%r15d, %r15d
	je	.L41
.L18:
	cmpl	%r12d, 12(%rsp)
	jle	.L42
.L9:
	movq	%r14, %rdx
	movq	%r13, %rsi
	leaq	.LC3(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	16(%rsp), %rdx
	movslq	20(%rsp), %rax
	salq	$2, %rdx
	salq	$2, %rax
	leaq	(%rbx,%rdx), %rdi
	leaq	(%rbx,%rax), %rcx
	movl	(%rdi), %esi
	movl	(%rcx), %r9d
	movl	%r9d, (%rdi)
	movl	%esi, (%rcx)
	leaq	-4(%rdx), %rcx
	movl	(%rdi), %edi
	addq	%rbp, %rcx
	cmpl	%edi, -4(%rbx,%rdx)
	jg	.L10
	movl	(%rcx), %r9d
	testl	%r9d, %r9d
	je	.L11
	movl	$0, (%rcx)
	subl	$1, %r15d
.L11:
	leaq	0(%rbp,%rdx), %rcx
	movl	(%rcx), %r9d
	cmpl	4(%rbx,%rdx), %edi
	jle	.L43
	testl	%r9d, %r9d
	jne	.L13
	leaq	-4(%rbp,%rax), %rdx
	movl	$-1, (%rcx)
	addl	$1, %r15d
	movl	(%rdx), %ecx
	cmpl	%esi, -4(%rbx,%rax)
	jle	.L44
.L14:
	testl	%ecx, %ecx
	jne	.L15
	movl	$-1, (%rdx)
	leaq	0(%rbp,%rax), %rdx
	addl	$1, %r15d
	movl	(%rdx), %ecx
	cmpl	%esi, 4(%rbx,%rax)
	jge	.L45
.L16:
	testl	%ecx, %ecx
	jne	.L17
	addl	$1, %r15d
	movl	$-1, (%rdx)
	addl	$1, %r12d
	testl	%r15d, %r15d
	jne	.L18
.L41:
	movl	%r12d, %edx
	leaq	.LC4(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L8
.L2:
	movl	$2000000000, 4(%rbx)
.L4:
	leaq	.LC1(%rip), %rdi
	call	puts@PLT
.L8:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L46
	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
.L42:
	.cfi_restore_state
	testl	%r15d, %r15d
	jle	.L8
.L19:
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L10:
	movl	(%rcx), %r8d
	testl	%r8d, %r8d
	jne	.L11
	movl	$-1, (%rcx)
	addl	$1, %r15d
	jmp	.L11
.L46:
	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:

#include<stdio.h>
#include<stdlib.h>

#define OVER 2000000000

int main()
{
    int n;
    int *a;
    int *a_ng;
    int q;
    int x;
    int y;
    int ng = 0;
    int tmp;
    int i;
    
    scanf("%d", &n);
    
    a = (int *)malloc(sizeof(int) * (n + 2));
    a_ng = (int *)malloc(sizeof(int) * (n + 2));
    
    a[0] = OVER * (-1);
    a_ng[0] = 0;
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        a_ng[i] = 0;
    }
    a[i] = OVER;
    a_ng[i] = 0;
    
    for(i = 1; i <= n; i++)
    {
        if(a[i] > a[i + 1])
        {
            ng++;
            a_ng[i] = -1;
        }
    }
    
    if(ng == 0)
    {
        puts("0");
    }
    else
    {
        scanf("%d", &q);
        
        for(i = 0; i < q; i++)
        {
            scanf("%d%d", &x, &y);
            
            tmp = a[x];
            a[x] = a[y];
            a[y] = tmp;
            
            if(a[x - 1] <= a[x])
            {
                if(a_ng[x - 1] != 0)
                {
                    ng--;
                    a_ng[x - 1] = 0;
                }
            }
            else
            {
                if(a_ng[x - 1] == 0)
                {
                    ng++;
                    a_ng[x - 1] = -1;
                }
            }

            if(a[x] <= a [x + 1])
            {
                if(a_ng[x] != 0)
                {
                    ng--;
                    a_ng[x] = 0;
                }
            }
            else
            {
                if(a_ng[x] == 0)
                {
                    ng++;
                    a_ng[x] = -1;
                }
            }
            
            if(a[y - 1] <= a [y])
            {
                if(a_ng[y - 1] != 0)
                {
                    ng--;
                    a_ng[y - 1] = 0;
                }
            }
            else
            {
                if(a_ng[y - 1] == 0)
                {
                    ng++;
                    a_ng[y - 1] = -1;
                }
            }
            
            if(a[y] <= a [y + 1])
            {
                if(a_ng[y] != 0)
                {
                    ng--;
                    a_ng[y] = 0;
                }
            }
            else
            {
                if(a_ng[y] == 0)
                {
                    ng++;
                    a_ng[y] = -1;
                }
            }

            if(ng == 0)
            {
                printf("%d\n", i + 1);
                break;
            }
        }
        
        if(ng > 0)
        {
            puts("-1");
        }
    }
    
    return 0;
}

6
9 7 5 6 3 1
3
1 6
2 5
3 4

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>

#define OVER 2000000000

int main()
{
    int n;
    int *a;
    int *a_ng;
    int q;
    int x;
    int y;
    int ng = 0;
    int tmp;
    int i;
    
    scanf("%d", &n);
    
    a = (int *)malloc(sizeof(int) * (n + 2));
    a_ng = (int *)malloc(sizeof(int) * (n + 2));
    
    a[0] = OVER * (-1);
    a_ng[0] = 0;
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        a_ng[i] = 0;
    }
    a[i] = OVER;
    a_ng[i] = 0;
    
    for(i = 1; i <= n; i++)
    {
        if(a[i] > a[i + 1])
        {
            ng++;
            a_ng[i] = -1;
        }
    }
    
    if(ng == 0)
    {
        puts("0");
    }
    else
    {
        scanf("%d", &q);
        
        for(i = 0; i < q; i++)
        {
            scanf("%d%d", &x, &y);
            
            tmp = a[x];
            a[x] = a[y];
            a[y] = tmp;
            
            if(a[x - 1] <= a[x])
            {
                if(a_ng[x - 1] != 0)
                {
                    ng--;
                    a_ng[x - 1] = 0;
                }
            }
            else
            {
                if(a_ng[x - 1] == 0)
                {
                    ng++;
                    a_ng[x - 1] = -1;
                }
            }

            if(a[x] <= a [x + 1])
            {
                if(a_ng[x] != 0)
                {
                    ng--;
                    a_ng[x] = 0;
                }
            }
            else
            {
                if(a_ng[x] == 0)
                {
                    ng++;
                    a_ng[x] = -1;
                }
            }
            
            if(a[y - 1] <= a [y])
            {
                if(a_ng[y - 1] != 0)
                {
                    ng--;
                    a_ng[y - 1] = 0;
                }
            }
            else
            {
                if(a_ng[y - 1] == 0)
                {
                    ng++;
                    a_ng[y - 1] = -1;
                }
            }
            
            if(a[y] <= a [y + 1])
            {
                if(a_ng[y] != 0)
                {
                    ng--;
                    a_ng[y] = 0;
                }
            }
            else
            {
                if(a_ng[y] == 0)
                {
                    ng++;
                    a_ng[y] = -1;
                }
            }

            if(ng == 0)
            {
                printf("%d\n", i + 1);
                break;
            }
        }
        
        if(ng > 0)
        {
            puts("-1");
        }
    }
    
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"0"
.LC2:
	.string	"%d%d"
.LC3:
	.string	"%d\n"
.LC4:
	.string	"-1"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -36(%rbp)
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movl	$-2000000000, (%rax)
	movq	-16(%rbp), %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L2
.L3:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -32(%rbp)
.L2:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L3
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$2000000000, (%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L4
.L6:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L5
	addl	$1, -36(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L5:
	addl	$1, -32(%rbp)
.L4:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L6
	cmpl	$0, -36(%rbp)
	jne	.L7
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L8
.L7:
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L20:
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-44(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-28(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L10
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L11
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L11
.L10:
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L11
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L11:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L12
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L13
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L13
.L12:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L13
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L13:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L14
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L15
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L15
.L14:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L15
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L15:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L16
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L17
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L17
.L16:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L17
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L17:
	cmpl	$0, -36(%rbp)
	jne	.L18
	movl	-32(%rbp), %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L19
.L18:
	addl	$1, -32(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L20
.L19:
	cmpl	$0, -36(%rbp)
	jle	.L8
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L8:
	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	"0"
.LC2:
	.string	"%d%d"
.LC3:
	.string	"%d\n"
.LC4:
	.string	"-1"
	.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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -36(%rbp)
	leaq	-52(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-52(%rbp), %eax
	addl	$2, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	movl	$-2000000000, (%rax)
	movq	-16(%rbp), %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L2
.L3:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -32(%rbp)
.L2:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L3
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$2000000000, (%rax)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	movl	$1, -32(%rbp)
	jmp	.L4
.L6:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jle	.L5
	addl	$1, -36(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L5:
	addl	$1, -32(%rbp)
.L4:
	movl	-52(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L6
	cmpl	$0, -36(%rbp)
	jne	.L7
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L8
.L7:
	leaq	-48(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L20:
	leaq	-40(%rbp), %rdx
	leaq	-44(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-44(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-28(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L10
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L11
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L11
.L10:
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L11
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L11:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-44(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L12
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L13
	subl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L13
.L12:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L13
	addl	$1, -36(%rbp)
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L13:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L14
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L15
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L15
.L14:
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L15
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L15:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jg	.L16
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L17
	subl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	jmp	.L17
.L16:
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L17
	addl	$1, -36(%rbp)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	$-1, (%rax)
.L17:
	cmpl	$0, -36(%rbp)
	jne	.L18
	movl	-32(%rbp), %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L19
.L18:
	addl	$1, -32(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L20
.L19:
	cmpl	$0, -36(%rbp)
	jle	.L8
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L8:
	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:
