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>
int N,a[300000],d=0;

#define gc() getchar()
int scan(int * N)
{
	int c,n=0;
	for(c=gc();'0'<=c&&c<='9';c=gc()){
		n=(n*10)+(c&0xf);
	}
	if(N!=NULL) *N=n;
	return n;
}

int check(int i)
{
    int r=0;
    if(0<i) r+=a[i-1]>a[i];
    if(i<N-1) r+=a[i]>a[i+1];
    return r;
}

void update(int x, int y)
{
    int tmp=a[x];
    d-=check(x);
    a[x]=a[y];
    d+=check(x);
    d-=check(y);
    a[y]=tmp;
    d+=check(y);
}

int main()
{
  int i,Q;
  scan(&N);
  scan(&a[0]);
  for(i=1;i<N;i++) d+=a[i-1]>scan(&a[i]);
  scan(&Q);
  for(i=0;i<Q;i++){
      if(d==0)break;
      update(scan(NULL)-1,scan(NULL)-1);
  }
  printf("%d\n",d?-1:i);
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1200000
a:
	.zero	1200000
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.text
	.globl	scan
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	$0, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
.L2:
	cmpl	$47, -8(%rbp)
	jle	.L3
	cmpl	$57, -8(%rbp)
	jle	.L4
.L3:
	cmpq	$0, -24(%rbp)
	je	.L5
	movq	-24(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
.L5:
	movl	-4(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -4(%rbp)
	cmpl	$0, -20(%rbp)
	jle	.L8
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L8:
	movl	N(%rip), %eax
	subl	$1, %eax
	cmpl	%eax, -20(%rbp)
	jge	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L9:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.globl	update
	.type	update, @function
update:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$24, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	update, .-update
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	N(%rip), %rax
	movq	%rax, %rdi
	call	scan
	leaq	a(%rip), %rax
	movq	%rax, %rdi
	call	scan
	movl	$1, -28(%rbp)
	jmp	.L13
.L14:
	movl	-28(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ebx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	scan
	cmpl	%eax, %ebx
	setg	%al
	movzbl	%al, %edx
	movl	d(%rip), %eax
	addl	%edx, %eax
	movl	%eax, d(%rip)
	addl	$1, -28(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L14
	leaq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	scan
	movl	$0, -28(%rbp)
	jmp	.L15
.L18:
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L23
	movl	$0, %edi
	call	scan
	leal	-1(%rax), %ebx
	movl	$0, %edi
	call	scan
	subl	$1, %eax
	movl	%ebx, %esi
	movl	%eax, %edi
	call	update
	addl	$1, -28(%rbp)
.L15:
	movl	-32(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L18
	jmp	.L17
.L23:
	nop
.L17:
	movl	d(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	-28(%rbp), %eax
	jmp	.L20
.L19:
	movl	$-1, %eax
.L20:
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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
	.p2align 4
	.globl	scan
	.type	scan, @function
scan:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%r12d, %r12d
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 32
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movq	stdin(%rip), %rdi
	leal	(%r12,%r12,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L3
.L2:
	testq	%rbx, %rbx
	je	.L1
	movl	%r12d, (%rbx)
.L1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	movl	%r12d, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	scan, .-scan
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testl	%edi, %edi
	jle	.L13
	leal	-1(%rdi), %eax
	leaq	a(%rip), %rdx
	movslq	%edi, %rcx
	xorl	%r8d, %r8d
	cltq
	movl	(%rdx,%rcx,4), %esi
	cmpl	%esi, (%rdx,%rax,4)
	setg	%r8b
.L13:
	movl	N(%rip), %eax
	subl	$1, %eax
	cmpl	%edi, %eax
	jle	.L12
	movslq	%edi, %rdx
	addl	$1, %edi
	leaq	a(%rip), %rax
	movslq	%edi, %rdi
	movl	(%rax,%rdi,4), %ecx
	cmpl	%ecx, (%rax,%rdx,4)
	setg	%al
	movzbl	%al, %eax
	addl	%eax, %r8d
.L12:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.p2align 4
	.globl	update
	.type	update, @function
update:
.LFB25:
	.cfi_startproc
	endbr64
	leaq	a(%rip), %rax
	movslq	%edi, %r11
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	(%rax,%r11,4), %r8d
	testl	%edi, %edi
	jle	.L17
	leal	-1(%rdi), %ebx
	movl	N(%rip), %ecx
	xorl	%ebp, %ebp
	movslq	%esi, %r9
	movslq	%ebx, %rbx
	movl	d(%rip), %r10d
	movl	(%rax,%r9,4), %esi
	cmpl	(%rax,%rbx,4), %r8d
	setl	%bpl
	subl	$1, %ecx
	cmpl	%ecx, %edi
	jl	.L33
	movl	%esi, (%rax,%r11,4)
	cmpl	%esi, (%rax,%rbx,4)
	setg	%sil
	subl	%ebp, %r10d
	movzbl	%sil, %esi
	addl	%esi, %r10d
.L28:
	testl	%edx, %edx
	jle	.L19
.L34:
	leal	-1(%rdx), %esi
	xorl	%edi, %edi
	movl	(%rax,%r9,4), %ebx
	movslq	%esi, %rsi
	cmpl	%ebx, (%rax,%rsi,4)
	setg	%dil
	cmpl	%ecx, %edx
	jge	.L20
	addl	$1, %edx
	xorl	%ecx, %ecx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	cmpl	%ebx, (%rax,%r9,4)
	movl	%r8d, (%rax,%r9,4)
	setg	%cl
	addl	%edi, %ecx
	subl	%ecx, %r10d
	xorl	%ecx, %ecx
	cmpl	(%rax,%rsi,4), %r8d
	setl	%cl
.L21:
	cmpl	(%rax,%rdx,4), %r8d
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	setg	%al
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	movzbl	%al, %eax
	addl	%ecx, %eax
	addl	%eax, %r10d
	movl	%r10d, d(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L33:
	.cfi_restore_state
	addl	$1, %edi
	xorl	%r12d, %r12d
	movslq	%edi, %rdi
	cmpl	(%rax,%rdi,4), %r8d
	movl	%esi, (%rax,%r11,4)
	setg	%r12b
	xorl	%r11d, %r11d
	addl	%r12d, %ebp
	subl	%ebp, %r10d
	cmpl	%esi, (%rax,%rbx,4)
	setg	%r11b
.L24:
	cmpl	%esi, (%rax,%rdi,4)
	setl	%sil
	movzbl	%sil, %esi
	addl	%r11d, %esi
	addl	%esi, %r10d
	testl	%edx, %edx
	jg	.L34
.L19:
	cmpl	%ecx, %edx
	jge	.L35
	addl	$1, %edx
	movl	(%rax,%r9,4), %ebx
	xorl	%ecx, %ecx
	movslq	%edx, %rdx
	cmpl	%ebx, (%rax,%rdx,4)
	movl	%r8d, (%rax,%r9,4)
	setl	%cl
	subl	%ecx, %r10d
	xorl	%ecx, %ecx
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L17:
	movl	N(%rip), %ebx
	movslq	%esi, %r9
	movl	d(%rip), %r10d
	movl	(%rax,%r9,4), %esi
	leal	-1(%rbx), %ecx
	cmpl	%ecx, %edi
	jge	.L36
	addl	$1, %edi
	xorl	%ebx, %ebx
	movslq	%edi, %rdi
	cmpl	(%rax,%rdi,4), %r8d
	movl	%esi, (%rax,%r11,4)
	setg	%bl
	xorl	%r11d, %r11d
	subl	%ebx, %r10d
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%r8d, (%rax,%r9,4)
	cmpl	(%rax,%rsi,4), %r8d
	setl	%al
	subl	%edi, %r10d
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	movzbl	%al, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	addl	%eax, %r10d
	movl	%r10d, d(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L36:
	.cfi_restore_state
	movl	%esi, (%rax,%r11,4)
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L35:
	movl	%r8d, (%rax,%r9,4)
	popq	%rbx
	.cfi_def_cfa_offset 24
	movl	%r10d, d(%rip)
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE25:
	.size	update, .-update
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	N(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	leaq	a(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-4(%rbp), %r13
	movl	$1, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	scan
	movq	%rbp, %rdi
	call	scan
	cmpl	$1, N(%rip)
	jle	.L43
	.p2align 4,,10
	.p2align 3
.L38:
	movq	stdin(%rip), %rdi
	movl	0(%r13,%rbx,4), %r12d
	xorl	%r14d, %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L41
	.p2align 4,,10
	.p2align 3
.L42:
	movq	stdin(%rip), %rdi
	leal	(%r14,%r14,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L42
.L41:
	xorl	%eax, %eax
	cmpl	%r14d, %r12d
	movl	%r14d, 0(%rbp,%rbx,4)
	setg	%al
	addq	$1, %rbx
	addl	%eax, d(%rip)
	cmpl	%ebx, N(%rip)
	jg	.L38
.L43:
	leaq	4(%rsp), %rdi
	xorl	%r12d, %r12d
	call	scan
	movl	4(%rsp), %edx
	movl	d(%rip), %eax
	testl	%edx, %edx
	jle	.L40
	.p2align 4,,10
	.p2align 3
.L53:
	testl	%eax, %eax
	je	.L44
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L65
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L46:
	movq	stdin(%rip), %rdi
	leal	(%rbx,%rbx,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %ebx
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L46
	leal	-1(%rbx), %r13d
.L45:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L47
	xorl	%r14d, %r14d
	.p2align 4,,10
	.p2align 3
.L48:
	movq	stdin(%rip), %rdi
	leal	(%r14,%r14,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L48
	leal	-1(%r14), %edx
	movslq	%r13d, %rsi
	movl	d(%rip), %eax
	movl	N(%rip), %r8d
	movslq	%edx, %r9
	movl	0(%rbp,%rsi,4), %edi
	movl	0(%rbp,%r9,4), %ecx
	testl	%edx, %edx
	jle	.L49
	leal	-2(%r14), %edx
	xorl	%r10d, %r10d
	movslq	%edx, %rdx
	cmpl	0(%rbp,%rdx,4), %ecx
	setl	%r10b
	cmpl	%r8d, %r14d
	jge	.L50
	movslq	%r14d, %r14
	xorl	%r11d, %r11d
	cmpl	0(%rbp,%r14,4), %ecx
	movl	%edi, 0(%rbp,%r9,4)
	setg	%r11b
	xorl	%r9d, %r9d
	addl	%r11d, %r10d
	subl	%r10d, %eax
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%r9b
.L59:
	xorl	%edx, %edx
	cmpl	%edi, 0(%rbp,%r14,4)
	setl	%dl
	addl	%r9d, %edx
	addl	%edx, %eax
.L55:
	testl	%r13d, %r13d
	jle	.L51
	leal	-2(%rbx), %edx
	xorl	%r9d, %r9d
	movl	0(%rbp,%rsi,4), %edi
	movslq	%edx, %rdx
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%r9b
	cmpl	%r8d, %ebx
	jge	.L52
	movslq	%ebx, %rbx
	cmpl	0(%rbp,%rbx,4), %edi
	movl	%ecx, 0(%rbp,%rsi,4)
	setg	%dil
	xorl	%esi, %esi
	movzbl	%dil, %edi
	addl	%r9d, %edi
	subl	%edi, %eax
	cmpl	%ecx, 0(%rbp,%rdx,4)
	setg	%sil
.L56:
	xorl	%edx, %edx
	cmpl	%ecx, 0(%rbp,%rbx,4)
	setl	%dl
	addl	%esi, %edx
	addl	%edx, %eax
.L54:
	movl	%eax, d(%rip)
	addl	$1, %r12d
	cmpl	%r12d, 4(%rsp)
	jg	.L53
.L40:
	cmpl	$0, d(%rip)
	movl	$-1, %eax
	cmovne	%eax, %r12d
.L44:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L47:
	.cfi_restore_state
	movl	-4+a(%rip), %ecx
	movl	d(%rip), %eax
	xorl	%r14d, %r14d
	movslq	%r13d, %rsi
	movl	N(%rip), %r8d
	movq	$-1, %r9
.L49:
	movl	0(%rbp,%rsi,4), %edi
	cmpl	%r14d, %r8d
	jle	.L83
	movslq	%r14d, %r14
	xorl	%edx, %edx
	cmpl	%ecx, 0(%rbp,%r14,4)
	movl	%edi, 0(%rbp,%r9,4)
	setl	%dl
	xorl	%r9d, %r9d
	subl	%edx, %eax
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L51:
	cmpl	%r8d, %ebx
	jge	.L84
	movslq	%ebx, %rbx
	movl	0(%rbp,%rsi,4), %edi
	xorl	%edx, %edx
	cmpl	%edi, 0(%rbp,%rbx,4)
	movl	%ecx, 0(%rbp,%rsi,4)
	setl	%dl
	xorl	%esi, %esi
	subl	%edx, %eax
	jmp	.L56
	.p2align 4,,10
	.p2align 3
.L50:
	subl	%r10d, %eax
	movl	%edi, 0(%rbp,%r9,4)
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%dl
	movzbl	%dl, %edx
	addl	%edx, %eax
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L52:
	movl	%ecx, 0(%rbp,%rsi,4)
	cmpl	%ecx, 0(%rbp,%rdx,4)
	setg	%dl
	subl	%r9d, %eax
	movzbl	%dl, %edx
	addl	%edx, %eax
	jmp	.L54
	.p2align 4,,10
	.p2align 3
.L84:
	movl	%ecx, 0(%rbp,%rsi,4)
	jmp	.L54
	.p2align 4,,10
	.p2align 3
.L83:
	movl	%edi, 0(%rbp,%r9,4)
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L65:
	movl	$-1, %r13d
	xorl	%ebx, %ebx
	jmp	.L45
.L82:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1200000
a:
	.zero	1200000
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.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
	.p2align 4
	.globl	scan
	.type	scan, @function
scan:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%r12d, %r12d
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 32
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movq	stdin(%rip), %rdi
	leal	(%r12,%r12,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r12d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L3
.L2:
	testq	%rbx, %rbx
	je	.L1
	movl	%r12d, (%rbx)
.L1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	movl	%r12d, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	scan, .-scan
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testl	%edi, %edi
	jle	.L13
	leal	-1(%rdi), %eax
	leaq	a(%rip), %rdx
	movslq	%edi, %rcx
	xorl	%r8d, %r8d
	cltq
	movl	(%rdx,%rcx,4), %esi
	cmpl	%esi, (%rdx,%rax,4)
	setg	%r8b
.L13:
	movl	N(%rip), %eax
	subl	$1, %eax
	cmpl	%edi, %eax
	jle	.L12
	movslq	%edi, %rdx
	addl	$1, %edi
	leaq	a(%rip), %rax
	movslq	%edi, %rdi
	movl	(%rax,%rdi,4), %ecx
	cmpl	%ecx, (%rax,%rdx,4)
	setg	%al
	movzbl	%al, %eax
	addl	%eax, %r8d
.L12:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.p2align 4
	.globl	update
	.type	update, @function
update:
.LFB25:
	.cfi_startproc
	endbr64
	leaq	a(%rip), %rax
	movslq	%edi, %r11
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	(%rax,%r11,4), %r8d
	testl	%edi, %edi
	jle	.L17
	leal	-1(%rdi), %ebx
	movl	N(%rip), %ecx
	xorl	%ebp, %ebp
	movslq	%esi, %r9
	movslq	%ebx, %rbx
	movl	d(%rip), %r10d
	movl	(%rax,%r9,4), %esi
	cmpl	(%rax,%rbx,4), %r8d
	setl	%bpl
	subl	$1, %ecx
	cmpl	%ecx, %edi
	jl	.L33
	movl	%esi, (%rax,%r11,4)
	cmpl	%esi, (%rax,%rbx,4)
	setg	%sil
	subl	%ebp, %r10d
	movzbl	%sil, %esi
	addl	%esi, %r10d
.L28:
	testl	%edx, %edx
	jle	.L19
.L34:
	leal	-1(%rdx), %esi
	xorl	%edi, %edi
	movl	(%rax,%r9,4), %ebx
	movslq	%esi, %rsi
	cmpl	%ebx, (%rax,%rsi,4)
	setg	%dil
	cmpl	%ecx, %edx
	jge	.L20
	addl	$1, %edx
	xorl	%ecx, %ecx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	cmpl	%ebx, (%rax,%r9,4)
	movl	%r8d, (%rax,%r9,4)
	setg	%cl
	addl	%edi, %ecx
	subl	%ecx, %r10d
	xorl	%ecx, %ecx
	cmpl	(%rax,%rsi,4), %r8d
	setl	%cl
.L21:
	cmpl	(%rax,%rdx,4), %r8d
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	setg	%al
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	movzbl	%al, %eax
	addl	%ecx, %eax
	addl	%eax, %r10d
	movl	%r10d, d(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L33:
	.cfi_restore_state
	addl	$1, %edi
	xorl	%r12d, %r12d
	movslq	%edi, %rdi
	cmpl	(%rax,%rdi,4), %r8d
	movl	%esi, (%rax,%r11,4)
	setg	%r12b
	xorl	%r11d, %r11d
	addl	%r12d, %ebp
	subl	%ebp, %r10d
	cmpl	%esi, (%rax,%rbx,4)
	setg	%r11b
.L24:
	cmpl	%esi, (%rax,%rdi,4)
	setl	%sil
	movzbl	%sil, %esi
	addl	%r11d, %esi
	addl	%esi, %r10d
	testl	%edx, %edx
	jg	.L34
.L19:
	cmpl	%ecx, %edx
	jge	.L35
	addl	$1, %edx
	movl	(%rax,%r9,4), %ebx
	xorl	%ecx, %ecx
	movslq	%edx, %rdx
	cmpl	%ebx, (%rax,%rdx,4)
	movl	%r8d, (%rax,%r9,4)
	setl	%cl
	subl	%ecx, %r10d
	xorl	%ecx, %ecx
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L17:
	movl	N(%rip), %ebx
	movslq	%esi, %r9
	movl	d(%rip), %r10d
	movl	(%rax,%r9,4), %esi
	leal	-1(%rbx), %ecx
	cmpl	%ecx, %edi
	jge	.L36
	addl	$1, %edi
	xorl	%ebx, %ebx
	movslq	%edi, %rdi
	cmpl	(%rax,%rdi,4), %r8d
	movl	%esi, (%rax,%r11,4)
	setg	%bl
	xorl	%r11d, %r11d
	subl	%ebx, %r10d
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%r8d, (%rax,%r9,4)
	cmpl	(%rax,%rsi,4), %r8d
	setl	%al
	subl	%edi, %r10d
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	movzbl	%al, %eax
	popq	%r12
	.cfi_def_cfa_offset 8
	addl	%eax, %r10d
	movl	%r10d, d(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L36:
	.cfi_restore_state
	movl	%esi, (%rax,%r11,4)
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L35:
	movl	%r8d, (%rax,%r9,4)
	popq	%rbx
	.cfi_def_cfa_offset 24
	movl	%r10d, d(%rip)
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE25:
	.size	update, .-update
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	N(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	leaq	a(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-4(%rbp), %r13
	movl	$1, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	scan
	movq	%rbp, %rdi
	call	scan
	cmpl	$1, N(%rip)
	jle	.L43
	.p2align 4,,10
	.p2align 3
.L38:
	movq	stdin(%rip), %rdi
	movl	0(%r13,%rbx,4), %r12d
	xorl	%r14d, %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L41
	.p2align 4,,10
	.p2align 3
.L42:
	movq	stdin(%rip), %rdi
	leal	(%r14,%r14,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L42
.L41:
	xorl	%eax, %eax
	cmpl	%r14d, %r12d
	movl	%r14d, 0(%rbp,%rbx,4)
	setg	%al
	addq	$1, %rbx
	addl	%eax, d(%rip)
	cmpl	%ebx, N(%rip)
	jg	.L38
.L43:
	leaq	4(%rsp), %rdi
	xorl	%r12d, %r12d
	call	scan
	movl	4(%rsp), %edx
	movl	d(%rip), %eax
	testl	%edx, %edx
	jle	.L40
	.p2align 4,,10
	.p2align 3
.L53:
	testl	%eax, %eax
	je	.L44
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L65
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L46:
	movq	stdin(%rip), %rdi
	leal	(%rbx,%rbx,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %ebx
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L46
	leal	-1(%rbx), %r13d
.L45:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	ja	.L47
	xorl	%r14d, %r14d
	.p2align 4,,10
	.p2align 3
.L48:
	movq	stdin(%rip), %rdi
	leal	(%r14,%r14,4), %edx
	andl	$15, %eax
	leal	(%rax,%rdx,2), %r14d
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpl	$9, %edx
	jbe	.L48
	leal	-1(%r14), %edx
	movslq	%r13d, %rsi
	movl	d(%rip), %eax
	movl	N(%rip), %r8d
	movslq	%edx, %r9
	movl	0(%rbp,%rsi,4), %edi
	movl	0(%rbp,%r9,4), %ecx
	testl	%edx, %edx
	jle	.L49
	leal	-2(%r14), %edx
	xorl	%r10d, %r10d
	movslq	%edx, %rdx
	cmpl	0(%rbp,%rdx,4), %ecx
	setl	%r10b
	cmpl	%r8d, %r14d
	jge	.L50
	movslq	%r14d, %r14
	xorl	%r11d, %r11d
	cmpl	0(%rbp,%r14,4), %ecx
	movl	%edi, 0(%rbp,%r9,4)
	setg	%r11b
	xorl	%r9d, %r9d
	addl	%r11d, %r10d
	subl	%r10d, %eax
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%r9b
.L59:
	xorl	%edx, %edx
	cmpl	%edi, 0(%rbp,%r14,4)
	setl	%dl
	addl	%r9d, %edx
	addl	%edx, %eax
.L55:
	testl	%r13d, %r13d
	jle	.L51
	leal	-2(%rbx), %edx
	xorl	%r9d, %r9d
	movl	0(%rbp,%rsi,4), %edi
	movslq	%edx, %rdx
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%r9b
	cmpl	%r8d, %ebx
	jge	.L52
	movslq	%ebx, %rbx
	cmpl	0(%rbp,%rbx,4), %edi
	movl	%ecx, 0(%rbp,%rsi,4)
	setg	%dil
	xorl	%esi, %esi
	movzbl	%dil, %edi
	addl	%r9d, %edi
	subl	%edi, %eax
	cmpl	%ecx, 0(%rbp,%rdx,4)
	setg	%sil
.L56:
	xorl	%edx, %edx
	cmpl	%ecx, 0(%rbp,%rbx,4)
	setl	%dl
	addl	%esi, %edx
	addl	%edx, %eax
.L54:
	movl	%eax, d(%rip)
	addl	$1, %r12d
	cmpl	%r12d, 4(%rsp)
	jg	.L53
.L40:
	cmpl	$0, d(%rip)
	movl	$-1, %eax
	cmovne	%eax, %r12d
.L44:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L47:
	.cfi_restore_state
	movl	-4+a(%rip), %ecx
	movl	d(%rip), %eax
	xorl	%r14d, %r14d
	movslq	%r13d, %rsi
	movl	N(%rip), %r8d
	movq	$-1, %r9
.L49:
	movl	0(%rbp,%rsi,4), %edi
	cmpl	%r14d, %r8d
	jle	.L83
	movslq	%r14d, %r14
	xorl	%edx, %edx
	cmpl	%ecx, 0(%rbp,%r14,4)
	movl	%edi, 0(%rbp,%r9,4)
	setl	%dl
	xorl	%r9d, %r9d
	subl	%edx, %eax
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L51:
	cmpl	%r8d, %ebx
	jge	.L84
	movslq	%ebx, %rbx
	movl	0(%rbp,%rsi,4), %edi
	xorl	%edx, %edx
	cmpl	%edi, 0(%rbp,%rbx,4)
	movl	%ecx, 0(%rbp,%rsi,4)
	setl	%dl
	xorl	%esi, %esi
	subl	%edx, %eax
	jmp	.L56
	.p2align 4,,10
	.p2align 3
.L50:
	subl	%r10d, %eax
	movl	%edi, 0(%rbp,%r9,4)
	cmpl	%edi, 0(%rbp,%rdx,4)
	setg	%dl
	movzbl	%dl, %edx
	addl	%edx, %eax
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L52:
	movl	%ecx, 0(%rbp,%rsi,4)
	cmpl	%ecx, 0(%rbp,%rdx,4)
	setg	%dl
	subl	%r9d, %eax
	movzbl	%dl, %edx
	addl	%edx, %eax
	jmp	.L54
	.p2align 4,,10
	.p2align 3
.L84:
	movl	%ecx, 0(%rbp,%rsi,4)
	jmp	.L54
	.p2align 4,,10
	.p2align 3
.L83:
	movl	%edi, 0(%rbp,%r9,4)
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L65:
	movl	$-1, %r13d
	xorl	%ebx, %ebx
	jmp	.L45
.L82:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1200000
a:
	.zero	1200000
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.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>
int N,a[300000],d=0;

#define gc() getchar()
int scan(int * N)
{
	int c,n=0;
	for(c=gc();'0'<=c&&c<='9';c=gc()){
		n=(n*10)+(c&0xf);
	}
	if(N!=NULL) *N=n;
	return n;
}

int check(int i)
{
    int r=0;
    if(0<i) r+=a[i-1]>a[i];
    if(i<N-1) r+=a[i]>a[i+1];
    return r;
}

void update(int x, int y)
{
    int tmp=a[x];
    d-=check(x);
    a[x]=a[y];
    d+=check(x);
    d-=check(y);
    a[y]=tmp;
    d+=check(y);
}

int main()
{
  int i,Q;
  scan(&N);
  scan(&a[0]);
  for(i=1;i<N;i++) d+=a[i-1]>scan(&a[i]);
  scan(&Q);
  for(i=0;i<Q;i++){
      if(d==0)break;
      update(scan(NULL)-1,scan(NULL)-1);
  }
  printf("%d\n",d?-1:i);
}


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>
int N,a[300000],d=0;

#define gc() getchar()
int scan(int * N)
{
	int c,n=0;
	for(c=gc();'0'<=c&&c<='9';c=gc()){
		n=(n*10)+(c&0xf);
	}
	if(N!=NULL) *N=n;
	return n;
}

int check(int i)
{
    int r=0;
    if(0<i) r+=a[i-1]>a[i];
    if(i<N-1) r+=a[i]>a[i+1];
    return r;
}

void update(int x, int y)
{
    int tmp=a[x];
    d-=check(x);
    a[x]=a[y];
    d+=check(x);
    d-=check(y);
    a[y]=tmp;
    d+=check(y);
}

int main()
{
  int i,Q;
  scan(&N);
  scan(&a[0]);
  for(i=1;i<N;i++) d+=a[i-1]>scan(&a[i]);
  scan(&Q);
  for(i=0;i<Q;i++){
      if(d==0)break;
      update(scan(NULL)-1,scan(NULL)-1);
  }
  printf("%d\n",d?-1:i);
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1200000
a:
	.zero	1200000
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.text
	.globl	scan
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	$0, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
.L2:
	cmpl	$47, -8(%rbp)
	jle	.L3
	cmpl	$57, -8(%rbp)
	jle	.L4
.L3:
	cmpq	$0, -24(%rbp)
	je	.L5
	movq	-24(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
.L5:
	movl	-4(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -4(%rbp)
	cmpl	$0, -20(%rbp)
	jle	.L8
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L8:
	movl	N(%rip), %eax
	subl	$1, %eax
	cmpl	%eax, -20(%rbp)
	jge	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L9:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.globl	update
	.type	update, @function
update:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$24, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	update, .-update
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	N(%rip), %rax
	movq	%rax, %rdi
	call	scan
	leaq	a(%rip), %rax
	movq	%rax, %rdi
	call	scan
	movl	$1, -28(%rbp)
	jmp	.L13
.L14:
	movl	-28(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ebx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	scan
	cmpl	%eax, %ebx
	setg	%al
	movzbl	%al, %edx
	movl	d(%rip), %eax
	addl	%edx, %eax
	movl	%eax, d(%rip)
	addl	$1, -28(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L14
	leaq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	scan
	movl	$0, -28(%rbp)
	jmp	.L15
.L18:
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L23
	movl	$0, %edi
	call	scan
	leal	-1(%rax), %ebx
	movl	$0, %edi
	call	scan
	subl	$1, %eax
	movl	%ebx, %esi
	movl	%eax, %edi
	call	update
	addl	$1, -28(%rbp)
.L15:
	movl	-32(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L18
	jmp	.L17
.L23:
	nop
.L17:
	movl	d(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	-28(%rbp), %eax
	jmp	.L20
.L19:
	movl	$-1, %eax
.L20:
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 1200000
a:
	.zero	1200000
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.text
	.globl	scan
	.type	scan, @function
scan:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	$0, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
	jmp	.L2
.L4:
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	call	getchar@PLT
	movl	%eax, -8(%rbp)
.L2:
	cmpl	$47, -8(%rbp)
	jle	.L3
	cmpl	$57, -8(%rbp)
	jle	.L4
.L3:
	cmpq	$0, -24(%rbp)
	je	.L5
	movq	-24(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
.L5:
	movl	-4(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	scan, .-scan
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	$0, -4(%rbp)
	cmpl	$0, -20(%rbp)
	jle	.L8
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L8:
	movl	N(%rip), %eax
	subl	$1, %eax
	cmpl	%eax, -20(%rbp)
	jge	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %eax
	addl	%eax, -4(%rbp)
.L9:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.globl	update
	.type	update, @function
update:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$24, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-20(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	%eax, %edx
	movl	d(%rip), %eax
	subl	%edx, %eax
	movl	%eax, d(%rip)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-24(%rbp), %eax
	movl	%eax, %edi
	call	check
	movl	d(%rip), %edx
	addl	%edx, %eax
	movl	%eax, d(%rip)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	update, .-update
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	N(%rip), %rax
	movq	%rax, %rdi
	call	scan
	leaq	a(%rip), %rax
	movq	%rax, %rdi
	call	scan
	movl	$1, -28(%rbp)
	jmp	.L13
.L14:
	movl	-28(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ebx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	scan
	cmpl	%eax, %ebx
	setg	%al
	movzbl	%al, %edx
	movl	d(%rip), %eax
	addl	%edx, %eax
	movl	%eax, d(%rip)
	addl	$1, -28(%rbp)
.L13:
	movl	N(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L14
	leaq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	scan
	movl	$0, -28(%rbp)
	jmp	.L15
.L18:
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L23
	movl	$0, %edi
	call	scan
	leal	-1(%rax), %ebx
	movl	$0, %edi
	call	scan
	subl	$1, %eax
	movl	%ebx, %esi
	movl	%eax, %edi
	call	update
	addl	$1, -28(%rbp)
.L15:
	movl	-32(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L18
	jmp	.L17
.L23:
	nop
.L17:
	movl	d(%rip), %eax
	testl	%eax, %eax
	jne	.L19
	movl	-28(%rbp), %eax
	jmp	.L20
.L19:
	movl	$-1, %eax
.L20:
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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:
