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<stdlib.h>

int main(){

int ans=0;
long N;
scanf("%ld",&N);

int digit[17];
for (int i = 16; i >= 0; i--){
  digit[i]=N%10;
  N/=10;
}

int s;
for (int i = 0; i < 17; i++){
  if (digit[i]!=0){
    s=i;
    break;
  }
}

ans=digit[s];
for (int i = s+1; i < 17; i++)
{
  if (digit[i]==9){
    ans+=9;
  }else{
    ans += (16-i+1)*9-1;
    break;
  }
} 

printf("%d",ans);

return 0;

}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -108(%rbp)
	leaq	-88(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$16, -104(%rbp)
	jmp	.L2
.L3:
	movq	-88(%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	-104(%rbp), %eax
	cltq
	movl	%edx, -80(%rbp,%rax,4)
	movq	-88(%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, -88(%rbp)
	subl	$1, -104(%rbp)
.L2:
	cmpl	$0, -104(%rbp)
	jns	.L3
	movl	$0, -96(%rbp)
	jmp	.L4
.L7:
	movl	-96(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L5
	movl	-96(%rbp), %eax
	movl	%eax, -100(%rbp)
	jmp	.L6
.L5:
	addl	$1, -96(%rbp)
.L4:
	cmpl	$16, -96(%rbp)
	jle	.L7
.L6:
	movl	-100(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, -108(%rbp)
	movl	-100(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -92(%rbp)
	jmp	.L8
.L12:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	cmpl	$9, %eax
	jne	.L9
	addl	$9, -108(%rbp)
	jmp	.L15
.L9:
	movl	$17, %eax
	subl	-92(%rbp), %eax
	movl	%eax, %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	subl	$1, %eax
	addl	%eax, -108(%rbp)
	jmp	.L11
.L15:
	addl	$1, -92(%rbp)
.L8:
	cmpl	$16, -92(%rbp)
	jle	.L12
.L11:
	movl	-108(%rbp), %eax
	movl	%eax, %esi
	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	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movq	56(%rsp), %rsi
	movabsq	$7378697629483820647, %rcx
	movq	%rsi, %rax
	imulq	%rcx
	movq	%rsi, %rax
	sarq	$63, %rax
	sarq	$2, %rdx
	movq	%rdx, %rbx
	subq	%rax, %rbx
	leaq	(%rbx,%rbx,4), %rax
	movq	%rbx, %rdi
	movq	%rsi, %rbx
	addq	%rax, %rax
	subq	%rax, %rbx
	movq	%rdi, %rax
	imulq	%rcx
	movq	%rdi, %rax
	movl	%ebx, 128(%rsp)
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rsi, %rax
	movl	%edi, 124(%rsp)
	movq	%rdi, %r14
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rdi, %rax
	movl	%esi, 120(%rsp)
	movq	%rsi, %r13
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rsi, %rax
	movq	%rdi, %r10
	sarq	$63, %rax
	movd	%r10d, %xmm2
	movq	%r10, 40(%rsp)
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, 32(%rsp)
	movq	%rdi, %rsi
	sarq	$63, %rsi
	punpckldq	%xmm2, %xmm0
	movq	%xmm0, 112(%rsp)
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%edi, 108(%rsp)
	movq	%rdi, %r12
	movq	%rsi, %rdi
	sarq	$63, %rdi
	sarq	$2, %rdx
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%esi, 104(%rsp)
	movq	%rsi, %rbp
	movq	%rdi, %rsi
	sarq	$63, %rsi
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rdi, %r11
	movq	%rsi, %rdi
	sarq	$63, %rdi
	movd	%r11d, %xmm3
	movq	%r11, 24(%rsp)
	sarq	$2, %rdx
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, 16(%rsp)
	movq	%rdi, %rsi
	sarq	$63, %rsi
	punpckldq	%xmm3, %xmm0
	movq	%xmm0, 96(%rsp)
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%edi, 92(%rsp)
	movq	%rdi, %r11
	movq	%rsi, %rdi
	sarq	$2, %rdx
	sarq	$63, %rdi
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%esi, 88(%rsp)
	movq	%rsi, %r10
	movq	%rdi, %rsi
	sarq	$63, %rsi
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%edi, %xmm4
	movq	%rdi, 8(%rsp)
	movq	%rdx, %r9
	movq	%rsi, %rdx
	sarq	$63, %rdx
	sarq	$2, %r9
	subq	%rdx, %r9
	leaq	(%r9,%r9,4), %rax
	movq	%r9, %r15
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%r15, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, %r9
	punpckldq	%xmm4, %xmm0
	movq	%xmm0, 80(%rsp)
	movq	%rdx, %rsi
	movq	%r15, %rdx
	sarq	$63, %rdx
	sarq	$2, %rsi
	subq	%rdx, %rsi
	movq	%rsi, %rax
	imulq	%rcx
	movq	%rdx, %rdi
	movq	%rsi, %rdx
	sarq	$63, %rdx
	sarq	$2, %rdi
	subq	%rdx, %rdi
	movq	%rdi, %rax
	imulq	%rcx
	movq	%rdx, %r8
	movq	%rdi, %rdx
	sarq	$63, %rdx
	sarq	$2, %r8
	subq	%rdx, %r8
	movq	%r8, %rax
	imulq	%rcx
	movq	%rdx, %rcx
	movq	%r8, %rdx
	sarq	$63, %rdx
	sarq	$2, %rcx
	subq	%rdx, %rcx
	movq	%r8, %rdx
	leaq	(%rcx,%rcx,4), %rax
	movq	%rcx, 56(%rsp)
	addq	%rax, %rax
	subq	%rax, %rdx
	leaq	(%r8,%r8,4), %rax
	movq	%rdx, %xmm0
	addq	%rax, %rax
	movq	%rdi, %rdx
	subq	%rax, %rdx
	leaq	(%rdi,%rdi,4), %rax
	movq	%rdx, %xmm5
	addq	%rax, %rax
	movq	%rsi, %rdx
	subq	%rax, %rdx
	leaq	(%rsi,%rsi,4), %rax
	punpcklqdq	%xmm5, %xmm0
	addq	%rax, %rax
	movq	%rdx, %xmm1
	subq	%rax, %r15
	movq	%r15, %xmm6
	punpcklqdq	%xmm6, %xmm1
	shufps	$136, %xmm1, %xmm0
	pshufd	$255, %xmm0, %xmm1
	movd	%xmm0, %ecx
	movaps	%xmm0, 64(%rsp)
	movd	%xmm1, %esi
	movdqa	%xmm0, %xmm1
	punpckhdq	%xmm0, %xmm1
	movd	%xmm1, %edx
	pshufd	$85, %xmm0, %xmm1
	testl	%ecx, %ecx
	jne	.L9
	movd	%xmm1, %eax
	testl	%eax, %eax
	jne	.L10
	testl	%edx, %edx
	jne	.L11
	testl	%esi, %esi
	jne	.L12
	testq	%r9, %r9
	jne	.L13
	cmpq	$0, 8(%rsp)
	jne	.L14
	testq	%r10, %r10
	jne	.L15
	testq	%r11, %r11
	jne	.L16
	cmpq	$0, 16(%rsp)
	jne	.L17
	cmpq	$0, 24(%rsp)
	jne	.L18
	testq	%rbp, %rbp
	jne	.L19
	testq	%r12, %r12
	jne	.L20
	cmpq	$0, 32(%rsp)
	jne	.L21
	cmpq	$0, 40(%rsp)
	jne	.L22
	testq	%r13, %r13
	jne	.L23
	testq	%r14, %r14
	jne	.L24
	testq	%rbx, %rbx
	jne	.L3
	movl	64(%rsp), %r8d
	movl	$1, %eax
.L7:
	movslq	%eax, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L25
	leal	9(%r8), %esi
	leal	1(%rax), %ecx
	cmpl	$16, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	18(%r8), %esi
	leal	2(%rax), %ecx
	cmpl	$15, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	27(%r8), %esi
	leal	3(%rax), %ecx
	cmpl	$14, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	36(%r8), %esi
	leal	4(%rax), %ecx
	cmpl	$13, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	45(%r8), %esi
	leal	5(%rax), %ecx
	cmpl	$12, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	54(%r8), %esi
	leal	6(%rax), %ecx
	cmpl	$11, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	63(%r8), %esi
	leal	7(%rax), %ecx
	cmpl	$10, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	72(%r8), %esi
	leal	8(%rax), %ecx
	cmpl	$9, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	81(%r8), %esi
	leal	9(%rax), %ecx
	cmpl	$8, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	90(%r8), %esi
	leal	10(%rax), %ecx
	cmpl	$7, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	99(%r8), %esi
	leal	11(%rax), %ecx
	cmpl	$6, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	108(%r8), %esi
	leal	12(%rax), %ecx
	cmpl	$5, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	117(%r8), %esi
	leal	13(%rax), %ecx
	cmpl	$4, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	126(%r8), %esi
	leal	14(%rax), %ecx
	cmpl	$3, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	subl	$1, %eax
	leal	135(%r8), %esi
	jne	.L6
	cmpq	$9, %rbx
	jne	.L26
	leal	144(%r8), %esi
.L6:
	movl	%esi, %r8d
.L4:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L75
	addq	$152, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L25:
	.cfi_restore_state
	movl	%r8d, %esi
	movl	%eax, %ecx
.L5:
	movl	$17, %eax
	subl	%ecx, %eax
	leal	(%rax,%rax,8), %eax
	leal	-1(%rsi,%rax), %r8d
	jmp	.L4
.L9:
	xorl	%eax, %eax
.L2:
	movslq	%eax, %rdx
	addl	$1, %eax
	movl	64(%rsp,%rdx,4), %r8d
	jmp	.L7
.L10:
	movl	$1, %eax
	jmp	.L2
.L21:
	movl	$12, %eax
	jmp	.L2
.L11:
	movl	$2, %eax
	jmp	.L2
.L12:
	movl	$3, %eax
	jmp	.L2
.L13:
	movl	$4, %eax
	jmp	.L2
.L14:
	movl	$5, %eax
	jmp	.L2
.L15:
	movl	$6, %eax
	jmp	.L2
.L16:
	movl	$7, %eax
	jmp	.L2
.L17:
	movl	$8, %eax
	jmp	.L2
.L18:
	movl	$9, %eax
	jmp	.L2
.L19:
	movl	$10, %eax
	jmp	.L2
.L20:
	movl	$11, %eax
	jmp	.L2
.L22:
	movl	$13, %eax
	jmp	.L2
.L23:
	movl	$14, %eax
	jmp	.L2
.L24:
	movl	$15, %eax
	jmp	.L2
.L3:
	movl	128(%rsp), %r8d
	jmp	.L4
.L26:
	movl	$16, %ecx
	jmp	.L5
.L75:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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:

rule
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movq	56(%rsp), %rsi
	movabsq	$7378697629483820647, %rcx
	movq	%rsi, %rax
	imulq	%rcx
	movq	%rsi, %rax
	sarq	$63, %rax
	sarq	$2, %rdx
	movq	%rdx, %rbx
	subq	%rax, %rbx
	leaq	(%rbx,%rbx,4), %rax
	movq	%rbx, %rdi
	movq	%rsi, %rbx
	addq	%rax, %rax
	subq	%rax, %rbx
	movq	%rdi, %rax
	imulq	%rcx
	movq	%rdi, %rax
	movl	%ebx, 128(%rsp)
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rsi, %rax
	movl	%edi, 124(%rsp)
	movq	%rdi, %r14
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rdi, %rax
	movl	%esi, 120(%rsp)
	movq	%rsi, %r13
	sarq	$63, %rax
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rsi, %rax
	movq	%rdi, %r10
	sarq	$63, %rax
	movd	%r10d, %xmm2
	movq	%r10, 40(%rsp)
	sarq	$2, %rdx
	subq	%rax, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, 32(%rsp)
	movq	%rdi, %rsi
	sarq	$63, %rsi
	punpckldq	%xmm2, %xmm0
	movq	%xmm0, 112(%rsp)
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%edi, 108(%rsp)
	movq	%rdi, %r12
	movq	%rsi, %rdi
	sarq	$63, %rdi
	sarq	$2, %rdx
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%esi, 104(%rsp)
	movq	%rsi, %rbp
	movq	%rdi, %rsi
	sarq	$63, %rsi
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movq	%rdi, %r11
	movq	%rsi, %rdi
	sarq	$63, %rdi
	movd	%r11d, %xmm3
	movq	%r11, 24(%rsp)
	sarq	$2, %rdx
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, 16(%rsp)
	movq	%rdi, %rsi
	sarq	$63, %rsi
	punpckldq	%xmm3, %xmm0
	movq	%xmm0, 96(%rsp)
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%edi, 92(%rsp)
	movq	%rdi, %r11
	movq	%rsi, %rdi
	sarq	$2, %rdx
	sarq	$63, %rdi
	subq	%rdi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rdi
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%rdx, %rax
	imulq	%rcx
	movl	%esi, 88(%rsp)
	movq	%rsi, %r10
	movq	%rdi, %rsi
	sarq	$63, %rsi
	sarq	$2, %rdx
	subq	%rsi, %rdx
	leaq	(%rdx,%rdx,4), %rax
	movq	%rdx, %rsi
	addq	%rax, %rax
	subq	%rax, %rdi
	movq	%rdx, %rax
	imulq	%rcx
	movd	%edi, %xmm4
	movq	%rdi, 8(%rsp)
	movq	%rdx, %r9
	movq	%rsi, %rdx
	sarq	$63, %rdx
	sarq	$2, %r9
	subq	%rdx, %r9
	leaq	(%r9,%r9,4), %rax
	movq	%r9, %r15
	addq	%rax, %rax
	subq	%rax, %rsi
	movq	%r15, %rax
	imulq	%rcx
	movd	%esi, %xmm0
	movq	%rsi, %r9
	punpckldq	%xmm4, %xmm0
	movq	%xmm0, 80(%rsp)
	movq	%rdx, %rsi
	movq	%r15, %rdx
	sarq	$63, %rdx
	sarq	$2, %rsi
	subq	%rdx, %rsi
	movq	%rsi, %rax
	imulq	%rcx
	movq	%rdx, %rdi
	movq	%rsi, %rdx
	sarq	$63, %rdx
	sarq	$2, %rdi
	subq	%rdx, %rdi
	movq	%rdi, %rax
	imulq	%rcx
	movq	%rdx, %r8
	movq	%rdi, %rdx
	sarq	$63, %rdx
	sarq	$2, %r8
	subq	%rdx, %r8
	movq	%r8, %rax
	imulq	%rcx
	movq	%rdx, %rcx
	movq	%r8, %rdx
	sarq	$63, %rdx
	sarq	$2, %rcx
	subq	%rdx, %rcx
	movq	%r8, %rdx
	leaq	(%rcx,%rcx,4), %rax
	movq	%rcx, 56(%rsp)
	addq	%rax, %rax
	subq	%rax, %rdx
	leaq	(%r8,%r8,4), %rax
	movq	%rdx, %xmm0
	addq	%rax, %rax
	movq	%rdi, %rdx
	subq	%rax, %rdx
	leaq	(%rdi,%rdi,4), %rax
	movq	%rdx, %xmm5
	addq	%rax, %rax
	movq	%rsi, %rdx
	subq	%rax, %rdx
	leaq	(%rsi,%rsi,4), %rax
	punpcklqdq	%xmm5, %xmm0
	addq	%rax, %rax
	movq	%rdx, %xmm1
	subq	%rax, %r15
	movq	%r15, %xmm6
	punpcklqdq	%xmm6, %xmm1
	shufps	$136, %xmm1, %xmm0
	pshufd	$255, %xmm0, %xmm1
	movd	%xmm0, %ecx
	movaps	%xmm0, 64(%rsp)
	movd	%xmm1, %esi
	movdqa	%xmm0, %xmm1
	punpckhdq	%xmm0, %xmm1
	movd	%xmm1, %edx
	pshufd	$85, %xmm0, %xmm1
	testl	%ecx, %ecx
	jne	.L9
	movd	%xmm1, %eax
	testl	%eax, %eax
	jne	.L10
	testl	%edx, %edx
	jne	.L11
	testl	%esi, %esi
	jne	.L12
	testq	%r9, %r9
	jne	.L13
	cmpq	$0, 8(%rsp)
	jne	.L14
	testq	%r10, %r10
	jne	.L15
	testq	%r11, %r11
	jne	.L16
	cmpq	$0, 16(%rsp)
	jne	.L17
	cmpq	$0, 24(%rsp)
	jne	.L18
	testq	%rbp, %rbp
	jne	.L19
	testq	%r12, %r12
	jne	.L20
	cmpq	$0, 32(%rsp)
	jne	.L21
	cmpq	$0, 40(%rsp)
	jne	.L22
	testq	%r13, %r13
	jne	.L23
	testq	%r14, %r14
	jne	.L24
	testq	%rbx, %rbx
	jne	.L3
	movl	64(%rsp), %r8d
	movl	$1, %eax
.L7:
	movslq	%eax, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L25
	leal	9(%r8), %esi
	leal	1(%rax), %ecx
	cmpl	$16, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	18(%r8), %esi
	leal	2(%rax), %ecx
	cmpl	$15, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	27(%r8), %esi
	leal	3(%rax), %ecx
	cmpl	$14, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	36(%r8), %esi
	leal	4(%rax), %ecx
	cmpl	$13, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	45(%r8), %esi
	leal	5(%rax), %ecx
	cmpl	$12, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	54(%r8), %esi
	leal	6(%rax), %ecx
	cmpl	$11, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	63(%r8), %esi
	leal	7(%rax), %ecx
	cmpl	$10, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	72(%r8), %esi
	leal	8(%rax), %ecx
	cmpl	$9, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	81(%r8), %esi
	leal	9(%rax), %ecx
	cmpl	$8, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	90(%r8), %esi
	leal	10(%rax), %ecx
	cmpl	$7, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	99(%r8), %esi
	leal	11(%rax), %ecx
	cmpl	$6, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	108(%r8), %esi
	leal	12(%rax), %ecx
	cmpl	$5, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	117(%r8), %esi
	leal	13(%rax), %ecx
	cmpl	$4, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	leal	126(%r8), %esi
	leal	14(%rax), %ecx
	cmpl	$3, %eax
	je	.L6
	movslq	%ecx, %rdx
	cmpl	$9, 64(%rsp,%rdx,4)
	jne	.L5
	subl	$1, %eax
	leal	135(%r8), %esi
	jne	.L6
	cmpq	$9, %rbx
	jne	.L26
	leal	144(%r8), %esi
.L6:
	movl	%esi, %r8d
.L4:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L75
	addq	$152, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L25:
	.cfi_restore_state
	movl	%r8d, %esi
	movl	%eax, %ecx
.L5:
	movl	$17, %eax
	subl	%ecx, %eax
	leal	(%rax,%rax,8), %eax
	leal	-1(%rsi,%rax), %r8d
	jmp	.L4
.L9:
	xorl	%eax, %eax
.L2:
	movslq	%eax, %rdx
	addl	$1, %eax
	movl	64(%rsp,%rdx,4), %r8d
	jmp	.L7
.L10:
	movl	$1, %eax
	jmp	.L2
.L21:
	movl	$12, %eax
	jmp	.L2
.L11:
	movl	$2, %eax
	jmp	.L2
.L12:
	movl	$3, %eax
	jmp	.L2
.L13:
	movl	$4, %eax
	jmp	.L2
.L14:
	movl	$5, %eax
	jmp	.L2
.L15:
	movl	$6, %eax
	jmp	.L2
.L16:
	movl	$7, %eax
	jmp	.L2
.L17:
	movl	$8, %eax
	jmp	.L2
.L18:
	movl	$9, %eax
	jmp	.L2
.L19:
	movl	$10, %eax
	jmp	.L2
.L20:
	movl	$11, %eax
	jmp	.L2
.L22:
	movl	$13, %eax
	jmp	.L2
.L23:
	movl	$14, %eax
	jmp	.L2
.L24:
	movl	$15, %eax
	jmp	.L2
.L3:
	movl	128(%rsp), %r8d
	jmp	.L4
.L26:
	movl	$16, %ecx
	jmp	.L5
.L75:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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:

#include<stdio.h>
#include<stdlib.h>

int main(){

int ans=0;
long N;
scanf("%ld",&N);

int digit[17];
for (int i = 16; i >= 0; i--){
  digit[i]=N%10;
  N/=10;
}

int s;
for (int i = 0; i < 17; i++){
  if (digit[i]!=0){
    s=i;
    break;
  }
}

ans=digit[s];
for (int i = s+1; i < 17; i++)
{
  if (digit[i]==9){
    ans+=9;
  }else{
    ans += (16-i+1)*9-1;
    break;
  }
} 

printf("%d",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>
#include<stdlib.h>

int main(){

int ans=0;
long N;
scanf("%ld",&N);

int digit[17];
for (int i = 16; i >= 0; i--){
  digit[i]=N%10;
  N/=10;
}

int s;
for (int i = 0; i < 17; i++){
  if (digit[i]!=0){
    s=i;
    break;
  }
}

ans=digit[s];
for (int i = s+1; i < 17; i++)
{
  if (digit[i]==9){
    ans+=9;
  }else{
    ans += (16-i+1)*9-1;
    break;
  }
} 

printf("%d",ans);

return 0;

}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -108(%rbp)
	leaq	-88(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$16, -104(%rbp)
	jmp	.L2
.L3:
	movq	-88(%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	-104(%rbp), %eax
	cltq
	movl	%edx, -80(%rbp,%rax,4)
	movq	-88(%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, -88(%rbp)
	subl	$1, -104(%rbp)
.L2:
	cmpl	$0, -104(%rbp)
	jns	.L3
	movl	$0, -96(%rbp)
	jmp	.L4
.L7:
	movl	-96(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L5
	movl	-96(%rbp), %eax
	movl	%eax, -100(%rbp)
	jmp	.L6
.L5:
	addl	$1, -96(%rbp)
.L4:
	cmpl	$16, -96(%rbp)
	jle	.L7
.L6:
	movl	-100(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, -108(%rbp)
	movl	-100(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -92(%rbp)
	jmp	.L8
.L12:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	cmpl	$9, %eax
	jne	.L9
	addl	$9, -108(%rbp)
	jmp	.L15
.L9:
	movl	$17, %eax
	subl	-92(%rbp), %eax
	movl	%eax, %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	subl	$1, %eax
	addl	%eax, -108(%rbp)
	jmp	.L11
.L15:
	addl	$1, -92(%rbp)
.L8:
	cmpl	$16, -92(%rbp)
	jle	.L12
.L11:
	movl	-108(%rbp), %eax
	movl	%eax, %esi
	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	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$112, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -108(%rbp)
	leaq	-88(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$16, -104(%rbp)
	jmp	.L2
.L3:
	movq	-88(%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	-104(%rbp), %eax
	cltq
	movl	%edx, -80(%rbp,%rax,4)
	movq	-88(%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, -88(%rbp)
	subl	$1, -104(%rbp)
.L2:
	cmpl	$0, -104(%rbp)
	jns	.L3
	movl	$0, -96(%rbp)
	jmp	.L4
.L7:
	movl	-96(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	testl	%eax, %eax
	je	.L5
	movl	-96(%rbp), %eax
	movl	%eax, -100(%rbp)
	jmp	.L6
.L5:
	addl	$1, -96(%rbp)
.L4:
	cmpl	$16, -96(%rbp)
	jle	.L7
.L6:
	movl	-100(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	movl	%eax, -108(%rbp)
	movl	-100(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -92(%rbp)
	jmp	.L8
.L12:
	movl	-92(%rbp), %eax
	cltq
	movl	-80(%rbp,%rax,4), %eax
	cmpl	$9, %eax
	jne	.L9
	addl	$9, -108(%rbp)
	jmp	.L15
.L9:
	movl	$17, %eax
	subl	-92(%rbp), %eax
	movl	%eax, %edx
	movl	%edx, %eax
	sall	$3, %eax
	addl	%edx, %eax
	subl	$1, %eax
	addl	%eax, -108(%rbp)
	jmp	.L11
.L15:
	addl	$1, -92(%rbp)
.L8:
	cmpl	$16, -92(%rbp)
	jle	.L12
.L11:
	movl	-108(%rbp), %eax
	movl	%eax, %esi
	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	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
