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>
#include <string.h>

int dp[31];

int rec(int i){
  if (dp[i] != -1) return dp[i];
  if (i == 0) return 1;
  if (i == 1) return 1;
  if (i == 2) return 2;
  return dp[i] = rec(i - 1) + rec(i - 2) + rec(i - 3);
}

int main(void)
{
  int n;
  while (1){
    scanf("%d", &n);
    if (n == 0) break;
    memset(dp, -1, sizeof(dp));
    printf("%d\n", rec(n) / 3650 + 1);
  }

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 124
dp:
	.zero	124
	.text
	.globl	rec
	.type	rec, @function
rec:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movl	%edi, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L2
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L3
.L2:
	cmpl	$0, -20(%rbp)
	jne	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	cmpl	$1, -20(%rbp)
	jne	.L5
	movl	$1, %eax
	jmp	.L3
.L5:
	cmpl	$2, -20(%rbp)
	jne	.L6
	movl	$2, %eax
	jmp	.L3
.L6:
	movl	-20(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	rec
	movl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$2, %eax
	movl	%eax, %edi
	call	rec
	addl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$3, %eax
	movl	%eax, %edi
	call	rec
	leal	(%rbx,%rax), %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	rec, .-rec
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L10:
	leaq	-12(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-12(%rbp), %eax
	testl	%eax, %eax
	je	.L14
	movl	$124, %edx
	movl	$-1, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-12(%rbp), %eax
	movl	%eax, %edi
	call	rec
	movslq	%eax, %rdx
	imulq	$602472125, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$9, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L10
.L14:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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	rec.part.0, @function
rec.part.0:
.LFB37:
	.cfi_startproc
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	dp(%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
	movslq	%edi, %rbx
	leal	-1(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %r12d
	cmpl	$-1, %r12d
	jne	.L2
	movl	$1, %r12d
	cmpl	$1, %edi
	jbe	.L2
	movl	$2, %r12d
	cmpl	$2, %edi
	je	.L2
	call	rec.part.0
	movl	%eax, %r12d
.L2:
	leal	-2(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L3
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L3
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L3
	call	rec.part.0
.L3:
	leal	-3(%rbx), %edx
	addl	%eax, %r12d
	movslq	%edx, %r14
	movl	0(%r13,%r14,4), %eax
	cmpl	$-1, %eax
	jne	.L4
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L4
	movl	$2, %eax
	cmpl	$2, %edx
	je	.L4
	leal	-4(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %ebp
	cmpl	$-1, %ebp
	jne	.L5
	movl	$1, %ebp
	cmpl	$1, %edi
	jbe	.L5
	movl	$2, %ebp
	cmpl	$2, %edi
	je	.L5
	call	rec.part.0
	movl	%eax, %ebp
.L5:
	leal	-5(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L6
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L6
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L6
	call	rec.part.0
.L6:
	leal	-6(%rbx), %edi
	addl	%eax, %ebp
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L7
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L7
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L7
	call	rec.part.0
.L7:
	addl	%ebp, %eax
	movl	%eax, 0(%r13,%r14,4)
.L4:
	addl	%r12d, %eax
	movl	%eax, 0(%r13,%rbx,4)
	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
.LFE37:
	.size	rec.part.0, .-rec.part.0
	.p2align 4
	.globl	rec
	.type	rec, @function
rec:
.LFB35:
	.cfi_startproc
	endbr64
	movslq	%edi, %r10
	leaq	dp(%rip), %r9
	movl	(%r9,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L61
.L58:
	ret
	.p2align 4,,10
	.p2align 3
.L61:
	movq	%r10, %rcx
	movl	$1, %eax
	cmpl	$1, %r10d
	jbe	.L58
	movl	$2, %eax
	cmpl	$2, %r10d
	je	.L58
	leal	-1(%r10), %edi
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %r8d
	cmpl	$-1, %r8d
	jne	.L30
	movl	$1, %r8d
	cmpl	$1, %edi
	jbe	.L30
	movl	$2, %r8d
	cmpl	$2, %edi
	je	.L30
	call	rec.part.0
	movl	%eax, %r8d
.L30:
	leal	-2(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L31
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L31
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L31
	call	rec.part.0
.L31:
	leal	-3(%rcx), %edx
	addl	%eax, %r8d
	movslq	%edx, %r11
	movl	(%r9,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L32
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L32
	movl	$2, %eax
	cmpl	$2, %edx
	je	.L32
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %esi
	cmpl	$-1, %esi
	jne	.L33
	movl	$1, %esi
	cmpl	$1, %edi
	jbe	.L33
	movl	$2, %esi
	cmpl	$2, %edi
	je	.L33
	call	rec.part.0
	movl	%eax, %esi
.L33:
	leal	-5(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L34
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L34
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L34
	call	rec.part.0
.L34:
	leal	-6(%rcx), %edi
	addl	%eax, %esi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L35
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L35
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L35
	call	rec.part.0
.L35:
	addl	%esi, %eax
	movl	%eax, (%r9,%r11,4)
.L32:
	addl	%r8d, %eax
	movl	%eax, (%r9,%r10,4)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE35:
	.size	rec, .-rec
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	dp(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L74:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	4(%rsp), %rcx
	testl	%ecx, %ecx
	je	.L63
	pcmpeqd	%xmm0, %xmm0
	leal	-1(%rcx), %eax
	movq	$-1, 112+dp(%rip)
	movl	$1, %edx
	movl	$-1, 120+dp(%rip)
	movaps	%xmm0, dp(%rip)
	movaps	%xmm0, 16+dp(%rip)
	movaps	%xmm0, 32+dp(%rip)
	movaps	%xmm0, 48+dp(%rip)
	movaps	%xmm0, 64+dp(%rip)
	movaps	%xmm0, 80+dp(%rip)
	movaps	%xmm0, 96+dp(%rip)
	cmpl	$1, %eax
	jbe	.L64
	movl	%eax, %r8d
	cmpl	$2, %eax
	je	.L65
	movl	%eax, %edi
	call	rec.part.0
	movl	%eax, %r8d
.L65:
	leal	-2(%rcx), %edx
	leal	-3(%rcx), %esi
	movslq	%edx, %r10
	movslq	%esi, %r9
	movl	0(%r13,%r10,4), %eax
	cmpl	$-1, %eax
	jne	.L66
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L66
	cmpl	$2, %edx
	je	.L78
	movl	0(%r13,%r9,4), %r11d
	cmpl	$-1, %r11d
	jne	.L67
	movl	$1, %r11d
	cmpl	$1, %esi
	jbe	.L67
	cmpl	$2, %esi
	je	.L80
	movl	%esi, %edi
	call	rec.part.0
	movl	%eax, %r11d
.L67:
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L68
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L68
	cmpl	$2, %edi
	je	.L82
	call	rec.part.0
.L68:
	leal	-5(%rcx), %edi
	addl	%eax, %r11d
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L69
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L69
	cmpl	$2, %edi
	je	.L84
	call	rec.part.0
.L69:
	addl	%r11d, %eax
	movl	%eax, 0(%r13,%r10,4)
.L66:
	addl	%eax, %r8d
	movl	0(%r13,%r9,4), %eax
	cmpl	$-1, %eax
	jne	.L70
	movl	$1, %eax
	cmpl	$1, %esi
	jbe	.L70
	cmpl	$2, %esi
	je	.L86
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %esi
	cmpl	$-1, %esi
	jne	.L71
	movl	$1, %esi
	cmpl	$1, %edi
	jbe	.L71
	cmpl	$2, %edi
	je	.L88
	call	rec.part.0
	movl	%eax, %esi
.L71:
	leal	-5(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L72
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L72
	cmpl	$2, %edi
	je	.L90
	call	rec.part.0
.L72:
	leal	-6(%rcx), %edi
	addl	%eax, %esi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L73
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L73
	cmpl	$2, %edi
	je	.L92
	call	rec.part.0
.L73:
	addl	%esi, %eax
	movl	%eax, 0(%r13,%r9,4)
.L70:
	addl	%r8d, %eax
	movslq	%eax, %rdx
	movl	%eax, 0(%r13,%rcx,4)
	sarl	$31, %eax
	imulq	$602472125, %rdx, %rdx
	sarq	$41, %rdx
	subl	%eax, %edx
	addl	$1, %edx
.L64:
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L74
	.p2align 4,,10
	.p2align 3
.L63:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L98
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L78:
	.cfi_restore_state
	movl	$2, %eax
	jmp	.L66
.L86:
	movl	$2, %eax
	jmp	.L70
.L92:
	movl	$2, %eax
	jmp	.L73
.L88:
	movl	$2, %esi
	jmp	.L71
.L80:
	movl	$2, %r11d
	jmp	.L67
.L82:
	movl	$2, %eax
	jmp	.L68
.L84:
	movl	$2, %eax
	jmp	.L69
.L90:
	movl	$2, %eax
	jmp	.L72
.L98:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 124
dp:
	.zero	124
	.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	rec.part.0, @function
rec.part.0:
.LFB37:
	.cfi_startproc
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	leaq	dp(%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
	movslq	%edi, %rbx
	leal	-1(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %r12d
	cmpl	$-1, %r12d
	jne	.L2
	movl	$1, %r12d
	cmpl	$1, %edi
	jbe	.L2
	movl	$2, %r12d
	cmpl	$2, %edi
	je	.L2
	call	rec.part.0
	movl	%eax, %r12d
.L2:
	leal	-2(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L3
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L3
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L3
	call	rec.part.0
.L3:
	leal	-3(%rbx), %edx
	addl	%eax, %r12d
	movslq	%edx, %r14
	movl	0(%r13,%r14,4), %eax
	cmpl	$-1, %eax
	jne	.L4
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L4
	movl	$2, %eax
	cmpl	$2, %edx
	je	.L4
	leal	-4(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %ebp
	cmpl	$-1, %ebp
	jne	.L5
	movl	$1, %ebp
	cmpl	$1, %edi
	jbe	.L5
	movl	$2, %ebp
	cmpl	$2, %edi
	je	.L5
	call	rec.part.0
	movl	%eax, %ebp
.L5:
	leal	-5(%rbx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L6
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L6
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L6
	call	rec.part.0
.L6:
	leal	-6(%rbx), %edi
	addl	%eax, %ebp
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L7
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L7
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L7
	call	rec.part.0
.L7:
	addl	%ebp, %eax
	movl	%eax, 0(%r13,%r14,4)
.L4:
	addl	%r12d, %eax
	movl	%eax, 0(%r13,%rbx,4)
	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
.LFE37:
	.size	rec.part.0, .-rec.part.0
	.p2align 4
	.globl	rec
	.type	rec, @function
rec:
.LFB35:
	.cfi_startproc
	endbr64
	movslq	%edi, %r10
	leaq	dp(%rip), %r9
	movl	(%r9,%r10,4), %eax
	cmpl	$-1, %eax
	je	.L61
.L58:
	ret
	.p2align 4,,10
	.p2align 3
.L61:
	movq	%r10, %rcx
	movl	$1, %eax
	cmpl	$1, %r10d
	jbe	.L58
	movl	$2, %eax
	cmpl	$2, %r10d
	je	.L58
	leal	-1(%r10), %edi
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %r8d
	cmpl	$-1, %r8d
	jne	.L30
	movl	$1, %r8d
	cmpl	$1, %edi
	jbe	.L30
	movl	$2, %r8d
	cmpl	$2, %edi
	je	.L30
	call	rec.part.0
	movl	%eax, %r8d
.L30:
	leal	-2(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L31
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L31
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L31
	call	rec.part.0
.L31:
	leal	-3(%rcx), %edx
	addl	%eax, %r8d
	movslq	%edx, %r11
	movl	(%r9,%r11,4), %eax
	cmpl	$-1, %eax
	jne	.L32
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L32
	movl	$2, %eax
	cmpl	$2, %edx
	je	.L32
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %esi
	cmpl	$-1, %esi
	jne	.L33
	movl	$1, %esi
	cmpl	$1, %edi
	jbe	.L33
	movl	$2, %esi
	cmpl	$2, %edi
	je	.L33
	call	rec.part.0
	movl	%eax, %esi
.L33:
	leal	-5(%rcx), %edi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L34
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L34
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L34
	call	rec.part.0
.L34:
	leal	-6(%rcx), %edi
	addl	%eax, %esi
	movslq	%edi, %rax
	movl	(%r9,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L35
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L35
	movl	$2, %eax
	cmpl	$2, %edi
	je	.L35
	call	rec.part.0
.L35:
	addl	%esi, %eax
	movl	%eax, (%r9,%r11,4)
.L32:
	addl	%r8d, %eax
	movl	%eax, (%r9,%r10,4)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE35:
	.size	rec, .-rec
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	dp(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L74:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	4(%rsp), %rcx
	testl	%ecx, %ecx
	je	.L63
	pcmpeqd	%xmm0, %xmm0
	leal	-1(%rcx), %eax
	movq	$-1, 112+dp(%rip)
	movl	$1, %edx
	movl	$-1, 120+dp(%rip)
	movaps	%xmm0, dp(%rip)
	movaps	%xmm0, 16+dp(%rip)
	movaps	%xmm0, 32+dp(%rip)
	movaps	%xmm0, 48+dp(%rip)
	movaps	%xmm0, 64+dp(%rip)
	movaps	%xmm0, 80+dp(%rip)
	movaps	%xmm0, 96+dp(%rip)
	cmpl	$1, %eax
	jbe	.L64
	movl	%eax, %r8d
	cmpl	$2, %eax
	je	.L65
	movl	%eax, %edi
	call	rec.part.0
	movl	%eax, %r8d
.L65:
	leal	-2(%rcx), %edx
	leal	-3(%rcx), %esi
	movslq	%edx, %r10
	movslq	%esi, %r9
	movl	0(%r13,%r10,4), %eax
	cmpl	$-1, %eax
	jne	.L66
	movl	$1, %eax
	cmpl	$1, %edx
	jbe	.L66
	cmpl	$2, %edx
	je	.L78
	movl	0(%r13,%r9,4), %r11d
	cmpl	$-1, %r11d
	jne	.L67
	movl	$1, %r11d
	cmpl	$1, %esi
	jbe	.L67
	cmpl	$2, %esi
	je	.L80
	movl	%esi, %edi
	call	rec.part.0
	movl	%eax, %r11d
.L67:
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L68
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L68
	cmpl	$2, %edi
	je	.L82
	call	rec.part.0
.L68:
	leal	-5(%rcx), %edi
	addl	%eax, %r11d
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L69
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L69
	cmpl	$2, %edi
	je	.L84
	call	rec.part.0
.L69:
	addl	%r11d, %eax
	movl	%eax, 0(%r13,%r10,4)
.L66:
	addl	%eax, %r8d
	movl	0(%r13,%r9,4), %eax
	cmpl	$-1, %eax
	jne	.L70
	movl	$1, %eax
	cmpl	$1, %esi
	jbe	.L70
	cmpl	$2, %esi
	je	.L86
	leal	-4(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %esi
	cmpl	$-1, %esi
	jne	.L71
	movl	$1, %esi
	cmpl	$1, %edi
	jbe	.L71
	cmpl	$2, %edi
	je	.L88
	call	rec.part.0
	movl	%eax, %esi
.L71:
	leal	-5(%rcx), %edi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L72
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L72
	cmpl	$2, %edi
	je	.L90
	call	rec.part.0
.L72:
	leal	-6(%rcx), %edi
	addl	%eax, %esi
	movslq	%edi, %rax
	movl	0(%r13,%rax,4), %eax
	cmpl	$-1, %eax
	jne	.L73
	movl	$1, %eax
	cmpl	$1, %edi
	jbe	.L73
	cmpl	$2, %edi
	je	.L92
	call	rec.part.0
.L73:
	addl	%esi, %eax
	movl	%eax, 0(%r13,%r9,4)
.L70:
	addl	%r8d, %eax
	movslq	%eax, %rdx
	movl	%eax, 0(%r13,%rcx,4)
	sarl	$31, %eax
	imulq	$602472125, %rdx, %rdx
	sarq	$41, %rdx
	subl	%eax, %edx
	addl	$1, %edx
.L64:
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L74
	.p2align 4,,10
	.p2align 3
.L63:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L98
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L78:
	.cfi_restore_state
	movl	$2, %eax
	jmp	.L66
.L86:
	movl	$2, %eax
	jmp	.L70
.L92:
	movl	$2, %eax
	jmp	.L73
.L88:
	movl	$2, %esi
	jmp	.L71
.L80:
	movl	$2, %r11d
	jmp	.L67
.L82:
	movl	$2, %eax
	jmp	.L68
.L84:
	movl	$2, %eax
	jmp	.L69
.L90:
	movl	$2, %eax
	jmp	.L72
.L98:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 124
dp:
	.zero	124
	.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>
#include <string.h>

int dp[31];

int rec(int i){
  if (dp[i] != -1) return dp[i];
  if (i == 0) return 1;
  if (i == 1) return 1;
  if (i == 2) return 2;
  return dp[i] = rec(i - 1) + rec(i - 2) + rec(i - 3);
}

int main(void)
{
  int n;
  while (1){
    scanf("%d", &n);
    if (n == 0) break;
    memset(dp, -1, sizeof(dp));
    printf("%d\n", rec(n) / 3650 + 1);
  }

  return 0;
}
1
10
14
25
0
 1
10
14
23
0
 1
10
14
6
0
 1
1
20
25
0
 1
10
14
24
0
 1
10
0
25
0
 1
19
14
5
0
 1
18
0
25
0
 1
18
1
25
0
 1
0
14
6
0

1
1
1
701
 1
1
1
207
 1
1
1
1
 1
1
34
701
 1
1
1
381
 1
1
 1
19
1
1
 1
10
 1
10
1
701
 1

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>
#include <string.h>

int dp[31];

int rec(int i){
  if (dp[i] != -1) return dp[i];
  if (i == 0) return 1;
  if (i == 1) return 1;
  if (i == 2) return 2;
  return dp[i] = rec(i - 1) + rec(i - 2) + rec(i - 3);
}

int main(void)
{
  int n;
  while (1){
    scanf("%d", &n);
    if (n == 0) break;
    memset(dp, -1, sizeof(dp));
    printf("%d\n", rec(n) / 3650 + 1);
  }

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 124
dp:
	.zero	124
	.text
	.globl	rec
	.type	rec, @function
rec:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movl	%edi, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L2
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L3
.L2:
	cmpl	$0, -20(%rbp)
	jne	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	cmpl	$1, -20(%rbp)
	jne	.L5
	movl	$1, %eax
	jmp	.L3
.L5:
	cmpl	$2, -20(%rbp)
	jne	.L6
	movl	$2, %eax
	jmp	.L3
.L6:
	movl	-20(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	rec
	movl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$2, %eax
	movl	%eax, %edi
	call	rec
	addl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$3, %eax
	movl	%eax, %edi
	call	rec
	leal	(%rbx,%rax), %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	rec, .-rec
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L10:
	leaq	-12(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-12(%rbp), %eax
	testl	%eax, %eax
	je	.L14
	movl	$124, %edx
	movl	$-1, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-12(%rbp), %eax
	movl	%eax, %edi
	call	rec
	movslq	%eax, %rdx
	imulq	$602472125, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$9, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L10
.L14:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 124
dp:
	.zero	124
	.text
	.globl	rec
	.type	rec, @function
rec:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	movl	%edi, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	$-1, %eax
	je	.L2
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	jmp	.L3
.L2:
	cmpl	$0, -20(%rbp)
	jne	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	cmpl	$1, -20(%rbp)
	jne	.L5
	movl	$1, %eax
	jmp	.L3
.L5:
	cmpl	$2, -20(%rbp)
	jne	.L6
	movl	$2, %eax
	jmp	.L3
.L6:
	movl	-20(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	rec
	movl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$2, %eax
	movl	%eax, %edi
	call	rec
	addl	%eax, %ebx
	movl	-20(%rbp), %eax
	subl	$3, %eax
	movl	%eax, %edi
	call	rec
	leal	(%rbx,%rax), %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
.L3:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	rec, .-rec
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L10:
	leaq	-12(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-12(%rbp), %eax
	testl	%eax, %eax
	je	.L14
	movl	$124, %edx
	movl	$-1, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-12(%rbp), %eax
	movl	%eax, %edi
	call	rec
	movslq	%eax, %rdx
	imulq	$602472125, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$9, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L10
.L14:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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:
