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>

#define MOD_BY 10007

int N;
char sekinin[1024];

int memo[8][1000];

int tansaku(int key,int day) {
	int result=0;
	int i;
	if(day>=N)return 1;
	if(memo[key][day]>0)return memo[key][day]-1;
	for(i=0;i<8;i++) {
		int j,valid=1;
		for(j=0;j<3;j++) {
			if(sekinin[day]=="JOI"[j] && !(i&(1<<j)))valid=0;
		}
		if(valid && (i&key)) {
			result+=tansaku(i,day+1);
		}
	}
	result%=MOD_BY;
	memo[key][day]=result+1;
	return result; 
}

int main(void) {
	scanf("%d",&N);
	scanf("%s",sekinin);
	printf("%d\n",tansaku(1,0));
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	sekinin
	.align 32
	.type	sekinin, @object
	.size	sekinin, 1024
sekinin:
	.zero	1024
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 32000
memo:
	.zero	32000
	.section	.rodata
.LC0:
	.string	"JOI"
	.text
	.globl	tansaku
	.type	tansaku, @function
tansaku:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$0, -16(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, -12(%rbp)
	jmp	.L5
.L10:
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L6
.L8:
	movl	-24(%rbp), %eax
	cltq
	leaq	sekinin(%rip), %rdx
	movzbl	(%rax,%rdx), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	.LC0(%rip), %rcx
	movzbl	(%rax,%rcx), %eax
	cmpb	%al, %dl
	jne	.L7
	movl	-8(%rbp), %eax
	movl	-12(%rbp), %edx
	movl	%eax, %ecx
	sarl	%cl, %edx
	movl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L7
	movl	$0, -4(%rbp)
.L7:
	addl	$1, -8(%rbp)
.L6:
	cmpl	$2, -8(%rbp)
	jle	.L8
	cmpl	$0, -4(%rbp)
	je	.L9
	movl	-12(%rbp), %eax
	andl	-20(%rbp), %eax
	testl	%eax, %eax
	je	.L9
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-12(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	tansaku
	addl	%eax, -16(%rbp)
.L9:
	addl	$1, -12(%rbp)
.L5:
	cmpl	$7, -12(%rbp)
	jle	.L10
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1757988013, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$12, %edx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	imull	$10007, %edx, %edx
	subl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-16(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	tansaku, .-tansaku
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%s"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	sekinin(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, %esi
	movl	$1, %edi
	call	tansaku
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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
	.type	tansaku.part.0, @function
tansaku.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	sekinin(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L94
	cmpb	$79, %al
	je	.L7
	cmpb	$73, %al
	je	.L7
	movl	%edi, %ebp
	leaq	memo(%rip), %r14
	andl	$1, %ebp
	je	.L10
.L41:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	movl	$1, %ebp
	leaq	memo(%rip), %r14
	jge	.L3
	leaq	memo(%rip), %r14
	movslq	%esi, %rax
	movl	4000(%r14,%rax,4), %eax
	leal	-1(%rax), %ebp
	testl	%eax, %eax
	jg	.L3
	movl	$1, %edi
	call	tansaku.part.0
	movl	%eax, %ebp
.L3:
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	jne	.L10
.L90:
	testb	$3, %bl
	je	.L17
.L97:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L95
	movslq	%esi, %rax
	movl	12000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L20
	movl	$3, %edi
	call	tansaku.part.0
.L20:
	addl	%eax, %ebp
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L7:
	movzbl	(%r15,%r13), %eax
	xorl	%ebp, %ebp
	leaq	memo(%rip), %r14
.L10:
	cmpb	$73, %al
	je	.L28
	testb	$2, %bl
	jne	.L96
.L13:
	testb	$3, %bl
	jne	.L97
.L17:
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L24
	cmpb	$79, %al
	jne	.L28
.L40:
	testb	$6, %bl
	jne	.L98
	.p2align 4,,10
	.p2align 3
.L33:
	testb	$7, %bl
	jne	.L99
.L37:
	movslq	%ebp, %rax
	movl	%ebp, %edx
	imulq	$1757988013, %rax, %rax
	sarl	$31, %edx
	sarq	$44, %rax
	subl	%edx, %eax
	imull	$10007, %eax, %edx
	movl	%ebp, %eax
	subl	%edx, %eax
	movslq	%ebx, %rdx
	imulq	$1000, %rdx, %rdx
	leal	1(%rax), %ecx
	addq	%r13, %rdx
	movl	%ecx, (%r14,%rdx,4)
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L96:
	.cfi_restore_state
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L100
	movslq	%esi, %rax
	movl	8000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L15
	movl	$2, %edi
	call	tansaku.part.0
.L15:
	addl	%eax, %ebp
	cmpb	$73, (%r15,%r13)
	jne	.L13
.L28:
	testb	$4, %bl
	jne	.L101
.L24:
	testb	$5, %bl
	jne	.L102
.L29:
	cmpb	$74, (%r15,%r13)
	jne	.L40
	testb	$7, %bl
	je	.L37
.L99:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	movl	$1, %eax
	jge	.L38
	movslq	%esi, %rax
	movl	28000(%r14,%rax,4), %eax
	testl	%eax, %eax
	jg	.L103
	movl	$7, %edi
	call	tansaku.part.0
.L38:
	addl	%eax, %ebp
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L94:
	movl	%edi, %ebp
	leaq	memo(%rip), %r14
	andl	$1, %ebp
	jne	.L41
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L90
	jmp	.L10
.L102:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L104
	movslq	%esi, %rax
	movl	20000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L32
	movl	$5, %edi
	call	tansaku.part.0
.L32:
	addl	%eax, %ebp
	jmp	.L29
.L101:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L105
	movslq	%esi, %rax
	movl	16000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L27
	movl	$4, %edi
	call	tansaku.part.0
.L27:
	addl	%eax, %ebp
	cmpb	$79, (%r15,%r13)
	jne	.L24
	testb	$6, %bl
	je	.L33
.L98:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L106
	movslq	%esi, %rax
	movl	24000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L36
	movl	$6, %edi
	call	tansaku.part.0
.L36:
	addl	%eax, %ebp
	jmp	.L33
.L100:
	movl	$1, %eax
	jmp	.L15
.L95:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L17
.L106:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L33
.L105:
	movl	$1, %eax
	jmp	.L27
.L104:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L29
.L103:
	subl	$1, %eax
	addl	%eax, %ebp
	jmp	.L37
	.cfi_endproc
.LFE25:
	.size	tansaku.part.0, .-tansaku.part.0
	.p2align 4
	.globl	tansaku
	.type	tansaku, @function
tansaku:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%esi, N(%rip)
	jle	.L110
	movslq	%edi, %rax
	movslq	%esi, %rdx
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %eax
	testl	%eax, %eax
	jg	.L111
	jmp	tansaku.part.0
	.p2align 4,,10
	.p2align 3
.L111:
	subl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L110:
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	tansaku, .-tansaku
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	N(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	sekinin(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	movl	$1, %edx
	testl	%eax, %eax
	jle	.L113
	movl	4000+memo(%rip), %edx
	testl	%edx, %edx
	jg	.L117
	xorl	%esi, %esi
	movl	$1, %edi
	call	tansaku.part.0
	movl	%eax, %edx
.L113:
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L117:
	.cfi_restore_state
	subl	$1, %edx
	jmp	.L113
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 32000
memo:
	.zero	32000
	.globl	sekinin
	.align 32
	.type	sekinin, @object
	.size	sekinin, 1024
sekinin:
	.zero	1024
	.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
	.type	tansaku.part.0, @function
tansaku.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	sekinin(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L94
	cmpb	$79, %al
	je	.L7
	cmpb	$73, %al
	je	.L7
	movl	%edi, %ebp
	leaq	memo(%rip), %r14
	andl	$1, %ebp
	je	.L10
.L41:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	movl	$1, %ebp
	leaq	memo(%rip), %r14
	jge	.L3
	leaq	memo(%rip), %r14
	movslq	%esi, %rax
	movl	4000(%r14,%rax,4), %eax
	leal	-1(%rax), %ebp
	testl	%eax, %eax
	jg	.L3
	movl	$1, %edi
	call	tansaku.part.0
	movl	%eax, %ebp
.L3:
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	jne	.L10
.L90:
	testb	$3, %bl
	je	.L17
.L97:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L95
	movslq	%esi, %rax
	movl	12000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L20
	movl	$3, %edi
	call	tansaku.part.0
.L20:
	addl	%eax, %ebp
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L7:
	movzbl	(%r15,%r13), %eax
	xorl	%ebp, %ebp
	leaq	memo(%rip), %r14
.L10:
	cmpb	$73, %al
	je	.L28
	testb	$2, %bl
	jne	.L96
.L13:
	testb	$3, %bl
	jne	.L97
.L17:
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L24
	cmpb	$79, %al
	jne	.L28
.L40:
	testb	$6, %bl
	jne	.L98
	.p2align 4,,10
	.p2align 3
.L33:
	testb	$7, %bl
	jne	.L99
.L37:
	movslq	%ebp, %rax
	movl	%ebp, %edx
	imulq	$1757988013, %rax, %rax
	sarl	$31, %edx
	sarq	$44, %rax
	subl	%edx, %eax
	imull	$10007, %eax, %edx
	movl	%ebp, %eax
	subl	%edx, %eax
	movslq	%ebx, %rdx
	imulq	$1000, %rdx, %rdx
	leal	1(%rax), %ecx
	addq	%r13, %rdx
	movl	%ecx, (%r14,%rdx,4)
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L96:
	.cfi_restore_state
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L100
	movslq	%esi, %rax
	movl	8000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L15
	movl	$2, %edi
	call	tansaku.part.0
.L15:
	addl	%eax, %ebp
	cmpb	$73, (%r15,%r13)
	jne	.L13
.L28:
	testb	$4, %bl
	jne	.L101
.L24:
	testb	$5, %bl
	jne	.L102
.L29:
	cmpb	$74, (%r15,%r13)
	jne	.L40
	testb	$7, %bl
	je	.L37
.L99:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	movl	$1, %eax
	jge	.L38
	movslq	%esi, %rax
	movl	28000(%r14,%rax,4), %eax
	testl	%eax, %eax
	jg	.L103
	movl	$7, %edi
	call	tansaku.part.0
.L38:
	addl	%eax, %ebp
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L94:
	movl	%edi, %ebp
	leaq	memo(%rip), %r14
	andl	$1, %ebp
	jne	.L41
	movzbl	(%r15,%r13), %eax
	cmpb	$74, %al
	je	.L90
	jmp	.L10
.L102:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L104
	movslq	%esi, %rax
	movl	20000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L32
	movl	$5, %edi
	call	tansaku.part.0
.L32:
	addl	%eax, %ebp
	jmp	.L29
.L101:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L105
	movslq	%esi, %rax
	movl	16000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L27
	movl	$4, %edi
	call	tansaku.part.0
.L27:
	addl	%eax, %ebp
	cmpb	$79, (%r15,%r13)
	jne	.L24
	testb	$6, %bl
	je	.L33
.L98:
	leal	1(%r12), %esi
	cmpl	N(%rip), %esi
	jge	.L106
	movslq	%esi, %rax
	movl	24000(%r14,%rax,4), %edx
	leal	-1(%rdx), %eax
	testl	%edx, %edx
	jg	.L36
	movl	$6, %edi
	call	tansaku.part.0
.L36:
	addl	%eax, %ebp
	jmp	.L33
.L100:
	movl	$1, %eax
	jmp	.L15
.L95:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L17
.L106:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L33
.L105:
	movl	$1, %eax
	jmp	.L27
.L104:
	movl	$1, %eax
	addl	%eax, %ebp
	jmp	.L29
.L103:
	subl	$1, %eax
	addl	%eax, %ebp
	jmp	.L37
	.cfi_endproc
.LFE25:
	.size	tansaku.part.0, .-tansaku.part.0
	.p2align 4
	.globl	tansaku
	.type	tansaku, @function
tansaku:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%esi, N(%rip)
	jle	.L110
	movslq	%edi, %rax
	movslq	%esi, %rdx
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %eax
	testl	%eax, %eax
	jg	.L111
	jmp	tansaku.part.0
	.p2align 4,,10
	.p2align 3
.L111:
	subl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L110:
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	tansaku, .-tansaku
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	N(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	sekinin(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	movl	$1, %edx
	testl	%eax, %eax
	jle	.L113
	movl	4000+memo(%rip), %edx
	testl	%edx, %edx
	jg	.L117
	xorl	%esi, %esi
	movl	$1, %edi
	call	tansaku.part.0
	movl	%eax, %edx
.L113:
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L117:
	.cfi_restore_state
	subl	$1, %edx
	jmp	.L113
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 32000
memo:
	.zero	32000
	.globl	sekinin
	.align 32
	.type	sekinin, @object
	.size	sekinin, 1024
sekinin:
	.zero	1024
	.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>

#define MOD_BY 10007

int N;
char sekinin[1024];

int memo[8][1000];

int tansaku(int key,int day) {
	int result=0;
	int i;
	if(day>=N)return 1;
	if(memo[key][day]>0)return memo[key][day]-1;
	for(i=0;i<8;i++) {
		int j,valid=1;
		for(j=0;j<3;j++) {
			if(sekinin[day]=="JOI"[j] && !(i&(1<<j)))valid=0;
		}
		if(valid && (i&key)) {
			result+=tansaku(i,day+1);
		}
	}
	result%=MOD_BY;
	memo[key][day]=result+1;
	return result; 
}

int main(void) {
	scanf("%d",&N);
	scanf("%s",sekinin);
	printf("%d\n",tansaku(1,0));
	return 0;
}
2
OI

7

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>

#define MOD_BY 10007

int N;
char sekinin[1024];

int memo[8][1000];

int tansaku(int key,int day) {
	int result=0;
	int i;
	if(day>=N)return 1;
	if(memo[key][day]>0)return memo[key][day]-1;
	for(i=0;i<8;i++) {
		int j,valid=1;
		for(j=0;j<3;j++) {
			if(sekinin[day]=="JOI"[j] && !(i&(1<<j)))valid=0;
		}
		if(valid && (i&key)) {
			result+=tansaku(i,day+1);
		}
	}
	result%=MOD_BY;
	memo[key][day]=result+1;
	return result; 
}

int main(void) {
	scanf("%d",&N);
	scanf("%s",sekinin);
	printf("%d\n",tansaku(1,0));
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	sekinin
	.align 32
	.type	sekinin, @object
	.size	sekinin, 1024
sekinin:
	.zero	1024
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 32000
memo:
	.zero	32000
	.section	.rodata
.LC0:
	.string	"JOI"
	.text
	.globl	tansaku
	.type	tansaku, @function
tansaku:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$0, -16(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, -12(%rbp)
	jmp	.L5
.L10:
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L6
.L8:
	movl	-24(%rbp), %eax
	cltq
	leaq	sekinin(%rip), %rdx
	movzbl	(%rax,%rdx), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	.LC0(%rip), %rcx
	movzbl	(%rax,%rcx), %eax
	cmpb	%al, %dl
	jne	.L7
	movl	-8(%rbp), %eax
	movl	-12(%rbp), %edx
	movl	%eax, %ecx
	sarl	%cl, %edx
	movl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L7
	movl	$0, -4(%rbp)
.L7:
	addl	$1, -8(%rbp)
.L6:
	cmpl	$2, -8(%rbp)
	jle	.L8
	cmpl	$0, -4(%rbp)
	je	.L9
	movl	-12(%rbp), %eax
	andl	-20(%rbp), %eax
	testl	%eax, %eax
	je	.L9
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-12(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	tansaku
	addl	%eax, -16(%rbp)
.L9:
	addl	$1, -12(%rbp)
.L5:
	cmpl	$7, -12(%rbp)
	jle	.L10
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1757988013, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$12, %edx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	imull	$10007, %edx, %edx
	subl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-16(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	tansaku, .-tansaku
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%s"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	sekinin(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, %esi
	movl	$1, %edi
	call	tansaku
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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	sekinin
	.align 32
	.type	sekinin, @object
	.size	sekinin, 1024
sekinin:
	.zero	1024
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 32000
memo:
	.zero	32000
	.section	.rodata
.LC0:
	.string	"JOI"
	.text
	.globl	tansaku
	.type	tansaku, @function
tansaku:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$0, -16(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, -12(%rbp)
	jmp	.L5
.L10:
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L6
.L8:
	movl	-24(%rbp), %eax
	cltq
	leaq	sekinin(%rip), %rdx
	movzbl	(%rax,%rdx), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	.LC0(%rip), %rcx
	movzbl	(%rax,%rcx), %eax
	cmpb	%al, %dl
	jne	.L7
	movl	-8(%rbp), %eax
	movl	-12(%rbp), %edx
	movl	%eax, %ecx
	sarl	%cl, %edx
	movl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L7
	movl	$0, -4(%rbp)
.L7:
	addl	$1, -8(%rbp)
.L6:
	cmpl	$2, -8(%rbp)
	jle	.L8
	cmpl	$0, -4(%rbp)
	je	.L9
	movl	-12(%rbp), %eax
	andl	-20(%rbp), %eax
	testl	%eax, %eax
	je	.L9
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-12(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	tansaku
	addl	%eax, -16(%rbp)
.L9:
	addl	$1, -12(%rbp)
.L5:
	cmpl	$7, -12(%rbp)
	jle	.L10
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1757988013, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$12, %edx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	imull	$10007, %edx, %edx
	subl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-16(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	tansaku, .-tansaku
	.section	.rodata
.LC1:
	.string	"%d"
.LC2:
	.string	"%s"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	sekinin(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, %esi
	movl	$1, %edi
	call	tansaku
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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:
