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 INF 1000000009

int N, M;
int D[1000];
int C[1000];

int memo[1024][1024];

int search(int pos, int day) {
	int ret = INF;
	int idousuru, idousinai;
	if (pos >= N) return 0;
	if (day >= M) return INF;
	if (memo[pos][day] > 0) return memo[pos][day] - 1;
	idousuru = search(pos + 1, day + 1) + D[pos] * C[day];
	idousinai = search(pos, day + 1);
	if (idousuru <= idousinai) {
		ret = idousuru;
	} else {
		ret = idousinai;
	}
	memo[pos][day] = ret + 1;
	return ret;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &D[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		if (scanf("%d", &C[i]) != 1) return 1;
	}
	printf("%d\n", search(0, 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	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	D
	.align 32
	.type	D, @object
	.size	D, 4000
D:
	.zero	4000
	.globl	C
	.align 32
	.type	C, @object
	.size	C, 4000
C:
	.zero	4000
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 4194304
memo:
	.zero	4194304
	.text
	.globl	search
	.type	search, @function
search:
.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	$1000000009, -12(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L2
	movl	$0, %eax
	jmp	.L3
.L2:
	movl	M(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L4
	movl	$1000000009, %eax
	jmp	.L3
.L4:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L5:
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, %esi
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	C(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%edx, %eax
	addl	%esi, %eax
	movl	%eax, -8(%rbp)
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jg	.L6
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L7
.L6:
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L7:
	movl	-12(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-12(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	search, .-search
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.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
	subq	$16, %rsp
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$2, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L10
.L9:
	movl	$0, -4(%rbp)
	jmp	.L11
.L13:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L12
	movl	$1, %eax
	jmp	.L10
.L12:
	addl	$1, -4(%rbp)
.L11:
	movl	N(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L13
	movl	$0, -4(%rbp)
	jmp	.L14
.L16:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	C(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L15
	movl	$1, %eax
	jmp	.L10
.L15:
	addl	$1, -4(%rbp)
.L14:
	movl	M(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L16
	movl	$0, %esi
	movl	$0, %edi
	call	search
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L10:
	leave
	.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	search.part.0, @function
search.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leal	1(%rsi), %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edi, %r14d
	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
	leal	1(%rdi), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	N(%rip), %edx
	cmpl	%edx, %ebp
	jge	.L12
	movl	M(%rip), %esi
	cmpl	%esi, %r15d
	jge	.L13
	movslq	%ebp, %r13
	movslq	%r15d, %rcx
	leaq	memo(%rip), %r12
	movq	%r13, %rax
	salq	$10, %rax
	addq	%rcx, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L3
	movslq	%edi, %r13
	movslq	%ebx, %rbp
	leaq	D(%rip), %rsi
	leaq	C(%rip), %rdi
	movl	(%rsi,%r13,4), %esi
	imull	(%rdi,%rbp,4), %esi
	leal	-1(%rax,%rsi), %ebx
	xorl	%eax, %eax
	cmpl	%edx, %r14d
	jge	.L4
.L5:
	movq	%r13, %rax
	salq	$10, %rax
	addq	%rcx, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L10
	subl	$1, %eax
.L4:
	cmpl	%eax, %ebx
	cmovle	%ebx, %eax
	movl	%eax, %r8d
	movq	%r13, %rax
	salq	$10, %rax
	leal	1(%r8), %edx
	addq	%rbp, %rax
	movl	%edx, (%r12,%rax,4)
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r8d, %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
.L3:
	.cfi_restore_state
	leal	2(%rdi), %edi
	leal	2(%rbx), %r11d
	cmpl	%edi, %edx
	jle	.L15
	cmpl	%r11d, %esi
	jle	.L16
	movslq	%edi, %rax
	movslq	%r11d, %r8
	salq	$10, %rax
	addq	%r8, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L7
	subl	$1, %eax
.L6:
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	movl	(%r8,%r13,4), %r10d
	imull	(%r9,%rcx,4), %r10d
	addl	%eax, %r10d
.L11:
	movl	$1000000009, %eax
	cmpl	%esi, %r11d
	jge	.L8
	movq	%r13, %rax
	movslq	%r11d, %rsi
	salq	$10, %rax
	addq	%rsi, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L9
	subl	$1, %eax
.L8:
	cmpl	%r10d, %eax
	cmovg	%r10d, %eax
	salq	$10, %r13
	addq	%rcx, %r13
	leal	1(%rax), %ecx
	movl	%ecx, (%r12,%r13,4)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L12:
	xorl	%eax, %eax
	leaq	memo(%rip), %r12
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
.L2:
	movslq	%ebx, %rbp
	movslq	%r14d, %r13
	movl	(%r8,%r13,4), %r8d
	imull	(%r9,%rbp,4), %r8d
	leal	(%r8,%rax), %ebx
	xorl	%eax, %eax
	cmpl	%edx, %r14d
	jge	.L4
	cmpl	M(%rip), %r15d
	movl	$1000000009, %eax
	jge	.L4
	movslq	%r15d, %rcx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L10:
	movl	%r15d, %esi
	movl	%r14d, %edi
	call	search.part.0
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	xorl	%eax, %eax
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L13:
	movl	$1000000009, %eax
	leaq	memo(%rip), %r12
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L7:
	movl	%r11d, %esi
	movq	%rcx, 8(%rsp)
	movl	%r11d, 4(%rsp)
	call	search.part.0
	movq	8(%rsp), %rcx
	movl	4(%rsp), %r11d
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	movl	(%r8,%r13,4), %r10d
	movl	N(%rip), %edx
	imull	(%r9,%rcx,4), %r10d
	addl	%eax, %r10d
	cmpl	%edx, %ebp
	jl	.L24
	xorl	%eax, %eax
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%r11d, %esi
	movl	%ebp, %edi
	movq	%rcx, 24(%rsp)
	movq	%r8, 16(%rsp)
	movq	%r9, 8(%rsp)
	movl	%r10d, 4(%rsp)
	call	search.part.0
	movl	N(%rip), %edx
	movl	4(%rsp), %r10d
	movq	8(%rsp), %r9
	movq	16(%rsp), %r8
	movq	24(%rsp), %rcx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L16:
	movl	$1000000009, %eax
	jmp	.L6
.L24:
	movl	M(%rip), %esi
	jmp	.L11
	.cfi_endproc
.LFE25:
	.size	search.part.0, .-search.part.0
	.p2align 4
	.globl	search
	.type	search, @function
search:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edi, N(%rip)
	jle	.L28
	cmpl	%esi, M(%rip)
	jle	.L29
	movslq	%edi, %rax
	movslq	%esi, %rdx
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %eax
	testl	%eax, %eax
	jle	.L27
	subl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L27:
	jmp	search.part.0
	.p2align 4,,10
	.p2align 3
.L28:
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L29:
	movl	$1000000009, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	search, .-search
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%eax, %eax
	leaq	M(%rip), %rdx
	leaq	N(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC0(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	cmpl	$2, %eax
	jne	.L34
	cmpl	$0, N(%rip)
	jle	.L33
	leaq	D(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r12
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L41:
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, N(%rip)
	jle	.L33
.L35:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L41
.L34:
	movl	$1, %eax
.L30:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	cmpl	$0, M(%rip)
	jle	.L36
	leaq	C(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r12
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L42:
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, M(%rip)
	jle	.L36
.L37:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L42
	jmp	.L34
.L36:
	xorl	%esi, %esi
	xorl	%edi, %edi
	call	search
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L30
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 4194304
memo:
	.zero	4194304
	.globl	C
	.align 32
	.type	C, @object
	.size	C, 4000
C:
	.zero	4000
	.globl	D
	.align 32
	.type	D, @object
	.size	D, 4000
D:
	.zero	4000
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.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	search.part.0, @function
search.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leal	1(%rsi), %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edi, %r14d
	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
	leal	1(%rdi), %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	N(%rip), %edx
	cmpl	%edx, %ebp
	jge	.L12
	movl	M(%rip), %esi
	cmpl	%esi, %r15d
	jge	.L13
	movslq	%ebp, %r13
	movslq	%r15d, %rcx
	leaq	memo(%rip), %r12
	movq	%r13, %rax
	salq	$10, %rax
	addq	%rcx, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L3
	movslq	%edi, %r13
	movslq	%ebx, %rbp
	leaq	D(%rip), %rsi
	leaq	C(%rip), %rdi
	movl	(%rsi,%r13,4), %esi
	imull	(%rdi,%rbp,4), %esi
	leal	-1(%rax,%rsi), %ebx
	xorl	%eax, %eax
	cmpl	%edx, %r14d
	jge	.L4
.L5:
	movq	%r13, %rax
	salq	$10, %rax
	addq	%rcx, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L10
	subl	$1, %eax
.L4:
	cmpl	%eax, %ebx
	cmovle	%ebx, %eax
	movl	%eax, %r8d
	movq	%r13, %rax
	salq	$10, %rax
	leal	1(%r8), %edx
	addq	%rbp, %rax
	movl	%edx, (%r12,%rax,4)
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r8d, %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
.L3:
	.cfi_restore_state
	leal	2(%rdi), %edi
	leal	2(%rbx), %r11d
	cmpl	%edi, %edx
	jle	.L15
	cmpl	%r11d, %esi
	jle	.L16
	movslq	%edi, %rax
	movslq	%r11d, %r8
	salq	$10, %rax
	addq	%r8, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L7
	subl	$1, %eax
.L6:
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	movl	(%r8,%r13,4), %r10d
	imull	(%r9,%rcx,4), %r10d
	addl	%eax, %r10d
.L11:
	movl	$1000000009, %eax
	cmpl	%esi, %r11d
	jge	.L8
	movq	%r13, %rax
	movslq	%r11d, %rsi
	salq	$10, %rax
	addq	%rsi, %rax
	movl	(%r12,%rax,4), %eax
	testl	%eax, %eax
	jle	.L9
	subl	$1, %eax
.L8:
	cmpl	%r10d, %eax
	cmovg	%r10d, %eax
	salq	$10, %r13
	addq	%rcx, %r13
	leal	1(%rax), %ecx
	movl	%ecx, (%r12,%r13,4)
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L12:
	xorl	%eax, %eax
	leaq	memo(%rip), %r12
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
.L2:
	movslq	%ebx, %rbp
	movslq	%r14d, %r13
	movl	(%r8,%r13,4), %r8d
	imull	(%r9,%rbp,4), %r8d
	leal	(%r8,%rax), %ebx
	xorl	%eax, %eax
	cmpl	%edx, %r14d
	jge	.L4
	cmpl	M(%rip), %r15d
	movl	$1000000009, %eax
	jge	.L4
	movslq	%r15d, %rcx
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L10:
	movl	%r15d, %esi
	movl	%r14d, %edi
	call	search.part.0
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	xorl	%eax, %eax
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L13:
	movl	$1000000009, %eax
	leaq	memo(%rip), %r12
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L7:
	movl	%r11d, %esi
	movq	%rcx, 8(%rsp)
	movl	%r11d, 4(%rsp)
	call	search.part.0
	movq	8(%rsp), %rcx
	movl	4(%rsp), %r11d
	leaq	D(%rip), %r8
	leaq	C(%rip), %r9
	movl	(%r8,%r13,4), %r10d
	movl	N(%rip), %edx
	imull	(%r9,%rcx,4), %r10d
	addl	%eax, %r10d
	cmpl	%edx, %ebp
	jl	.L24
	xorl	%eax, %eax
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%r11d, %esi
	movl	%ebp, %edi
	movq	%rcx, 24(%rsp)
	movq	%r8, 16(%rsp)
	movq	%r9, 8(%rsp)
	movl	%r10d, 4(%rsp)
	call	search.part.0
	movl	N(%rip), %edx
	movl	4(%rsp), %r10d
	movq	8(%rsp), %r9
	movq	16(%rsp), %r8
	movq	24(%rsp), %rcx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L16:
	movl	$1000000009, %eax
	jmp	.L6
.L24:
	movl	M(%rip), %esi
	jmp	.L11
	.cfi_endproc
.LFE25:
	.size	search.part.0, .-search.part.0
	.p2align 4
	.globl	search
	.type	search, @function
search:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edi, N(%rip)
	jle	.L28
	cmpl	%esi, M(%rip)
	jle	.L29
	movslq	%edi, %rax
	movslq	%esi, %rdx
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	memo(%rip), %rdx
	movl	(%rdx,%rax,4), %eax
	testl	%eax, %eax
	jle	.L27
	subl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L27:
	jmp	search.part.0
	.p2align 4,,10
	.p2align 3
.L28:
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L29:
	movl	$1000000009, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	search, .-search
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%eax, %eax
	leaq	M(%rip), %rdx
	leaq	N(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC0(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	cmpl	$2, %eax
	jne	.L34
	cmpl	$0, N(%rip)
	jle	.L33
	leaq	D(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r12
	jmp	.L35
	.p2align 4,,10
	.p2align 3
.L41:
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, N(%rip)
	jle	.L33
.L35:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L41
.L34:
	movl	$1, %eax
.L30:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	cmpl	$0, M(%rip)
	jle	.L36
	leaq	C(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r12
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L42:
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, M(%rip)
	jle	.L36
.L37:
	xorl	%eax, %eax
	movq	%rbx, %rsi
	movq	%r12, %rdi
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L42
	jmp	.L34
.L36:
	xorl	%esi, %esi
	xorl	%edi, %edi
	call	search
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L30
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	memo
	.bss
	.align 32
	.type	memo, @object
	.size	memo, 4194304
memo:
	.zero	4194304
	.globl	C
	.align 32
	.type	C, @object
	.size	C, 4000
C:
	.zero	4000
	.globl	D
	.align 32
	.type	D, @object
	.size	D, 4000
D:
	.zero	4000
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.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 INF 1000000009

int N, M;
int D[1000];
int C[1000];

int memo[1024][1024];

int search(int pos, int day) {
	int ret = INF;
	int idousuru, idousinai;
	if (pos >= N) return 0;
	if (day >= M) return INF;
	if (memo[pos][day] > 0) return memo[pos][day] - 1;
	idousuru = search(pos + 1, day + 1) + D[pos] * C[day];
	idousinai = search(pos, day + 1);
	if (idousuru <= idousinai) {
		ret = idousuru;
	} else {
		ret = idousinai;
	}
	memo[pos][day] = ret + 1;
	return ret;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &D[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		if (scanf("%d", &C[i]) != 1) return 1;
	}
	printf("%d\n", search(0, 0));
	return 0;
}
3 5
10
25
15
50
30
6
40
30
 3 5
10
38
15
50
30
6
40
30
 3 5
10
38
7
50
30
6
40
30
 1 5
10
38
7
50
30
6
40
30
 3 5
10
25
15
50
30
15
12
30
 3 5
1
25
15
50
30
6
40
30
 3 5
10
38
18
50
30
6
40
30
 3 5
10
47
7
50
30
6
40
30
 1 5
10
38
7
32
30
1
40
30
 3 5
10
25
15
50
30
15
9
30

900
 978
 738
 60
 855
 630
 1068
 792
 10
 810

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 INF 1000000009

int N, M;
int D[1000];
int C[1000];

int memo[1024][1024];

int search(int pos, int day) {
	int ret = INF;
	int idousuru, idousinai;
	if (pos >= N) return 0;
	if (day >= M) return INF;
	if (memo[pos][day] > 0) return memo[pos][day] - 1;
	idousuru = search(pos + 1, day + 1) + D[pos] * C[day];
	idousinai = search(pos, day + 1);
	if (idousuru <= idousinai) {
		ret = idousuru;
	} else {
		ret = idousinai;
	}
	memo[pos][day] = ret + 1;
	return ret;
}

int main(void) {
	int i;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &D[i]) != 1) return 1;
	}
	for (i = 0; i < M; i++) {
		if (scanf("%d", &C[i]) != 1) return 1;
	}
	printf("%d\n", search(0, 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	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	D
	.align 32
	.type	D, @object
	.size	D, 4000
D:
	.zero	4000
	.globl	C
	.align 32
	.type	C, @object
	.size	C, 4000
C:
	.zero	4000
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 4194304
memo:
	.zero	4194304
	.text
	.globl	search
	.type	search, @function
search:
.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	$1000000009, -12(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L2
	movl	$0, %eax
	jmp	.L3
.L2:
	movl	M(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L4
	movl	$1000000009, %eax
	jmp	.L3
.L4:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L5:
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, %esi
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	C(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%edx, %eax
	addl	%esi, %eax
	movl	%eax, -8(%rbp)
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jg	.L6
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L7
.L6:
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L7:
	movl	-12(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-12(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	search, .-search
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.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
	subq	$16, %rsp
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$2, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L10
.L9:
	movl	$0, -4(%rbp)
	jmp	.L11
.L13:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L12
	movl	$1, %eax
	jmp	.L10
.L12:
	addl	$1, -4(%rbp)
.L11:
	movl	N(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L13
	movl	$0, -4(%rbp)
	jmp	.L14
.L16:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	C(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L15
	movl	$1, %eax
	jmp	.L10
.L15:
	addl	$1, -4(%rbp)
.L14:
	movl	M(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L16
	movl	$0, %esi
	movl	$0, %edi
	call	search
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L10:
	leave
	.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	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	D
	.align 32
	.type	D, @object
	.size	D, 4000
D:
	.zero	4000
	.globl	C
	.align 32
	.type	C, @object
	.size	C, 4000
C:
	.zero	4000
	.globl	memo
	.align 32
	.type	memo, @object
	.size	memo, 4194304
memo:
	.zero	4194304
	.text
	.globl	search
	.type	search, @function
search:
.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	$1000000009, -12(%rbp)
	movl	N(%rip), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L2
	movl	$0, %eax
	jmp	.L3
.L2:
	movl	M(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L4
	movl	$1000000009, %eax
	jmp	.L3
.L4:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	jmp	.L3
.L5:
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, %esi
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	C(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%edx, %eax
	addl	%esi, %eax
	movl	%eax, -8(%rbp)
	movl	-24(%rbp), %eax
	leal	1(%rax), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	search
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jg	.L6
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L7
.L6:
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L7:
	movl	-12(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$10, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	memo(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-12(%rbp), %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	search, .-search
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d"
.LC2:
	.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
	subq	$16, %rsp
	leaq	M(%rip), %rax
	movq	%rax, %rdx
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$2, %eax
	je	.L9
	movl	$1, %eax
	jmp	.L10
.L9:
	movl	$0, -4(%rbp)
	jmp	.L11
.L13:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	D(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L12
	movl	$1, %eax
	jmp	.L10
.L12:
	addl	$1, -4(%rbp)
.L11:
	movl	N(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L13
	movl	$0, -4(%rbp)
	jmp	.L14
.L16:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	C(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$1, %eax
	je	.L15
	movl	$1, %eax
	jmp	.L10
.L15:
	addl	$1, -4(%rbp)
.L14:
	movl	M(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L16
	movl	$0, %esi
	movl	$0, %edi
	call	search
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L10:
	leave
	.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:
