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>
long X, K, D;
int main(){
	scanf("%ld%ld%ld", &X, &K, &D);
	X = labs(X);
	if(X/D >= K){
		printf("%ld\n", X - K*D);
		return 0;
	}
	K = (K - (X/D)) % 2;
	X -= X / D * D;
	if(K)X = labs(X - D);
	printf("%ld\n", X);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	X
	.bss
	.align 8
	.type	X, @object
	.size	X, 8
X:
	.zero	8
	.globl	K
	.align 8
	.type	K, @object
	.size	K, 8
K:
	.zero	8
	.globl	D
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%ld%ld%ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	D(%rip), %rax
	movq	%rax, %rcx
	leaq	K(%rip), %rax
	movq	%rax, %rdx
	leaq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	X(%rip), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rsi
	cqto
	idivq	%rsi
	movq	%rax, %rdx
	movq	K(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	X(%rip), %rax
	movq	K(%rip), %rcx
	movq	D(%rip), %rdx
	imulq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L3
.L2:
	movq	K(%rip), %rcx
	movq	X(%rip), %rax
	movq	D(%rip), %rdi
	cqto
	idivq	%rdi
	movq	%rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	cqto
	shrq	$63, %rdx
	addq	%rdx, %rax
	andl	$1, %eax
	subq	%rdx, %rax
	movq	%rax, K(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, X(%rip)
	movq	K(%rip), %rax
	testq	%rax, %rax
	je	.L4
	movq	X(%rip), %rax
	movq	D(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
.L4:
	movq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L3:
	popq	%rbp
	.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%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	D(%rip), %rcx
	xorl	%eax, %eax
	leaq	K(%rip), %rdx
	leaq	X(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movq	X(%rip), %rax
	movq	D(%rip), %rdi
	movq	K(%rip), %rcx
	movq	%rax, %rsi
	negq	%rsi
	cmovs	%rax, %rsi
	movq	%rsi, %rax
	movq	%rsi, X(%rip)
	cqto
	idivq	%rdi
	cmpq	%rcx, %rax
	jge	.L8
	movq	%rdx, %rsi
	subq	%rax, %rcx
	subq	%rdi, %rsi
	andl	$1, %ecx
	movl	$1, %edi
	movq	%rsi, %rax
	movq	%rcx, K(%rip)
	negq	%rax
	cmovs	%rsi, %rax
	testq	%rcx, %rcx
	leaq	.LC1(%rip), %rsi
	cmovne	%rax, %rdx
	xorl	%eax, %eax
	movq	%rdx, X(%rip)
	call	__printf_chk@PLT
.L3:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore_state
	imulq	%rcx, %rdi
	movq	%rsi, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	subq	%rdi, %rdx
	movl	$1, %edi
	call	__printf_chk@PLT
	jmp	.L3
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.globl	D
	.bss
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.globl	K
	.align 8
	.type	K, @object
	.size	K, 8
K:
	.zero	8
	.globl	X
	.align 8
	.type	X, @object
	.size	X, 8
X:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	D(%rip), %rcx
	xorl	%eax, %eax
	leaq	K(%rip), %rdx
	leaq	X(%rip), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movq	X(%rip), %rax
	movq	D(%rip), %rdi
	movq	K(%rip), %rcx
	movq	%rax, %rsi
	negq	%rsi
	cmovs	%rax, %rsi
	movq	%rsi, %rax
	movq	%rsi, X(%rip)
	cqto
	idivq	%rdi
	cmpq	%rcx, %rax
	jge	.L8
	movq	%rdx, %rsi
	subq	%rax, %rcx
	subq	%rdi, %rsi
	andl	$1, %ecx
	movl	$1, %edi
	movq	%rsi, %rax
	movq	%rcx, K(%rip)
	negq	%rax
	cmovs	%rsi, %rax
	testq	%rcx, %rcx
	leaq	.LC1(%rip), %rsi
	cmovne	%rax, %rdx
	xorl	%eax, %eax
	movq	%rdx, X(%rip)
	call	__printf_chk@PLT
.L3:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore_state
	imulq	%rcx, %rdi
	movq	%rsi, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	subq	%rdi, %rdx
	movl	$1, %edi
	call	__printf_chk@PLT
	jmp	.L3
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.globl	D
	.bss
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.globl	K
	.align 8
	.type	K, @object
	.size	K, 8
K:
	.zero	8
	.globl	X
	.align 8
	.type	X, @object
	.size	X, 8
X:
	.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>
#include<stdlib.h>
long X, K, D;
int main(){
	scanf("%ld%ld%ld", &X, &K, &D);
	X = labs(X);
	if(X/D >= K){
		printf("%ld\n", X - K*D);
		return 0;
	}
	K = (K - (X/D)) % 2;
	X -= X / D * D;
	if(K)X = labs(X - D);
	printf("%ld\n", X);
	return 0;
}

1000000000000000 1000100000000000 1000000000000000
 3 2 4
 10 1 4
 7 6 3
 7 0 3
 13 0 3
 1000100000000000 1000101000000000 1000000001000000
 13 1 3
 1000100100000000 1000101000000000 1000000001000000
 15 1 3

1000000000000000
 3
 6
 1
 7
 13
 999900002000000
 10
 999899902000000
 12

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>
long X, K, D;
int main(){
	scanf("%ld%ld%ld", &X, &K, &D);
	X = labs(X);
	if(X/D >= K){
		printf("%ld\n", X - K*D);
		return 0;
	}
	K = (K - (X/D)) % 2;
	X -= X / D * D;
	if(K)X = labs(X - D);
	printf("%ld\n", X);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	X
	.bss
	.align 8
	.type	X, @object
	.size	X, 8
X:
	.zero	8
	.globl	K
	.align 8
	.type	K, @object
	.size	K, 8
K:
	.zero	8
	.globl	D
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%ld%ld%ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	D(%rip), %rax
	movq	%rax, %rcx
	leaq	K(%rip), %rax
	movq	%rax, %rdx
	leaq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	X(%rip), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rsi
	cqto
	idivq	%rsi
	movq	%rax, %rdx
	movq	K(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	X(%rip), %rax
	movq	K(%rip), %rcx
	movq	D(%rip), %rdx
	imulq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L3
.L2:
	movq	K(%rip), %rcx
	movq	X(%rip), %rax
	movq	D(%rip), %rdi
	cqto
	idivq	%rdi
	movq	%rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	cqto
	shrq	$63, %rdx
	addq	%rdx, %rax
	andl	$1, %eax
	subq	%rdx, %rax
	movq	%rax, K(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, X(%rip)
	movq	K(%rip), %rax
	testq	%rax, %rax
	je	.L4
	movq	X(%rip), %rax
	movq	D(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
.L4:
	movq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L3:
	popq	%rbp
	.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
	.globl	X
	.bss
	.align 8
	.type	X, @object
	.size	X, 8
X:
	.zero	8
	.globl	K
	.align 8
	.type	K, @object
	.size	K, 8
K:
	.zero	8
	.globl	D
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%ld%ld%ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	D(%rip), %rax
	movq	%rax, %rcx
	leaq	K(%rip), %rax
	movq	%rax, %rdx
	leaq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	X(%rip), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rsi
	cqto
	idivq	%rsi
	movq	%rax, %rdx
	movq	K(%rip), %rax
	cmpq	%rax, %rdx
	jl	.L2
	movq	X(%rip), %rax
	movq	K(%rip), %rcx
	movq	D(%rip), %rdx
	imulq	%rcx, %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L3
.L2:
	movq	K(%rip), %rcx
	movq	X(%rip), %rax
	movq	D(%rip), %rdi
	cqto
	idivq	%rdi
	movq	%rax, %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	cqto
	shrq	$63, %rdx
	addq	%rdx, %rax
	andl	$1, %eax
	subq	%rdx, %rax
	movq	%rax, K(%rip)
	movq	X(%rip), %rax
	movq	D(%rip), %rcx
	cqto
	idivq	%rcx
	movq	%rdx, %rax
	movq	%rax, X(%rip)
	movq	K(%rip), %rax
	testq	%rax, %rax
	je	.L4
	movq	X(%rip), %rax
	movq	D(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	movq	%rax, X(%rip)
.L4:
	movq	X(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L3:
	popq	%rbp
	.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:
