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 max(a,b) ((a)>(b)?(a):(b))

long long ans;
int m[41];

int solve(int kt,int hn,long long then){
	//printf("%lld\n",ans);
	if(hn==0){
		ans=max(ans,then+9*(kt+1));
		return 0;
	}else{
		if(kt!=0){
			solve(kt-1,1,then+m[kt]);
			if(m[kt]>0)solve(kt-1,0,then+m[kt]-1);
			return 0;
		}else {
			ans=max(ans,then+m[kt]);
			return 0;
		}
	}
}

int main(){
	int i;
	long long n;
	scanf("%lld",&n);
	for(i=0;i<40;i++){
		m[i]=n%10;
		n/=10;
	}
	solve(40,1,0);
	printf("%lld\n",ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 164
m:
	.zero	164
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movq	%rdx, -16(%rbp)
	cmpl	$0, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
	jmp	.L3
.L2:
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$1, %esi
	movl	%eax, %edi
	call	solve
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	leaq	-1(%rax), %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	solve
.L5:
	movl	$0, %eax
	jmp	.L3
.L4:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L7
.L8:
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	movq	%rcx, %rsi
	sarq	$63, %rsi
	subq	%rsi, %rax
	movq	%rax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rcx, %rdx
	movl	%edx, %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	sarq	$63, %rcx
	movq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, -16(%rbp)
	addl	$1, -20(%rbp)
.L7:
	cmpl	$39, -20(%rbp)
	jle	.L8
	movl	$0, %edx
	movl	$1, %esi
	movl	$40, %edi
	call	solve
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.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	solve.part.0, @function
solve.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%edi, %rdx
	leaq	m(%rip), %rax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %r13d
	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
	movq	%rdx, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	movslq	(%rax,%rdx,4), %rbp
	movq	%rbp, %r12
	addq	%rsi, %rbp
	subl	$1, %r13d
	jne	.L9
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%rbp, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L5:
	testl	%r12d, %r12d
	jle	.L1
	leal	(%rbx,%rbx,8), %eax
	cltq
	leaq	-1(%rbp,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L1:
	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
	.p2align 4,,10
	.p2align 3
.L9:
	.cfi_restore_state
	movslq	%r13d, %rdx
	movl	%ebx, %edi
	movslq	(%rax,%rdx,4), %r14
	movq	%r14, %r15
	addq	%rbp, %r14
	subl	$2, %edi
	jne	.L10
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r14, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L4:
	testl	%r15d, %r15d
	jle	.L5
	leal	0(%r13,%r13,8), %eax
	cltq
	leaq	-1(%r14,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r14, %rsi
	call	solve.part.0
	jmp	.L4
	.cfi_endproc
.LFE25:
	.size	solve.part.0, .-solve.part.0
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %ecx
	testl	%esi, %esi
	je	.L24
	movslq	m(%rip), %rax
	testl	%edi, %edi
	jne	.L25
.L23:
	addq	%rdx, %rax
	movq	ans(%rip), %rdx
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L25:
	leaq	m(%rip), %rax
	movslq	%edi, %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %r10d
	movslq	(%rax,%rsi,4), %rsi
	movq	%rsi, %r9
	leaq	(%rsi,%rdx), %r8
	subl	$1, %r10d
	jne	.L26
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r8, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L18:
	testl	%r9d, %r9d
	jle	.L13
	leal	(%rcx,%rcx,8), %eax
	cltq
	leaq	-1(%r8,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L13:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L24:
	.cfi_restore 3
	leal	9(%rdi,%rdi,8), %eax
	cltq
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L26:
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movslq	%r10d, %rdx
	movslq	(%rax,%rdx,4), %r11
	movq	%r11, %rbx
	addq	%r8, %r11
	subl	$2, %edi
	jne	.L27
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r11, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L17:
	testl	%ebx, %ebx
	jle	.L18
	leal	(%r10,%r10,8), %eax
	cltq
	leaq	-1(%r11,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L27:
	movq	%r11, %rsi
	call	solve.part.0
	jmp	.L17
	.cfi_endproc
.LFE23:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	(%rsp), %rcx
	movabsq	$7378697629483820647, %rdi
	leaq	160(%rsi), %r8
	.p2align 4,,10
	.p2align 3
.L29:
	movq	%rcx, %rax
	addq	$4, %rsi
	imulq	%rdi
	movq	%rcx, %rax
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movl	%ecx, -4(%rsi)
	movq	%rdx, %rcx
	cmpq	%r8, %rsi
	jne	.L29
	xorl	%esi, %esi
	movl	$40, %edi
	movq	%rdx, (%rsp)
	call	solve.part.0
	movq	ans(%rip), %rdx
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	m
	.bss
	.align 32
	.type	m, @object
	.size	m, 164
m:
	.zero	164
	.globl	ans
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.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	solve.part.0, @function
solve.part.0:
.LFB25:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%edi, %rdx
	leaq	m(%rip), %rax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %r13d
	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
	movq	%rdx, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	movslq	(%rax,%rdx,4), %rbp
	movq	%rbp, %r12
	addq	%rsi, %rbp
	subl	$1, %r13d
	jne	.L9
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%rbp, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L5:
	testl	%r12d, %r12d
	jle	.L1
	leal	(%rbx,%rbx,8), %eax
	cltq
	leaq	-1(%rbp,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L1:
	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
	.p2align 4,,10
	.p2align 3
.L9:
	.cfi_restore_state
	movslq	%r13d, %rdx
	movl	%ebx, %edi
	movslq	(%rax,%rdx,4), %r14
	movq	%r14, %r15
	addq	%rbp, %r14
	subl	$2, %edi
	jne	.L10
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r14, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L4:
	testl	%r15d, %r15d
	jle	.L5
	leal	0(%r13,%r13,8), %eax
	cltq
	leaq	-1(%r14,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r14, %rsi
	call	solve.part.0
	jmp	.L4
	.cfi_endproc
.LFE25:
	.size	solve.part.0, .-solve.part.0
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %ecx
	testl	%esi, %esi
	je	.L24
	movslq	m(%rip), %rax
	testl	%edi, %edi
	jne	.L25
.L23:
	addq	%rdx, %rax
	movq	ans(%rip), %rdx
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L25:
	leaq	m(%rip), %rax
	movslq	%edi, %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %r10d
	movslq	(%rax,%rsi,4), %rsi
	movq	%rsi, %r9
	leaq	(%rsi,%rdx), %r8
	subl	$1, %r10d
	jne	.L26
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r8, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L18:
	testl	%r9d, %r9d
	jle	.L13
	leal	(%rcx,%rcx,8), %eax
	cltq
	leaq	-1(%r8,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L13:
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L24:
	.cfi_restore 3
	leal	9(%rdi,%rdi,8), %eax
	cltq
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L26:
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movslq	%r10d, %rdx
	movslq	(%rax,%rdx,4), %r11
	movq	%r11, %rbx
	addq	%r8, %r11
	subl	$2, %edi
	jne	.L27
	movslq	m(%rip), %rax
	movq	ans(%rip), %rdx
	addq	%r11, %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
.L17:
	testl	%ebx, %ebx
	jle	.L18
	leal	(%r10,%r10,8), %eax
	cltq
	leaq	-1(%r11,%rax), %rdx
	movq	ans(%rip), %rax
	cmpq	%rdx, %rax
	cmovl	%rdx, %rax
	movq	%rax, ans(%rip)
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L27:
	movq	%r11, %rsi
	call	solve.part.0
	jmp	.L17
	.cfi_endproc
.LFE23:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	(%rsp), %rcx
	movabsq	$7378697629483820647, %rdi
	leaq	160(%rsi), %r8
	.p2align 4,,10
	.p2align 3
.L29:
	movq	%rcx, %rax
	addq	$4, %rsi
	imulq	%rdi
	movq	%rcx, %rax
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movl	%ecx, -4(%rsi)
	movq	%rdx, %rcx
	cmpq	%r8, %rsi
	jne	.L29
	xorl	%esi, %esi
	movl	$40, %edi
	movq	%rdx, (%rsp)
	call	solve.part.0
	movq	ans(%rip), %rdx
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	m
	.bss
	.align 32
	.type	m, @object
	.size	m, 164
m:
	.zero	164
	.globl	ans
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.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 max(a,b) ((a)>(b)?(a):(b))

long long ans;
int m[41];

int solve(int kt,int hn,long long then){
	//printf("%lld\n",ans);
	if(hn==0){
		ans=max(ans,then+9*(kt+1));
		return 0;
	}else{
		if(kt!=0){
			solve(kt-1,1,then+m[kt]);
			if(m[kt]>0)solve(kt-1,0,then+m[kt]-1);
			return 0;
		}else {
			ans=max(ans,then+m[kt]);
			return 0;
		}
	}
}

int main(){
	int i;
	long long n;
	scanf("%lld",&n);
	for(i=0;i<40;i++){
		m[i]=n%10;
		n/=10;
	}
	solve(40,1,0);
	printf("%lld\n",ans);
	return 0;
}
1265641936938969
 101
 613
 1180
 2005985506723837
 78
 813322357948504
 127248513971408
 46390584841058
 51

135
 18
 23
 27
 136
 15
 133
 126
 120
 13

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 max(a,b) ((a)>(b)?(a):(b))

long long ans;
int m[41];

int solve(int kt,int hn,long long then){
	//printf("%lld\n",ans);
	if(hn==0){
		ans=max(ans,then+9*(kt+1));
		return 0;
	}else{
		if(kt!=0){
			solve(kt-1,1,then+m[kt]);
			if(m[kt]>0)solve(kt-1,0,then+m[kt]-1);
			return 0;
		}else {
			ans=max(ans,then+m[kt]);
			return 0;
		}
	}
}

int main(){
	int i;
	long long n;
	scanf("%lld",&n);
	for(i=0;i<40;i++){
		m[i]=n%10;
		n/=10;
	}
	solve(40,1,0);
	printf("%lld\n",ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 164
m:
	.zero	164
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movq	%rdx, -16(%rbp)
	cmpl	$0, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
	jmp	.L3
.L2:
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$1, %esi
	movl	%eax, %edi
	call	solve
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	leaq	-1(%rax), %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	solve
.L5:
	movl	$0, %eax
	jmp	.L3
.L4:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L7
.L8:
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	movq	%rcx, %rsi
	sarq	$63, %rsi
	subq	%rsi, %rax
	movq	%rax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rcx, %rdx
	movl	%edx, %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	sarq	$63, %rcx
	movq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, -16(%rbp)
	addl	$1, -20(%rbp)
.L7:
	cmpl	$39, -20(%rbp)
	jle	.L8
	movl	$0, %edx
	movl	$1, %esi
	movl	$40, %edi
	call	solve
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.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	ans
	.bss
	.align 8
	.type	ans, @object
	.size	ans, 8
ans:
	.zero	8
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 164
m:
	.zero	164
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movq	%rdx, -16(%rbp)
	cmpl	$0, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
	jmp	.L3
.L2:
	cmpl	$0, -4(%rbp)
	je	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$1, %esi
	movl	%eax, %edi
	call	solve
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jle	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	leaq	-1(%rax), %rdx
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	solve
.L5:
	movl	$0, %eax
	jmp	.L3
.L4:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	(%rdx,%rax), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movq	ans(%rip), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, ans(%rip)
	movl	$0, %eax
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L7
.L8:
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	movq	%rcx, %rsi
	sarq	$63, %rsi
	subq	%rsi, %rax
	movq	%rax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rcx, %rdx
	movl	%edx, %ecx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	m(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movq	-16(%rbp), %rcx
	movabsq	$7378697629483820647, %rdx
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	sarq	$2, %rax
	sarq	$63, %rcx
	movq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, -16(%rbp)
	addl	$1, -20(%rbp)
.L7:
	cmpl	$39, -20(%rbp)
	jle	.L8
	movl	$0, %edx
	movl	$1, %esi
	movl	$40, %edi
	call	solve
	movq	ans(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L10
	call	__stack_chk_fail@PLT
.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:
