Given the following C code and assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
int S(long int x){
	int r=0;
	while(x>0){r+=x%10;x/=10;}
	return r;
}

int main(){
  long int n,i,j,x=1,y,r,s;
  double m,o;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    printf("%ld\n",x);
    r=++x;
  	m=(double)x/S(x);
  	for(j=0,s=10;j<15;j++,s*=10L){
  		y=s*(x/s+1)-1;o=(double)y/S(y);
  		if(o<m){m=o;r=y;}
  	}
    x=r;
  }
}
```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	S
	.type	S, @function
S:
.LFB23:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	jle	.L1
	movabsq	$-3689348814741910323, %rsi
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdi, %rax
	movq	%rdi, %rcx
	mulq	%rsi
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rdi, %rax
	movq	%rdx, %rdi
	addl	%ecx, %r8d
	cmpq	$9, %rax
	jg	.L3
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	S, .-S
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L8
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %rbx
	movabsq	$-3689348814741910323, %rbp
.L14:
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	1(%r12), %r10
	pxor	%xmm1, %xmm1
	xorl	%esi, %esi
	cvtsi2sdq	%r10, %xmm1
	movq	%r10, %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L9
	pxor	%xmm0, %xmm0
	movq	%r10, %r12
	movl	$15, %r9d
	movl	$10, %r8d
	cvtsi2sdl	%esi, %xmm0
	divsd	%xmm0, %xmm1
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r10, %rax
	pxor	%xmm0, %xmm0
	xorl	%esi, %esi
	cqto
	idivq	%r8
	addq	$1, %rax
	imulq	%r8, %rax
	leaq	-1(%rax), %rdi
	cvtsi2sdq	%rdi, %xmm0
	movq	%rdi, %rcx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L10
	pxor	%xmm2, %xmm2
	leaq	(%r8,%r8,4), %r8
	cvtsi2sdl	%esi, %xmm2
	divsd	%xmm2, %xmm0
	comisd	%xmm0, %xmm1
	minsd	%xmm1, %xmm0
	cmova	%rdi, %r12
	movapd	%xmm0, %xmm1
	addq	%r8, %r8
	subq	$1, %r9
	jne	.L13
	addq	$1, %r13
	cmpq	%r13, (%rsp)
	jg	.L14
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	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
.L22:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	S
	.type	S, @function
S:
.LFB23:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	jle	.L1
	movabsq	$-3689348814741910323, %rsi
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdi, %rax
	movq	%rdi, %rcx
	mulq	%rsi
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rdi, %rax
	movq	%rdx, %rdi
	addl	%ecx, %r8d
	cmpq	$9, %rax
	jg	.L3
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	S, .-S
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L8
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %rbx
	movabsq	$-3689348814741910323, %rbp
.L14:
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	1(%r12), %r10
	pxor	%xmm1, %xmm1
	xorl	%esi, %esi
	cvtsi2sdq	%r10, %xmm1
	movq	%r10, %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L9
	pxor	%xmm0, %xmm0
	movq	%r10, %r12
	movl	$15, %r9d
	movl	$10, %r8d
	cvtsi2sdl	%esi, %xmm0
	divsd	%xmm0, %xmm1
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r10, %rax
	pxor	%xmm0, %xmm0
	xorl	%esi, %esi
	cqto
	idivq	%r8
	addq	$1, %rax
	imulq	%r8, %rax
	leaq	-1(%rax), %rdi
	cvtsi2sdq	%rdi, %xmm0
	movq	%rdi, %rcx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L10
	pxor	%xmm2, %xmm2
	leaq	(%r8,%r8,4), %r8
	cvtsi2sdl	%esi, %xmm2
	divsd	%xmm2, %xmm0
	comisd	%xmm0, %xmm1
	minsd	%xmm1, %xmm0
	cmova	%rdi, %r12
	movapd	%xmm0, %xmm1
	addq	%r8, %r8
	subq	$1, %r9
	jne	.L13
	addq	$1, %r13
	cmpq	%r13, (%rsp)
	jg	.L14
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	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
.L22:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	S
	.type	S, @function
S:
.LFB23:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	jle	.L1
	movabsq	$-3689348814741910323, %rsi
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdi, %rax
	movq	%rdi, %rcx
	mulq	%rsi
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rdi, %rax
	movq	%rdx, %rdi
	addl	%ecx, %r8d
	cmpq	$9, %rax
	jg	.L3
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	S, .-S
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L8
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %rbx
	movabsq	$-3689348814741910323, %rbp
.L14:
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	1(%r12), %r10
	pxor	%xmm1, %xmm1
	xorl	%esi, %esi
	cvtsi2sdq	%r10, %xmm1
	movq	%r10, %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L9
	pxor	%xmm0, %xmm0
	movq	%r10, %r12
	movl	$15, %r9d
	movl	$10, %r8d
	cvtsi2sdl	%esi, %xmm0
	divsd	%xmm0, %xmm1
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r10, %rax
	pxor	%xmm0, %xmm0
	xorl	%esi, %esi
	cqto
	idivq	%r8
	addq	$1, %rax
	imulq	%r8, %rax
	leaq	-1(%rax), %rdi
	cvtsi2sdq	%rdi, %xmm0
	movq	%rdi, %rcx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L10
	pxor	%xmm2, %xmm2
	leaq	(%r8,%r8,4), %r8
	cvtsi2sdl	%esi, %xmm2
	divsd	%xmm2, %xmm0
	comisd	%xmm0, %xmm1
	minsd	%xmm1, %xmm0
	cmova	%rdi, %r12
	movapd	%xmm0, %xmm1
	addq	%r8, %r8
	subq	$1, %r9
	jne	.L13
	addq	$1, %r13
	cmpq	%r13, (%rsp)
	jg	.L14
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	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
.L22:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:
```
```c
#include<stdio.h>
int S(long int x){
	int r=0;
	while(x>0){r+=x%10;x/=10;}
	return r;
}

int main(){
  long int n,i,j,x=1,y,r,s;
  double m,o;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    printf("%ld\n",x);
    r=++x;
  	m=(double)x/S(x);
  	for(j=0,s=10;j<15;j++,s*=10L){
  		y=s*(x/s+1)-1;o=(double)y/S(y);
  		if(o<m){m=o;r=y;}
  	}
    x=r;
  }
}
```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
int S(long int x){
	int r=0;
	while(x>0){r+=x%10;x/=10;}
	return r;
}

int main(){
  long int n,i,j,x=1,y,r,s;
  double m,o;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    printf("%ld\n",x);
    r=++x;
  	m=(double)x/S(x);
  	for(j=0,s=10;j<15;j++,s*=10L){
  		y=s*(x/s+1)-1;o=(double)y/S(y);
  		if(o<m){m=o;r=y;}
  	}
    x=r;
  }
}
```

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.
Optimized Assembly Code:

18
 7
 5
 8
 2
 6
 15
 4
 1
 11

1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
79
89
99
 1
2
3
4
5
6
7
 1
2
3
4
5
 1
2
3
4
5
6
7
8
 1
2
 1
2
3
4
5
6
 1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
 1
2
3
4
 1
 1
2
3
4
5
6
7
8
9
19
29

Given the following C code and assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
int S(long int x){
	int r=0;
	while(x>0){r+=x%10;x/=10;}
	return r;
}

int main(){
  long int n,i,j,x=1,y,r,s;
  double m,o;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    printf("%ld\n",x);
    r=++x;
  	m=(double)x/S(x);
  	for(j=0,s=10;j<15;j++,s*=10L){
  		y=s*(x/s+1)-1;o=(double)y/S(y);
  		if(o<m){m=o;r=y;}
  	}
    x=r;
  }
}
```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	S
	.type	S, @function
S:
.LFB23:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	jle	.L1
	movabsq	$-3689348814741910323, %rsi
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdi, %rax
	movq	%rdi, %rcx
	mulq	%rsi
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rdi, %rax
	movq	%rdx, %rdi
	addl	%ecx, %r8d
	cmpq	$9, %rax
	jg	.L3
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	S, .-S
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L8
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %rbx
	movabsq	$-3689348814741910323, %rbp
.L14:
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	1(%r12), %r10
	pxor	%xmm1, %xmm1
	xorl	%esi, %esi
	cvtsi2sdq	%r10, %xmm1
	movq	%r10, %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L9
	pxor	%xmm0, %xmm0
	movq	%r10, %r12
	movl	$15, %r9d
	movl	$10, %r8d
	cvtsi2sdl	%esi, %xmm0
	divsd	%xmm0, %xmm1
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r10, %rax
	pxor	%xmm0, %xmm0
	xorl	%esi, %esi
	cqto
	idivq	%r8
	addq	$1, %rax
	imulq	%r8, %rax
	leaq	-1(%rax), %rdi
	cvtsi2sdq	%rdi, %xmm0
	movq	%rdi, %rcx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L10
	pxor	%xmm2, %xmm2
	leaq	(%r8,%r8,4), %r8
	cvtsi2sdl	%esi, %xmm2
	divsd	%xmm2, %xmm0
	comisd	%xmm0, %xmm1
	minsd	%xmm1, %xmm0
	cmova	%rdi, %r12
	movapd	%xmm0, %xmm1
	addq	%r8, %r8
	subq	$1, %r9
	jne	.L13
	addq	$1, %r13
	cmpq	%r13, (%rsp)
	jg	.L14
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	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
.L22:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	S
	.type	S, @function
S:
.LFB23:
	.cfi_startproc
	endbr64
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	jle	.L1
	movabsq	$-3689348814741910323, %rsi
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdi, %rax
	movq	%rdi, %rcx
	mulq	%rsi
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	movq	%rdi, %rax
	movq	%rdx, %rdi
	addl	%ecx, %r8d
	cmpq	$9, %rax
	jg	.L3
.L1:
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	S, .-S
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, (%rsp)
	jle	.L8
	movl	$1, %r12d
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %rbx
	movabsq	$-3689348814741910323, %rbp
.L14:
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	1(%r12), %r10
	pxor	%xmm1, %xmm1
	xorl	%esi, %esi
	cvtsi2sdq	%r10, %xmm1
	movq	%r10, %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L9
	pxor	%xmm0, %xmm0
	movq	%r10, %r12
	movl	$15, %r9d
	movl	$10, %r8d
	cvtsi2sdl	%esi, %xmm0
	divsd	%xmm0, %xmm1
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r10, %rax
	pxor	%xmm0, %xmm0
	xorl	%esi, %esi
	cqto
	idivq	%r8
	addq	$1, %rax
	imulq	%r8, %rax
	leaq	-1(%rax), %rdi
	cvtsi2sdq	%rdi, %xmm0
	movq	%rdi, %rcx
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rcx, %rax
	mulq	%rbp
	shrq	$3, %rdx
	leaq	(%rdx,%rdx,4), %rax
	addq	%rax, %rax
	subq	%rax, %rcx
	addl	%ecx, %esi
	movq	%rdx, %rcx
	testq	%rdx, %rdx
	jne	.L10
	pxor	%xmm2, %xmm2
	leaq	(%r8,%r8,4), %r8
	cvtsi2sdl	%esi, %xmm2
	divsd	%xmm2, %xmm0
	comisd	%xmm0, %xmm1
	minsd	%xmm1, %xmm0
	cmova	%rdi, %r12
	movapd	%xmm0, %xmm1
	addq	%r8, %r8
	subq	$1, %r9
	jne	.L13
	addq	$1, %r13
	cmpq	%r13, (%rsp)
	jg	.L14
.L8:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	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
.L22:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:
```