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

```c
a;b[1<<17];n;i;M=1e9+7;main(c){for(;~scanf("%d",&a);)!n?n=a:b[a]++;for(;++i<n;c=!((n%2^i%2?a-2:a)|n%2-*b)*c*-~!!a%M)a=b[i];printf("%d",c);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 524288
b:
	.zero	524288
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	M
	.data
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.long	1000000007
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L4:
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	movl	a(%rip), %eax
	movl	%eax, n(%rip)
	jmp	.L2
.L3:
	movl	a(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L2:
	leaq	a(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L4
	jmp	.L5
.L10:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, a(%rip)
	movl	n(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	je	.L6
	movl	a(%rip), %eax
	leal	-2(%rax), %edx
	jmp	.L7
.L6:
	movl	a(%rip), %edx
.L7:
	movl	n(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %ecx
	movl	b(%rip), %eax
	subl	%eax, %ecx
	movl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	testl	%eax, %eax
	je	.L8
	movl	$2, %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	imull	%edx, %eax
	movl	M(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	b(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	a(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L16
	movl	n(%rip), %edx
	movslq	a(%rip), %rax
	testl	%edx, %edx
	jne	.L3
	movl	%eax, n(%rip)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	addl	$1, 0(%r13,%rax,4)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L16:
	movl	i(%rip), %r13d
	movl	n(%rip), %r9d
	leal	1(%r13), %ebx
	movl	%ebx, i(%rip)
	cmpl	%r9d, %ebx
	jge	.L6
	movl	%r9d, %eax
	movl	M(%rip), %edi
	movslq	%ebx, %rcx
	leaq	b(%rip), %r10
	shrl	$31, %eax
	leal	(%r9,%rax), %r8d
	andl	$1, %r8d
	subl	%eax, %r8d
	movl	%r8d, %r11d
	subl	b(%rip), %r11d
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%ecx, %edx
	movl	(%r10,%rcx,4), %esi
	shrl	$31, %edx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%edx, %eax
	leal	-2(%rsi), %edx
	cmpl	%eax, %r8d
	movl	%edx, %eax
	cmove	%esi, %eax
	orl	%r11d, %eax
	sete	%al
	movzbl	%al, %eax
	imull	%r12d, %eax
	testl	%esi, %esi
	leal	(%rax,%rax), %edx
	cmovne	%edx, %eax
	addq	$1, %rcx
	cltd
	idivl	%edi
	movl	%edx, %r12d
	cmpl	%ecx, %r9d
	jg	.L9
	leal	-1(%rbx,%r9), %eax
	movl	%esi, a(%rip)
	subl	%r13d, %eax
	movl	%eax, i(%rip)
.L6:
	movl	%r12d, %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	M
	.data
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.long	1000000007
	.globl	i
	.bss
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 524288
b:
	.zero	524288
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	b(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	a(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L16
	movl	n(%rip), %edx
	movslq	a(%rip), %rax
	testl	%edx, %edx
	jne	.L3
	movl	%eax, n(%rip)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	addl	$1, 0(%r13,%rax,4)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L16:
	movl	i(%rip), %r13d
	movl	n(%rip), %r9d
	leal	1(%r13), %ebx
	movl	%ebx, i(%rip)
	cmpl	%r9d, %ebx
	jge	.L6
	movl	%r9d, %eax
	movl	M(%rip), %edi
	movslq	%ebx, %rcx
	leaq	b(%rip), %r10
	shrl	$31, %eax
	leal	(%r9,%rax), %r8d
	andl	$1, %r8d
	subl	%eax, %r8d
	movl	%r8d, %r11d
	subl	b(%rip), %r11d
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%ecx, %edx
	movl	(%r10,%rcx,4), %esi
	shrl	$31, %edx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%edx, %eax
	leal	-2(%rsi), %edx
	cmpl	%eax, %r8d
	movl	%edx, %eax
	cmove	%esi, %eax
	orl	%r11d, %eax
	sete	%al
	movzbl	%al, %eax
	imull	%r12d, %eax
	testl	%esi, %esi
	leal	(%rax,%rax), %edx
	cmovne	%edx, %eax
	addq	$1, %rcx
	cltd
	idivl	%edi
	movl	%edx, %r12d
	cmpl	%ecx, %r9d
	jg	.L9
	leal	-1(%rbx,%r9), %eax
	movl	%esi, a(%rip)
	subl	%r13d, %eax
	movl	%eax, i(%rip)
.L6:
	movl	%r12d, %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	M
	.data
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.long	1000000007
	.globl	i
	.bss
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 524288
b:
	.zero	524288
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.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:

a;b[1<<17];n;i;M=1e9+7;main(c){for(;~scanf("%d",&a);)!n?n=a:b[a]++;for(;++i<n;c=!((n%2^i%2?a-2:a)|n%2-*b)*c*-~!!a%M)a=b[i];printf("%d",c);}
5
2 4 4 0 2

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

```c
a;b[1<<17];n;i;M=1e9+7;main(c){for(;~scanf("%d",&a);)!n?n=a:b[a]++;for(;++i<n;c=!((n%2^i%2?a-2:a)|n%2-*b)*c*-~!!a%M)a=b[i];printf("%d",c);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 524288
b:
	.zero	524288
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	M
	.data
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.long	1000000007
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L4:
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	movl	a(%rip), %eax
	movl	%eax, n(%rip)
	jmp	.L2
.L3:
	movl	a(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L2:
	leaq	a(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L4
	jmp	.L5
.L10:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, a(%rip)
	movl	n(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	je	.L6
	movl	a(%rip), %eax
	leal	-2(%rax), %edx
	jmp	.L7
.L6:
	movl	a(%rip), %edx
.L7:
	movl	n(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %ecx
	movl	b(%rip), %eax
	subl	%eax, %ecx
	movl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	testl	%eax, %eax
	je	.L8
	movl	$2, %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	imull	%edx, %eax
	movl	M(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 32
	.type	b, @object
	.size	b, 524288
b:
	.zero	524288
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	M
	.data
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.long	1000000007
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	jmp	.L2
.L4:
	movl	n(%rip), %eax
	testl	%eax, %eax
	jne	.L3
	movl	a(%rip), %eax
	movl	%eax, n(%rip)
	jmp	.L2
.L3:
	movl	a(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	b(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L2:
	leaq	a(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L4
	jmp	.L5
.L10:
	movl	i(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	b(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, a(%rip)
	movl	n(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %ecx
	movl	i(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	cmpl	%eax, %ecx
	je	.L6
	movl	a(%rip), %eax
	leal	-2(%rax), %edx
	jmp	.L7
.L6:
	movl	a(%rip), %edx
.L7:
	movl	n(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %ecx
	movl	b(%rip), %eax
	subl	%eax, %ecx
	movl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	imull	-4(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	testl	%eax, %eax
	je	.L8
	movl	$2, %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	imull	%edx, %eax
	movl	M(%rip), %ecx
	cltd
	idivl	%ecx
	movl	%edx, -4(%rbp)
.L5:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L10
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
