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

```c
a[1<<17],m;main(n,v,i){for(;scanf("%d",&n)*n;){for(i=0;i++<n;a[m]++)scanf("%d",&v),a[m+=v!=m%2]|i%2||(a[v=m>1?m-2:m]+=a[m-1],a[m-1]=0,m=v);for(;m;a[m--]=0)n-=m%2*a[m];*a=!printf("%d\n",n);}}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 524288
a:
	.zero	524288
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	jmp	.L2
.L12:
	movl	$0, -12(%rbp)
	jmp	.L3
.L9:
	leaq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	m(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	setne	%al
	movzbl	%al, %edx
	movl	m(%rip), %eax
	addl	%edx, %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-12(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	jne	.L8
	movl	m(%rip), %eax
	cmpl	$1, %eax
	jle	.L5
	movl	m(%rip), %eax
	subl	$2, %eax
	jmp	.L6
.L5:
	movl	m(%rip), %eax
.L6:
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %esi
	movl	m(%rip), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	m(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	-8(%rbp), %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	testl	%eax, %eax
.L8:
	movl	m(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L3:
	movl	-12(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -12(%rbp)
	movl	-4(%rbp), %edx
	cmpl	%edx, %eax
	jl	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %edx
	movl	m(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %esi
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %esi
	movl	%esi, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, m(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
.L10:
	movl	m(%rip), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, a(%rip)
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	-4(%rbp), %edx
	imull	%edx, %eax
	testl	%eax, %eax
	jne	.L12
	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"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	a(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %r12
	movl	%esi, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	scanf@PLT
	movl	12(%rsp), %esi
	imull	%esi, %eax
	testl	%eax, %eax
	je	.L20
	movl	m(%rip), %eax
	testl	%esi, %esi
	jle	.L12
	leaq	8(%rsp), %rbp
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %r14d
	movq	%rbp, %rsi
	call	scanf@PLT
	movl	m(%rip), %edx
	movl	12(%rsp), %esi
	movl	%edx, %ecx
	shrl	$31, %ecx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%ecx, %eax
	cmpl	8(%rsp), %eax
	setne	%al
	movzbl	%al, %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	movl	%eax, m(%rip)
	addl	$1, 0(%r13,%rdx,4)
	cmpl	$1, %esi
	jg	.L5
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L15:
	movl	%edx, %r14d
.L5:
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	m(%rip), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%ecx, %eax
	cmpl	8(%rsp), %eax
	movl	%r14d, %ecx
	setne	%al
	andl	$1, %ecx
	movzbl	%al, %eax
	addl	%edx, %eax
	movslq	%eax, %rsi
	movl	%eax, m(%rip)
	movl	0(%r13,%rsi,4), %edx
	orl	%edx, %ecx
	jne	.L3
	movl	%eax, %edi
	cmpl	$1, %eax
	jle	.L4
	leal	-2(%rax), %edi
	movslq	%edi, %rsi
	movl	0(%r13,%rsi,4), %ecx
.L4:
	subl	$1, %eax
	movl	%edi, 8(%rsp)
	cltq
	movl	%edi, m(%rip)
	addl	0(%r13,%rax,4), %ecx
	movl	%ecx, 0(%r13,%rsi,4)
	movl	$0, 0(%r13,%rax,4)
	movl	0(%r13,%rsi,4), %edx
	movslq	%edi, %rsi
	movq	%rsi, %rax
.L3:
	addl	$1, %edx
	movl	%edx, 0(%r13,%rsi,4)
	movl	12(%rsp), %esi
	leal	1(%r14), %edx
	cmpl	%r14d, %esi
	jg	.L15
.L12:
	testl	%eax, %eax
	je	.L6
	leal	-1(%rax), %edx
	movl	%eax, %r9d
	cmpl	$2, %edx
	jbe	.L7
	movslq	%eax, %rdx
	movd	%eax, %xmm7
	pxor	%xmm3, %xmm3
	movl	%eax, %edi
	shrl	$2, %edi
	leaq	-12(%r13,%rdx,4), %rcx
	pshufd	$0, %xmm7, %xmm4
	leal	-1(%rdi), %r8d
	leaq	-16(%rcx), %rdx
	movdqa	%xmm3, %xmm5
	salq	$4, %r8
	movq	%rdx, %rdi
	paddd	.LC1(%rip), %xmm4
	subq	%r8, %rdi
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L32:
	subq	$16, %rdx
.L8:
	movdqa	%xmm4, %xmm0
	movdqu	(%rcx), %xmm6
	paddd	.LC2(%rip), %xmm4
	movups	%xmm5, (%rcx)
	movdqa	%xmm0, %xmm1
	movq	%rdx, %rcx
	psrld	$31, %xmm1
	paddd	%xmm1, %xmm0
	pand	.LC3(%rip), %xmm0
	psubd	%xmm1, %xmm0
	pshufd	$27, %xmm6, %xmm1
	movdqa	%xmm0, %xmm2
	psrlq	$32, %xmm0
	pmuludq	%xmm1, %xmm2
	psrlq	$32, %xmm1
	pmuludq	%xmm1, %xmm0
	pshufd	$8, %xmm2, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	psubd	%xmm1, %xmm3
	cmpq	%rdx, %rdi
	jne	.L32
	movdqa	%xmm3, %xmm0
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	addl	%edx, %esi
	movl	%eax, %edx
	andl	$-4, %edx
	subl	%edx, %eax
	cmpl	%edx, %r9d
	je	.L9
	leal	-1(%rax), %edx
.L7:
	movl	%eax, %edi
	shrl	$31, %edi
	leal	(%rax,%rdi), %ecx
	andl	$1, %ecx
	subl	%edi, %ecx
	movslq	%eax, %rdi
	imull	0(%r13,%rdi,4), %ecx
	movl	$0, 0(%r13,%rdi,4)
	subl	%ecx, %esi
	testl	%edx, %edx
	je	.L9
	movl	%edx, %edi
	movslq	%edx, %rcx
	shrl	$31, %edi
	addl	%edi, %edx
	andl	$1, %edx
	subl	%edi, %edx
	imull	0(%r13,%rcx,4), %edx
	movl	$0, 0(%r13,%rcx,4)
	subl	%edx, %esi
	subl	$2, %eax
	je	.L9
	movl	%eax, %ecx
	movslq	%eax, %rdx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	imull	0(%r13,%rdx,4), %eax
	movl	$0, 0(%r13,%rdx,4)
	subl	%eax, %esi
.L9:
	movl	%esi, 12(%rsp)
	movl	$0, m(%rip)
.L6:
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, 0(%r13)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L20:
	addq	$16, %rsp
	.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
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 524288
a:
	.zero	524288
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	0
	.long	-1
	.long	-2
	.long	-3
	.align 16
.LC2:
	.long	-4
	.long	-4
	.long	-4
	.long	-4
	.align 16
.LC3:
	.long	1
	.long	1
	.long	1
	.long	1
	.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"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	a(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %r12
	movl	%esi, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	scanf@PLT
	movl	12(%rsp), %esi
	imull	%esi, %eax
	testl	%eax, %eax
	je	.L20
	movl	m(%rip), %eax
	testl	%esi, %esi
	jle	.L12
	leaq	8(%rsp), %rbp
	xorl	%eax, %eax
	movq	%rbx, %rdi
	movl	$2, %r14d
	movq	%rbp, %rsi
	call	scanf@PLT
	movl	m(%rip), %edx
	movl	12(%rsp), %esi
	movl	%edx, %ecx
	shrl	$31, %ecx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%ecx, %eax
	cmpl	8(%rsp), %eax
	setne	%al
	movzbl	%al, %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	movl	%eax, m(%rip)
	addl	$1, 0(%r13,%rdx,4)
	cmpl	$1, %esi
	jg	.L5
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L15:
	movl	%edx, %r14d
.L5:
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	m(%rip), %edx
	movl	%edx, %ecx
	shrl	$31, %ecx
	leal	(%rdx,%rcx), %eax
	andl	$1, %eax
	subl	%ecx, %eax
	cmpl	8(%rsp), %eax
	movl	%r14d, %ecx
	setne	%al
	andl	$1, %ecx
	movzbl	%al, %eax
	addl	%edx, %eax
	movslq	%eax, %rsi
	movl	%eax, m(%rip)
	movl	0(%r13,%rsi,4), %edx
	orl	%edx, %ecx
	jne	.L3
	movl	%eax, %edi
	cmpl	$1, %eax
	jle	.L4
	leal	-2(%rax), %edi
	movslq	%edi, %rsi
	movl	0(%r13,%rsi,4), %ecx
.L4:
	subl	$1, %eax
	movl	%edi, 8(%rsp)
	cltq
	movl	%edi, m(%rip)
	addl	0(%r13,%rax,4), %ecx
	movl	%ecx, 0(%r13,%rsi,4)
	movl	$0, 0(%r13,%rax,4)
	movl	0(%r13,%rsi,4), %edx
	movslq	%edi, %rsi
	movq	%rsi, %rax
.L3:
	addl	$1, %edx
	movl	%edx, 0(%r13,%rsi,4)
	movl	12(%rsp), %esi
	leal	1(%r14), %edx
	cmpl	%r14d, %esi
	jg	.L15
.L12:
	testl	%eax, %eax
	je	.L6
	leal	-1(%rax), %edx
	movl	%eax, %r9d
	cmpl	$2, %edx
	jbe	.L7
	movslq	%eax, %rdx
	movd	%eax, %xmm7
	pxor	%xmm3, %xmm3
	movl	%eax, %edi
	shrl	$2, %edi
	leaq	-12(%r13,%rdx,4), %rcx
	pshufd	$0, %xmm7, %xmm4
	leal	-1(%rdi), %r8d
	leaq	-16(%rcx), %rdx
	movdqa	%xmm3, %xmm5
	salq	$4, %r8
	movq	%rdx, %rdi
	paddd	.LC1(%rip), %xmm4
	subq	%r8, %rdi
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L32:
	subq	$16, %rdx
.L8:
	movdqa	%xmm4, %xmm0
	movdqu	(%rcx), %xmm6
	paddd	.LC2(%rip), %xmm4
	movups	%xmm5, (%rcx)
	movdqa	%xmm0, %xmm1
	movq	%rdx, %rcx
	psrld	$31, %xmm1
	paddd	%xmm1, %xmm0
	pand	.LC3(%rip), %xmm0
	psubd	%xmm1, %xmm0
	pshufd	$27, %xmm6, %xmm1
	movdqa	%xmm0, %xmm2
	psrlq	$32, %xmm0
	pmuludq	%xmm1, %xmm2
	psrlq	$32, %xmm1
	pmuludq	%xmm1, %xmm0
	pshufd	$8, %xmm2, %xmm1
	pshufd	$8, %xmm0, %xmm0
	punpckldq	%xmm0, %xmm1
	psubd	%xmm1, %xmm3
	cmpq	%rdx, %rdi
	jne	.L32
	movdqa	%xmm3, %xmm0
	psrldq	$8, %xmm0
	paddd	%xmm0, %xmm3
	movdqa	%xmm3, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm3
	movd	%xmm3, %edx
	addl	%edx, %esi
	movl	%eax, %edx
	andl	$-4, %edx
	subl	%edx, %eax
	cmpl	%edx, %r9d
	je	.L9
	leal	-1(%rax), %edx
.L7:
	movl	%eax, %edi
	shrl	$31, %edi
	leal	(%rax,%rdi), %ecx
	andl	$1, %ecx
	subl	%edi, %ecx
	movslq	%eax, %rdi
	imull	0(%r13,%rdi,4), %ecx
	movl	$0, 0(%r13,%rdi,4)
	subl	%ecx, %esi
	testl	%edx, %edx
	je	.L9
	movl	%edx, %edi
	movslq	%edx, %rcx
	shrl	$31, %edi
	addl	%edi, %edx
	andl	$1, %edx
	subl	%edi, %edx
	imull	0(%r13,%rcx,4), %edx
	movl	$0, 0(%r13,%rcx,4)
	subl	%edx, %esi
	subl	$2, %eax
	je	.L9
	movl	%eax, %ecx
	movslq	%eax, %rdx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	imull	0(%r13,%rdx,4), %eax
	movl	$0, 0(%r13,%rdx,4)
	subl	%eax, %esi
.L9:
	movl	%esi, 12(%rsp)
	movl	$0, m(%rip)
.L6:
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, 0(%r13)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L20:
	addq	$16, %rsp
	.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
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 524288
a:
	.zero	524288
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	0
	.long	-1
	.long	-2
	.long	-3
	.align 16
.LC2:
	.long	-4
	.long	-4
	.long	-4
	.long	-4
	.align 16
.LC3:
	.long	1
	.long	1
	.long	1
	.long	1
	.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[1<<17],m;main(n,v,i){for(;scanf("%d",&n)*n;){for(i=0;i++<n;a[m]++)scanf("%d",&v),a[m+=v!=m%2]|i%2||(a[v=m>1?m-2:m]+=a[m-1],a[m-1]=0,m=v);for(;m;a[m--]=0)n-=m%2*a[m];*a=!printf("%d\n",n);}}
8
1
1
1
1
0
0
0
0
8
1
0
1
1
0
0
0
1
0
 8
1
1
1
1
0
0
0
0
8
1
0
0
1
0
0
0
1
0
 8
1
0
1
1
0
0
0
0
4
1
0
1
1
0
0
0
1
0
 8
1
0
1
1
0
0
0
0
2
1
0
1
1
0
0
-1
1
0
 8
0
0
1
1
0
0
0
0
2
1
0
2
1
0
0
-1
1
0
 8
1
1
1
1
0
0
0
0
8
1
0
1
1
0
0
1
1
0
 8
1
0
1
1
0
0
-1
0
8
1
0
0
1
0
0
0
1
0
 8
1
1
2
1
0
0
0
0
1
0
0
1
1
0
0
0
1
0
 8
0
0
1
1
0
0
0
0
3
1
0
1
1
0
0
-1
1
0
 8
1
1
1
1
1
0
0
0
8
1
0
1
1
0
0
1
1
0

4
2
 4
0
 6
2
 6
2
0
 6
2
2
 4
4
 6
0
 4
1
 6
2
1
 8
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[1<<17],m;main(n,v,i){for(;scanf("%d",&n)*n;){for(i=0;i++<n;a[m]++)scanf("%d",&v),a[m+=v!=m%2]|i%2||(a[v=m>1?m-2:m]+=a[m-1],a[m-1]=0,m=v);for(;m;a[m--]=0)n-=m%2*a[m];*a=!printf("%d\n",n);}}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 524288
a:
	.zero	524288
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	jmp	.L2
.L12:
	movl	$0, -12(%rbp)
	jmp	.L3
.L9:
	leaq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	m(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	setne	%al
	movzbl	%al, %edx
	movl	m(%rip), %eax
	addl	%edx, %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-12(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	jne	.L8
	movl	m(%rip), %eax
	cmpl	$1, %eax
	jle	.L5
	movl	m(%rip), %eax
	subl	$2, %eax
	jmp	.L6
.L5:
	movl	m(%rip), %eax
.L6:
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %esi
	movl	m(%rip), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	m(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	-8(%rbp), %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	testl	%eax, %eax
.L8:
	movl	m(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L3:
	movl	-12(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -12(%rbp)
	movl	-4(%rbp), %edx
	cmpl	%edx, %eax
	jl	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %edx
	movl	m(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %esi
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %esi
	movl	%esi, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, m(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
.L10:
	movl	m(%rip), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, a(%rip)
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	-4(%rbp), %edx
	imull	%edx, %eax
	testl	%eax, %eax
	jne	.L12
	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 32
	.type	a, @object
	.size	a, 524288
a:
	.zero	524288
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	jmp	.L2
.L12:
	movl	$0, -12(%rbp)
	jmp	.L3
.L9:
	leaq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	m(%rip), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	setne	%al
	movzbl	%al, %edx
	movl	m(%rip), %eax
	addl	%edx, %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-12(%rbp), %eax
	cltd
	shrl	$31, %edx
	addl	%edx, %eax
	andl	$1, %eax
	subl	%edx, %eax
	orl	%ecx, %eax
	testl	%eax, %eax
	jne	.L8
	movl	m(%rip), %eax
	cmpl	$1, %eax
	jle	.L5
	movl	m(%rip), %eax
	subl	$2, %eax
	jmp	.L6
.L5:
	movl	m(%rip), %eax
.L6:
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %esi
	movl	m(%rip), %edx
	subl	$1, %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	m(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
	movl	-8(%rbp), %eax
	movl	%eax, m(%rip)
	movl	m(%rip), %eax
	testl	%eax, %eax
.L8:
	movl	m(%rip), %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L3:
	movl	-12(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -12(%rbp)
	movl	-4(%rbp), %edx
	cmpl	%edx, %eax
	jl	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %edx
	movl	m(%rip), %eax
	movl	%eax, %ecx
	sarl	$31, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	andl	$1, %eax
	subl	%ecx, %eax
	movl	%eax, %esi
	movl	m(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	a(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %esi
	movl	%esi, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -4(%rbp)
	movl	m(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, m(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$0, (%rdx,%rax)
.L10:
	movl	m(%rip), %eax
	testl	%eax, %eax
	jne	.L11
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, a(%rip)
.L2:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	-4(%rbp), %edx
	imull	%edx, %eax
	testl	%eax, %eax
	jne	.L12
	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:
