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

```c
// AOJ 0504: Card Game II
// 2017.12.6 bal4u@uu

#include <stdio.h>
#include <string.h>

#define N 6
char ans[10015], *ap = ans+1;
int  d[10015];

void calc(int b, int n)
{
	int i, a;

	for (a = 1, i = 0; a > 0 && i <= n; i++) {
		d[i] += a / b, a %= b;
		a *= 10;
	}
}

int main()
{
	int n, k, m, r, i;
	
	while (scanf("%d%d%d%d", &n, &k, &m, &r) && n > 0) {
		r += N;

		memset(d, 0, sizeof(d));
		calc(n, r);
		if (m == 1) for (k = n, i = 1; i < n; i++, k+=n) calc(k, r);
		for (k = 0, i = r; i >= 0; i--) {
			k += d[i];
			ap[i] = '0' + k % 10;
			k /= 10;
		}
		ans[0] = ans[1], ans[1] = '.';
		ans[r-N+2] = 0;
		puts(ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 10015
ans:
	.zero	10015
	.globl	ap
	.section	.data.rel.local,"aw"
	.align 8
	.type	ap, @object
	.size	ap, 8
ap:
	.quad	ans+1
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 40060
d:
	.zero	40060
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	addl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	movl	%edx, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L2:
	cmpl	$0, -4(%rbp)
	jle	.L5
	movl	-8(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L4
.L5:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d%d%d"
	.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
	jmp	.L7
.L14:
	movl	-16(%rbp), %eax
	addl	$6, %eax
	movl	%eax, -16(%rbp)
	movl	$40060, %edx
	movl	$0, %esi
	leaq	d(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-16(%rbp), %edx
	movl	-28(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	movl	-20(%rbp), %eax
	cmpl	$1, %eax
	jne	.L8
	movl	-28(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	$1, -12(%rbp)
	jmp	.L9
.L10:
	movl	-16(%rbp), %edx
	movl	-24(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	addl	$1, -12(%rbp)
	movl	-24(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
.L9:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L10
.L8:
	movl	$0, -24(%rbp)
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L12:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-24(%rbp), %edx
	movslq	%edx, %rax
	imulq	$1717986919, %rax, %rax
	shrq	$32, %rax
	sarl	$2, %eax
	movl	%edx, %esi
	sarl	$31, %esi
	subl	%esi, %eax
	movl	%eax, %ecx
	movl	%ecx, %eax
	sall	$2, %eax
	addl	%ecx, %eax
	addl	%eax, %eax
	movl	%edx, %ecx
	subl	%eax, %ecx
	movl	%ecx, %eax
	leal	48(%rax), %ecx
	movq	ap(%rip), %rdx
	movl	-12(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movl	%ecx, %edx
	movb	%dl, (%rax)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1717986919, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$2, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -24(%rbp)
	subl	$1, -12(%rbp)
.L11:
	cmpl	$0, -12(%rbp)
	jns	.L12
	movzbl	1+ans(%rip), %eax
	movb	%al, ans(%rip)
	movb	$46, 1+ans(%rip)
	movl	-16(%rbp), %eax
	subl	$4, %eax
	cltq
	leaq	ans(%rip), %rdx
	movb	$0, (%rax,%rdx)
	leaq	ans(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	leaq	-16(%rbp), %rsi
	leaq	-20(%rbp), %rcx
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L13
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jg	.L14
.L13:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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
	.globl	calc
	.type	calc, @function
calc:
.LFB35:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	js	.L1
	movl	$1, %ecx
	movl	$1, %eax
	leaq	-4+d(%rip), %r8
	.p2align 4,,10
	.p2align 3
.L3:
	cltd
	idivl	%edi
	addl	%eax, (%r8,%rcx,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r9b
	cmpl	%ecx, %esi
	setge	%dl
	addq	$1, %rcx
	testb	%dl, %r9b
	jne	.L3
.L1:
	ret
	.cfi_endproc
.LFE35:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d%d%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	leaq	d(%rip), %rbx
	leaq	-4(%rbx), %r15
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	leaq	36(%rsp), %r14
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %r13
	leaq	28(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L7:
	movq	8(%rsp), %rsi
	xorl	%eax, %eax
	movq	%r14, %r8
	movq	%r13, %rcx
	movq	%r12, %rdx
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L17
	movl	24(%rsp), %ebp
	testl	%ebp, %ebp
	jle	.L17
	movl	36(%rsp), %eax
	movq	%rbx, %rdi
	movl	$40060, %edx
	xorl	%esi, %esi
	leal	6(%rax), %ecx
	movl	%ecx, 36(%rsp)
	movl	%ecx, 4(%rsp)
	call	memset@PLT
	movslq	4(%rsp), %rcx
	movl	32(%rsp), %edi
	testl	%ecx, %ecx
	js	.L8
	movl	$1, %esi
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L9:
	cltd
	idivl	%ebp
	addl	%eax, (%r15,%rsi,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r10b
	cmpl	%esi, %ecx
	setge	%dl
	addq	$1, %rsi
	testb	%dl, %r10b
	jne	.L9
	cmpl	$1, %edi
	je	.L41
.L20:
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L16:
	addl	(%rbx,%rcx,4), %eax
	movslq	%eax, %rdx
	movl	%eax, %esi
	movl	%eax, 28(%rsp)
	imulq	$1717986919, %rdx, %rdx
	sarl	$31, %esi
	sarq	$34, %rdx
	subl	%esi, %edx
	leal	(%rdx,%rdx,4), %edx
	addl	%edx, %edx
	subl	%edx, %eax
	movq	ap(%rip), %rdx
	addl	$48, %eax
	movb	%al, (%rdx,%rcx)
	movslq	28(%rsp), %rax
	subq	$1, %rcx
	movq	%rax, %rdx
	imulq	$1717986919, %rax, %rax
	sarl	$31, %edx
	sarq	$34, %rax
	subl	%edx, %eax
	movl	%eax, 28(%rsp)
	cmpl	$-1, %ecx
	jne	.L16
	movl	36(%rsp), %ecx
.L15:
	movzbl	1+ans(%rip), %eax
	subl	$4, %ecx
	leaq	ans(%rip), %rdi
	movb	$46, 1+ans(%rip)
	movslq	%ecx, %rcx
	movb	%al, ans(%rip)
	movb	$0, (%rdi,%rcx)
	call	puts@PLT
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L41:
	cmpl	$1, %ebp
	je	.L20
.L23:
	movl	%ebp, %edi
	movl	$1, %r10d
	.p2align 4,,10
	.p2align 3
.L12:
	movl	$1, %esi
	movl	$1, %eax
	testl	%ecx, %ecx
	js	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	cltd
	idivl	%edi
	addl	%eax, (%r15,%rsi,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r11b
	cmpl	%esi, %ecx
	setge	%dl
	addq	$1, %rsi
	testb	%dl, %r11b
	jne	.L11
.L14:
	addl	$1, %r10d
	addl	%ebp, %edi
	cmpl	%r10d, %ebp
	jne	.L12
	movl	$0, 28(%rsp)
	testl	%ecx, %ecx
	jns	.L20
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L17:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L42
	addq	$56, %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
.L8:
	.cfi_restore_state
	cmpl	$1, %edi
	je	.L43
.L39:
	movl	$0, 28(%rsp)
	jmp	.L15
.L43:
	cmpl	$1, %ebp
	jne	.L23
	jmp	.L39
.L42:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 40060
d:
	.zero	40060
	.globl	ap
	.section	.data.rel.local,"aw"
	.align 8
	.type	ap, @object
	.size	ap, 8
ap:
	.quad	ans+1
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 10015
ans:
	.zero	10015
	.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
	.globl	calc
	.type	calc, @function
calc:
.LFB35:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	js	.L1
	movl	$1, %ecx
	movl	$1, %eax
	leaq	-4+d(%rip), %r8
	.p2align 4,,10
	.p2align 3
.L3:
	cltd
	idivl	%edi
	addl	%eax, (%r8,%rcx,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r9b
	cmpl	%ecx, %esi
	setge	%dl
	addq	$1, %rcx
	testb	%dl, %r9b
	jne	.L3
.L1:
	ret
	.cfi_endproc
.LFE35:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d%d%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	leaq	d(%rip), %rbx
	leaq	-4(%rbx), %r15
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	leaq	36(%rsp), %r14
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %r13
	leaq	28(%rsp), %r12
	.p2align 4,,10
	.p2align 3
.L7:
	movq	8(%rsp), %rsi
	xorl	%eax, %eax
	movq	%r14, %r8
	movq	%r13, %rcx
	movq	%r12, %rdx
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L17
	movl	24(%rsp), %ebp
	testl	%ebp, %ebp
	jle	.L17
	movl	36(%rsp), %eax
	movq	%rbx, %rdi
	movl	$40060, %edx
	xorl	%esi, %esi
	leal	6(%rax), %ecx
	movl	%ecx, 36(%rsp)
	movl	%ecx, 4(%rsp)
	call	memset@PLT
	movslq	4(%rsp), %rcx
	movl	32(%rsp), %edi
	testl	%ecx, %ecx
	js	.L8
	movl	$1, %esi
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L9:
	cltd
	idivl	%ebp
	addl	%eax, (%r15,%rsi,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r10b
	cmpl	%esi, %ecx
	setge	%dl
	addq	$1, %rsi
	testb	%dl, %r10b
	jne	.L9
	cmpl	$1, %edi
	je	.L41
.L20:
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L16:
	addl	(%rbx,%rcx,4), %eax
	movslq	%eax, %rdx
	movl	%eax, %esi
	movl	%eax, 28(%rsp)
	imulq	$1717986919, %rdx, %rdx
	sarl	$31, %esi
	sarq	$34, %rdx
	subl	%esi, %edx
	leal	(%rdx,%rdx,4), %edx
	addl	%edx, %edx
	subl	%edx, %eax
	movq	ap(%rip), %rdx
	addl	$48, %eax
	movb	%al, (%rdx,%rcx)
	movslq	28(%rsp), %rax
	subq	$1, %rcx
	movq	%rax, %rdx
	imulq	$1717986919, %rax, %rax
	sarl	$31, %edx
	sarq	$34, %rax
	subl	%edx, %eax
	movl	%eax, 28(%rsp)
	cmpl	$-1, %ecx
	jne	.L16
	movl	36(%rsp), %ecx
.L15:
	movzbl	1+ans(%rip), %eax
	subl	$4, %ecx
	leaq	ans(%rip), %rdi
	movb	$46, 1+ans(%rip)
	movslq	%ecx, %rcx
	movb	%al, ans(%rip)
	movb	$0, (%rdi,%rcx)
	call	puts@PLT
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L41:
	cmpl	$1, %ebp
	je	.L20
.L23:
	movl	%ebp, %edi
	movl	$1, %r10d
	.p2align 4,,10
	.p2align 3
.L12:
	movl	$1, %esi
	movl	$1, %eax
	testl	%ecx, %ecx
	js	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	cltd
	idivl	%edi
	addl	%eax, (%r15,%rsi,4)
	leal	(%rdx,%rdx,4), %eax
	addl	%eax, %eax
	testl	%eax, %eax
	setg	%r11b
	cmpl	%esi, %ecx
	setge	%dl
	addq	$1, %rsi
	testb	%dl, %r11b
	jne	.L11
.L14:
	addl	$1, %r10d
	addl	%ebp, %edi
	cmpl	%r10d, %ebp
	jne	.L12
	movl	$0, 28(%rsp)
	testl	%ecx, %ecx
	jns	.L20
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L17:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L42
	addq	$56, %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
.L8:
	.cfi_restore_state
	cmpl	$1, %edi
	je	.L43
.L39:
	movl	$0, 28(%rsp)
	jmp	.L15
.L43:
	cmpl	$1, %ebp
	jne	.L23
	jmp	.L39
.L42:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 40060
d:
	.zero	40060
	.globl	ap
	.section	.data.rel.local,"aw"
	.align 8
	.type	ap, @object
	.size	ap, 8
ap:
	.quad	ans+1
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 10015
ans:
	.zero	10015
	.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:

// AOJ 0504: Card Game II
// 2017.12.6 bal4u@uu

#include <stdio.h>
#include <string.h>

#define N 6
char ans[10015], *ap = ans+1;
int  d[10015];

void calc(int b, int n)
{
	int i, a;

	for (a = 1, i = 0; a > 0 && i <= n; i++) {
		d[i] += a / b, a %= b;
		a *= 10;
	}
}

int main()
{
	int n, k, m, r, i;
	
	while (scanf("%d%d%d%d", &n, &k, &m, &r) && n > 0) {
		r += N;

		memset(d, 0, sizeof(d));
		calc(n, r);
		if (m == 1) for (k = n, i = 1; i < n; i++, k+=n) calc(k, r);
		for (k = 0, i = r; i >= 0; i--) {
			k += d[i];
			ap[i] = '0' + k % 10;
			k /= 10;
		}
		ans[0] = ans[1], ans[1] = '.';
		ans[r-N+2] = 0;
		puts(ans);
	}
	return 0;
}
2 1 0 5
3 1 2 3
2 2 1 3
0 0 0 0
 2 1 0 5
3 1 2 0
2 2 1 3
0 0 0 0
 2 1 0 5
3 1 2 6
2 2 1 3
0 0 0 0
 2 1 0 7
3 1 0 0
2 2 1 3
0 0 0 0
 2 1 0 1
2 1 0 0
2 2 1 3
0 0 0 0
 2 1 -1 5
4 1 2 0
2 2 1 3
0 0 0 0
 2 1 0 1
2 1 0 0
2 2 1 4
0 0 0 0
 2 1 0 5
4 1 -1 1
2 2 1 3
0 0 0 0
 2 1 0 1
2 1 -1 0
2 2 1 4
0 0 0 0
 2 1 0 1
4 1 -1 1
2 2 1 3
0 0 0 0

0.50000
0.333
1.000
 0.50000
0.
1.000
 0.50000
0.333333
1.000
 0.5000000
0.
1.000
 0.5
0.
1.000
 0.50000
0.
1.000
 0.5
0.
1.0000
 0.50000
0.2
1.000
 0.5
0.
1.0000
 0.5
0.2
1.000

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

```c
// AOJ 0504: Card Game II
// 2017.12.6 bal4u@uu

#include <stdio.h>
#include <string.h>

#define N 6
char ans[10015], *ap = ans+1;
int  d[10015];

void calc(int b, int n)
{
	int i, a;

	for (a = 1, i = 0; a > 0 && i <= n; i++) {
		d[i] += a / b, a %= b;
		a *= 10;
	}
}

int main()
{
	int n, k, m, r, i;
	
	while (scanf("%d%d%d%d", &n, &k, &m, &r) && n > 0) {
		r += N;

		memset(d, 0, sizeof(d));
		calc(n, r);
		if (m == 1) for (k = n, i = 1; i < n; i++, k+=n) calc(k, r);
		for (k = 0, i = r; i >= 0; i--) {
			k += d[i];
			ap[i] = '0' + k % 10;
			k /= 10;
		}
		ans[0] = ans[1], ans[1] = '.';
		ans[r-N+2] = 0;
		puts(ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 10015
ans:
	.zero	10015
	.globl	ap
	.section	.data.rel.local,"aw"
	.align 8
	.type	ap, @object
	.size	ap, 8
ap:
	.quad	ans+1
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 40060
d:
	.zero	40060
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	addl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	movl	%edx, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L2:
	cmpl	$0, -4(%rbp)
	jle	.L5
	movl	-8(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L4
.L5:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d%d%d"
	.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
	jmp	.L7
.L14:
	movl	-16(%rbp), %eax
	addl	$6, %eax
	movl	%eax, -16(%rbp)
	movl	$40060, %edx
	movl	$0, %esi
	leaq	d(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-16(%rbp), %edx
	movl	-28(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	movl	-20(%rbp), %eax
	cmpl	$1, %eax
	jne	.L8
	movl	-28(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	$1, -12(%rbp)
	jmp	.L9
.L10:
	movl	-16(%rbp), %edx
	movl	-24(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	addl	$1, -12(%rbp)
	movl	-24(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
.L9:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L10
.L8:
	movl	$0, -24(%rbp)
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L12:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-24(%rbp), %edx
	movslq	%edx, %rax
	imulq	$1717986919, %rax, %rax
	shrq	$32, %rax
	sarl	$2, %eax
	movl	%edx, %esi
	sarl	$31, %esi
	subl	%esi, %eax
	movl	%eax, %ecx
	movl	%ecx, %eax
	sall	$2, %eax
	addl	%ecx, %eax
	addl	%eax, %eax
	movl	%edx, %ecx
	subl	%eax, %ecx
	movl	%ecx, %eax
	leal	48(%rax), %ecx
	movq	ap(%rip), %rdx
	movl	-12(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movl	%ecx, %edx
	movb	%dl, (%rax)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1717986919, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$2, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -24(%rbp)
	subl	$1, -12(%rbp)
.L11:
	cmpl	$0, -12(%rbp)
	jns	.L12
	movzbl	1+ans(%rip), %eax
	movb	%al, ans(%rip)
	movb	$46, 1+ans(%rip)
	movl	-16(%rbp), %eax
	subl	$4, %eax
	cltq
	leaq	ans(%rip), %rdx
	movb	$0, (%rax,%rdx)
	leaq	ans(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	leaq	-16(%rbp), %rsi
	leaq	-20(%rbp), %rcx
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L13
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jg	.L14
.L13:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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 32
	.type	ans, @object
	.size	ans, 10015
ans:
	.zero	10015
	.globl	ap
	.section	.data.rel.local,"aw"
	.align 8
	.type	ap, @object
	.size	ap, 8
ap:
	.quad	ans+1
	.globl	d
	.bss
	.align 32
	.type	d, @object
	.size	d, 40060
d:
	.zero	40060
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	$1, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	addl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltd
	idivl	-20(%rbp)
	movl	%edx, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, -4(%rbp)
	addl	$1, -8(%rbp)
.L2:
	cmpl	$0, -4(%rbp)
	jle	.L5
	movl	-8(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L4
.L5:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d%d%d"
	.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
	jmp	.L7
.L14:
	movl	-16(%rbp), %eax
	addl	$6, %eax
	movl	%eax, -16(%rbp)
	movl	$40060, %edx
	movl	$0, %esi
	leaq	d(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	-16(%rbp), %edx
	movl	-28(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	movl	-20(%rbp), %eax
	cmpl	$1, %eax
	jne	.L8
	movl	-28(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	$1, -12(%rbp)
	jmp	.L9
.L10:
	movl	-16(%rbp), %edx
	movl	-24(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	calc
	addl	$1, -12(%rbp)
	movl	-24(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
.L9:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L10
.L8:
	movl	$0, -24(%rbp)
	movl	-16(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L12:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	d(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-24(%rbp), %edx
	movslq	%edx, %rax
	imulq	$1717986919, %rax, %rax
	shrq	$32, %rax
	sarl	$2, %eax
	movl	%edx, %esi
	sarl	$31, %esi
	subl	%esi, %eax
	movl	%eax, %ecx
	movl	%ecx, %eax
	sall	$2, %eax
	addl	%ecx, %eax
	addl	%eax, %eax
	movl	%edx, %ecx
	subl	%eax, %ecx
	movl	%ecx, %eax
	leal	48(%rax), %ecx
	movq	ap(%rip), %rdx
	movl	-12(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movl	%ecx, %edx
	movb	%dl, (%rax)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	imulq	$1717986919, %rdx, %rdx
	shrq	$32, %rdx
	sarl	$2, %edx
	sarl	$31, %eax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	movl	%eax, -24(%rbp)
	subl	$1, -12(%rbp)
.L11:
	cmpl	$0, -12(%rbp)
	jns	.L12
	movzbl	1+ans(%rip), %eax
	movb	%al, ans(%rip)
	movb	$46, 1+ans(%rip)
	movl	-16(%rbp), %eax
	subl	$4, %eax
	cltq
	leaq	ans(%rip), %rdx
	movb	$0, (%rax,%rdx)
	leaq	ans(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	leaq	-16(%rbp), %rsi
	leaq	-20(%rbp), %rcx
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	testl	%eax, %eax
	je	.L13
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jg	.L14
.L13:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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:
