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

```c
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}
int compl(const void *a, const void *b){return (*(long*)a>*(long*)b)-(*(long*)a<*(long*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int s[3];
int main(void){
	int n=nextpint();
	long ans=1;
	for(int i=0; i<n; i++){
		int a=nextpint();
		int b=(s[0]==a)+(s[1]==a)+(s[2]==a);
		ans=(ans*b)%P;
		if(0);
		else if(s[0]==a) s[0]++;
		else if(s[1]==a) s[1]++;
		else if(s[2]==a) s[2]++;
	}
	printf("%d\n", ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.globl	compw
	.type	compw, @function
compw:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %ecx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	compw, .-compw
	.globl	compr
	.type	compr, @function
compr:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	compr, .-compr
	.globl	compl
	.type	compl, @function
compl:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movq	(%rax), %rcx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rcx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	compl, .-compl
	.globl	nextpint
	.type	nextpint, @function
nextpint:
.LFB10:
	.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
	call	getchar@PLT
	movb	%al, -9(%rbp)
	jmp	.L10
.L11:
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L10:
	cmpb	$47, -9(%rbp)
	jle	.L11
	cmpb	$57, -9(%rbp)
	jg	.L11
	movq	$0, -8(%rbp)
	jmp	.L12
.L14:
	movq	-8(%rbp), %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, %rdx
	movsbq	-9(%rbp), %rax
	addq	%rdx, %rax
	subq	$48, %rax
	movq	%rax, -8(%rbp)
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L12:
	cmpb	$47, -9(%rbp)
	jle	.L13
	cmpb	$57, -9(%rbp)
	jle	.L14
.L13:
	movq	-8(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	nextpint, .-nextpint
	.globl	s
	.bss
	.align 8
	.type	s, @object
	.size	s, 12
s:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.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
	call	nextpint
	movl	%eax, -20(%rbp)
	movq	$1, -8(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L17
.L21:
	call	nextpint
	movl	%eax, -16(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %edx
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %edx
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	imulq	-8(%rbp), %rax
	movq	%rax, %rcx
	movabsq	$-8543223828751151131, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	leaq	(%rdx,%rcx), %rax
	sarq	$29, %rax
	movq	%rcx, %rdx
	sarq	$63, %rdx
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	imulq	$1000000007, %rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L18
	movl	s(%rip), %eax
	addl	$1, %eax
	movl	%eax, s(%rip)
	jmp	.L19
.L18:
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L20
	movl	4+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 4+s(%rip)
	jmp	.L19
.L20:
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L19
	movl	8+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 8+s(%rip)
.L19:
	addl	$1, -24(%rbp)
.L17:
	movl	-24(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L21
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	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
.LFE13:
	.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	comp
	.type	comp, @function
comp:
.LFB63:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE63:
	.size	comp, .-comp
	.p2align 4
	.globl	compw
	.type	compw, @function
compw:
.LFB64:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	cmpl	%eax, (%rdi)
	setg	%al
	setl	%dl
	movzbl	%dl, %edx
	movzbl	%al, %eax
	subl	%edx, %eax
	ret
	.cfi_endproc
.LFE64:
	.size	compw, .-compw
	.p2align 4
	.globl	compr
	.type	compr, @function
compr:
.LFB65:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE65:
	.size	compr, .-compr
	.p2align 4
	.globl	compl
	.type	compl, @function
compl:
.LFB66:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rax
	cmpq	%rax, (%rdi)
	setg	%al
	setl	%dl
	movzbl	%dl, %edx
	movzbl	%al, %eax
	subl	%edx, %eax
	ret
	.cfi_endproc
.LFE66:
	.size	compl, .-compl
	.p2align 4
	.globl	nextpint
	.type	nextpint, @function
nextpint:
.LFB67:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	.p2align 4,,10
	.p2align 3
.L16:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpb	$9, %dl
	ja	.L16
	movsbq	%al, %rdx
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	stdin(%rip), %rdi
	leaq	(%rbx,%rbx,4), %rax
	leaq	-48(%rdx,%rax,2), %rbx
	call	getc@PLT
	movsbq	%al, %rdx
	subl	$48, %eax
	cmpb	$9, %al
	jbe	.L10
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE67:
	.size	nextpint, .-nextpint
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB70:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	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	$8, %rsp
	.cfi_def_cfa_offset 64
	call	nextpint
	testl	%eax, %eax
	jle	.L27
	movl	%eax, %ebp
	xorl	%ebx, %ebx
	movl	$1, %r12d
	movabsq	$-8543223828751151131, %r14
	leaq	s(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L26:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpb	$9, %dl
	ja	.L26
	movsbq	%al, %rcx
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L22:
	movq	stdin(%rip), %rdi
	leaq	(%r15,%r15,4), %rax
	leaq	-48(%rcx,%rax,2), %r15
	call	getc@PLT
	movsbq	%al, %rcx
	subl	$48, %eax
	cmpb	$9, %al
	jbe	.L22
	movl	0(%r13), %esi
	movl	4+s(%rip), %edi
	xorl	%ecx, %ecx
	movl	8+s(%rip), %r8d
	cmpl	%r15d, %esi
	sete	%cl
	xorl	%eax, %eax
	cmpl	%r15d, %edi
	sete	%al
	addl	%eax, %ecx
	xorl	%eax, %eax
	cmpl	%r15d, %r8d
	sete	%al
	addl	%eax, %ecx
	movslq	%ecx, %rcx
	imulq	%r12, %rcx
	movq	%rcx, %rax
	mulq	%r14
	shrq	$29, %rdx
	imulq	$1000000007, %rdx, %rax
	subq	%rax, %rcx
	movq	%rcx, %r12
	cmpl	%r15d, %esi
	je	.L33
	cmpl	%r15d, %edi
	je	.L34
	cmpl	%r15d, %r8d
	jne	.L24
	addl	$1, %r8d
	movl	%r8d, 8+s(%rip)
	.p2align 4,,10
	.p2align 3
.L24:
	addl	$1, %ebx
	cmpl	%ebx, %ebp
	jne	.L26
.L18:
	movq	%r12, %rdx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L33:
	.cfi_restore_state
	addl	$1, %esi
	movl	%esi, 0(%r13)
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L34:
	addl	$1, %edi
	movl	%edi, 4+s(%rip)
	jmp	.L24
.L27:
	movl	$1, %r12d
	jmp	.L18
	.cfi_endproc
.LFE70:
	.size	main, .-main
	.globl	s
	.bss
	.align 8
	.type	s, @object
	.size	s, 12
s:
	.zero	12
	.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	comp
	.type	comp, @function
comp:
.LFB63:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE63:
	.size	comp, .-comp
	.p2align 4
	.globl	compw
	.type	compw, @function
compw:
.LFB64:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	cmpl	%eax, (%rdi)
	setg	%al
	setl	%dl
	movzbl	%dl, %edx
	movzbl	%al, %eax
	subl	%edx, %eax
	ret
	.cfi_endproc
.LFE64:
	.size	compw, .-compw
	.p2align 4
	.globl	compr
	.type	compr, @function
compr:
.LFB65:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE65:
	.size	compr, .-compr
	.p2align 4
	.globl	compl
	.type	compl, @function
compl:
.LFB66:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rax
	cmpq	%rax, (%rdi)
	setg	%al
	setl	%dl
	movzbl	%dl, %edx
	movzbl	%al, %eax
	subl	%edx, %eax
	ret
	.cfi_endproc
.LFE66:
	.size	compl, .-compl
	.p2align 4
	.globl	nextpint
	.type	nextpint, @function
nextpint:
.LFB67:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	.p2align 4,,10
	.p2align 3
.L16:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpb	$9, %dl
	ja	.L16
	movsbq	%al, %rdx
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	stdin(%rip), %rdi
	leaq	(%rbx,%rbx,4), %rax
	leaq	-48(%rdx,%rax,2), %rbx
	call	getc@PLT
	movsbq	%al, %rdx
	subl	$48, %eax
	cmpb	$9, %al
	jbe	.L10
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE67:
	.size	nextpint, .-nextpint
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB70:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	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	$8, %rsp
	.cfi_def_cfa_offset 64
	call	nextpint
	testl	%eax, %eax
	jle	.L27
	movl	%eax, %ebp
	xorl	%ebx, %ebx
	movl	$1, %r12d
	movabsq	$-8543223828751151131, %r14
	leaq	s(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L26:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	leal	-48(%rax), %edx
	cmpb	$9, %dl
	ja	.L26
	movsbq	%al, %rcx
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L22:
	movq	stdin(%rip), %rdi
	leaq	(%r15,%r15,4), %rax
	leaq	-48(%rcx,%rax,2), %r15
	call	getc@PLT
	movsbq	%al, %rcx
	subl	$48, %eax
	cmpb	$9, %al
	jbe	.L22
	movl	0(%r13), %esi
	movl	4+s(%rip), %edi
	xorl	%ecx, %ecx
	movl	8+s(%rip), %r8d
	cmpl	%r15d, %esi
	sete	%cl
	xorl	%eax, %eax
	cmpl	%r15d, %edi
	sete	%al
	addl	%eax, %ecx
	xorl	%eax, %eax
	cmpl	%r15d, %r8d
	sete	%al
	addl	%eax, %ecx
	movslq	%ecx, %rcx
	imulq	%r12, %rcx
	movq	%rcx, %rax
	mulq	%r14
	shrq	$29, %rdx
	imulq	$1000000007, %rdx, %rax
	subq	%rax, %rcx
	movq	%rcx, %r12
	cmpl	%r15d, %esi
	je	.L33
	cmpl	%r15d, %edi
	je	.L34
	cmpl	%r15d, %r8d
	jne	.L24
	addl	$1, %r8d
	movl	%r8d, 8+s(%rip)
	.p2align 4,,10
	.p2align 3
.L24:
	addl	$1, %ebx
	cmpl	%ebx, %ebp
	jne	.L26
.L18:
	movq	%r12, %rdx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L33:
	.cfi_restore_state
	addl	$1, %esi
	movl	%esi, 0(%r13)
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L34:
	addl	$1, %edi
	movl	%edi, 4+s(%rip)
	jmp	.L24
.L27:
	movl	$1, %r12d
	jmp	.L18
	.cfi_endproc
.LFE70:
	.size	main, .-main
	.globl	s
	.bss
	.align 8
	.type	s, @object
	.size	s, 12
s:
	.zero	12
	.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 <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}
int compl(const void *a, const void *b){return (*(long*)a>*(long*)b)-(*(long*)a<*(long*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int s[3];
int main(void){
	int n=nextpint();
	long ans=1;
	for(int i=0; i<n; i++){
		int a=nextpint();
		int b=(s[0]==a)+(s[1]==a)+(s[2]==a);
		ans=(ans*b)%P;
		if(0);
		else if(s[0]==a) s[0]++;
		else if(s[1]==a) s[1]++;
		else if(s[2]==a) s[2]++;
	}
	printf("%d\n", ans);
}

54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 20 13 14 14 15 15 15 16 16 16 17 17 17
 6
0 1 2 0 3 4
 6
0 1 1 3 4 5
 54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17
 6
0 1 0 3 4 5
 54
0 0 1 0 1 2 1 2 3 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17
 6
0 1 0 1 4 5
 54
0 0 1 0 1 2 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17
 6
0 1 0 1 2 5
 54
0 0 1 0 1 2 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17

0
 6
 0
 0
 0
 0
 0
 0
 0
 0

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

```c
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}
int compl(const void *a, const void *b){return (*(long*)a>*(long*)b)-(*(long*)a<*(long*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int s[3];
int main(void){
	int n=nextpint();
	long ans=1;
	for(int i=0; i<n; i++){
		int a=nextpint();
		int b=(s[0]==a)+(s[1]==a)+(s[2]==a);
		ans=(ans*b)%P;
		if(0);
		else if(s[0]==a) s[0]++;
		else if(s[1]==a) s[1]++;
		else if(s[2]==a) s[2]++;
	}
	printf("%d\n", ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.globl	compw
	.type	compw, @function
compw:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %ecx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	compw, .-compw
	.globl	compr
	.type	compr, @function
compr:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	compr, .-compr
	.globl	compl
	.type	compl, @function
compl:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movq	(%rax), %rcx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rcx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	compl, .-compl
	.globl	nextpint
	.type	nextpint, @function
nextpint:
.LFB10:
	.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
	call	getchar@PLT
	movb	%al, -9(%rbp)
	jmp	.L10
.L11:
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L10:
	cmpb	$47, -9(%rbp)
	jle	.L11
	cmpb	$57, -9(%rbp)
	jg	.L11
	movq	$0, -8(%rbp)
	jmp	.L12
.L14:
	movq	-8(%rbp), %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, %rdx
	movsbq	-9(%rbp), %rax
	addq	%rdx, %rax
	subq	$48, %rax
	movq	%rax, -8(%rbp)
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L12:
	cmpb	$47, -9(%rbp)
	jle	.L13
	cmpb	$57, -9(%rbp)
	jle	.L14
.L13:
	movq	-8(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	nextpint, .-nextpint
	.globl	s
	.bss
	.align 8
	.type	s, @object
	.size	s, 12
s:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.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
	call	nextpint
	movl	%eax, -20(%rbp)
	movq	$1, -8(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L17
.L21:
	call	nextpint
	movl	%eax, -16(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %edx
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %edx
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	imulq	-8(%rbp), %rax
	movq	%rax, %rcx
	movabsq	$-8543223828751151131, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	leaq	(%rdx,%rcx), %rax
	sarq	$29, %rax
	movq	%rcx, %rdx
	sarq	$63, %rdx
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	imulq	$1000000007, %rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L18
	movl	s(%rip), %eax
	addl	$1, %eax
	movl	%eax, s(%rip)
	jmp	.L19
.L18:
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L20
	movl	4+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 4+s(%rip)
	jmp	.L19
.L20:
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L19
	movl	8+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 8+s(%rip)
.L19:
	addl	$1, -24(%rbp)
.L17:
	movl	-24(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L21
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	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
.LFE13:
	.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	comp
	.type	comp, @function
comp:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	comp, .-comp
	.globl	compw
	.type	compw, @function
compw:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movq	-16(%rbp), %rax
	movl	(%rax), %eax
	cmpl	%eax, %ecx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	compw, .-compw
	.globl	compr
	.type	compr, @function
compr:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	compr, .-compr
	.globl	compl
	.type	compl, @function
compl:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	setg	%al
	movzbl	%al, %edx
	movq	-8(%rbp), %rax
	movq	(%rax), %rcx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rcx
	setl	%al
	movzbl	%al, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	compl, .-compl
	.globl	nextpint
	.type	nextpint, @function
nextpint:
.LFB10:
	.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
	call	getchar@PLT
	movb	%al, -9(%rbp)
	jmp	.L10
.L11:
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L10:
	cmpb	$47, -9(%rbp)
	jle	.L11
	cmpb	$57, -9(%rbp)
	jg	.L11
	movq	$0, -8(%rbp)
	jmp	.L12
.L14:
	movq	-8(%rbp), %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, %rdx
	movsbq	-9(%rbp), %rax
	addq	%rdx, %rax
	subq	$48, %rax
	movq	%rax, -8(%rbp)
	call	getchar@PLT
	movb	%al, -9(%rbp)
.L12:
	cmpb	$47, -9(%rbp)
	jle	.L13
	cmpb	$57, -9(%rbp)
	jle	.L14
.L13:
	movq	-8(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	nextpint, .-nextpint
	.globl	s
	.bss
	.align 8
	.type	s, @object
	.size	s, 12
s:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.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
	call	nextpint
	movl	%eax, -20(%rbp)
	movq	$1, -8(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L17
.L21:
	call	nextpint
	movl	%eax, -16(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %edx
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %edx
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	cltq
	imulq	-8(%rbp), %rax
	movq	%rax, %rcx
	movabsq	$-8543223828751151131, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	leaq	(%rdx,%rcx), %rax
	sarq	$29, %rax
	movq	%rcx, %rdx
	sarq	$63, %rdx
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	imulq	$1000000007, %rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -8(%rbp)
	movl	s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L18
	movl	s(%rip), %eax
	addl	$1, %eax
	movl	%eax, s(%rip)
	jmp	.L19
.L18:
	movl	4+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L20
	movl	4+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 4+s(%rip)
	jmp	.L19
.L20:
	movl	8+s(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jne	.L19
	movl	8+s(%rip), %eax
	addl	$1, %eax
	movl	%eax, 8+s(%rip)
.L19:
	addl	$1, -24(%rbp)
.L17:
	movl	-24(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jl	.L21
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	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
.LFE13:
	.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:
