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

```c
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}
main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	fun
	.type	fun, @function
fun:
.LFB0:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	je	.L2
	movl	$1, %r9d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	subq	%rdx, %rdi
	addq	%rax, %r8
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	je	.L2
.L4:
	movq	%r9, %rax
	leaq	-1(%rsi), %rdi
	salq	%cl, %rax
	subq	$1, %rcx
	leaq	-2(%rax,%rax), %rdx
	cmpq	%rsi, %rdx
	jl	.L9
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	jne	.L4
.L2:
	xorl	%eax, %eax
	testq	%rsi, %rsi
	setg	%al
	addq	%r8, %rax
	ret
	.cfi_endproc
.LFE0:
	.size	fun, .-fun
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	k(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movq	n(%rip), %rcx
	movq	k(%rip), %rax
	xorl	%r8d, %r8d
	testq	%rcx, %rcx
	je	.L11
	movl	$1, %r9d
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r9, %rdx
	leaq	-1(%rax), %rdi
	salq	%cl, %rdx
	subq	$1, %rcx
	leaq	-2(%rdx,%rdx), %rsi
	cmpq	%rax, %rsi
	movq	%rdi, %rax
	jge	.L12
	subq	%rsi, %rax
	addq	%rdx, %r8
.L12:
	testq	%rcx, %rcx
	jne	.L13
.L11:
	xorl	%esi, %esi
	testq	%rax, %rax
	leaq	.LC1(%rip), %rdi
	setg	%sil
	xorl	%eax, %eax
	addq	%r8, %rsi
	call	printf@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.globl	k
	.bss
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.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:
```

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	fun
	.type	fun, @function
fun:
.LFB0:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	je	.L2
	movl	$1, %r9d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	subq	%rdx, %rdi
	addq	%rax, %r8
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	je	.L2
.L4:
	movq	%r9, %rax
	leaq	-1(%rsi), %rdi
	salq	%cl, %rax
	subq	$1, %rcx
	leaq	-2(%rax,%rax), %rdx
	cmpq	%rsi, %rdx
	jl	.L9
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	jne	.L4
.L2:
	xorl	%eax, %eax
	testq	%rsi, %rsi
	setg	%al
	addq	%r8, %rax
	ret
	.cfi_endproc
.LFE0:
	.size	fun, .-fun
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	k(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movq	n(%rip), %rcx
	movq	k(%rip), %rax
	xorl	%r8d, %r8d
	testq	%rcx, %rcx
	je	.L11
	movl	$1, %r9d
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r9, %rdx
	leaq	-1(%rax), %rdi
	salq	%cl, %rdx
	subq	$1, %rcx
	leaq	-2(%rdx,%rdx), %rsi
	cmpq	%rax, %rsi
	movq	%rdi, %rax
	jge	.L12
	subq	%rsi, %rax
	addq	%rdx, %r8
.L12:
	testq	%rcx, %rcx
	jne	.L13
.L11:
	xorl	%esi, %esi
	testq	%rax, %rax
	leaq	.LC1(%rip), %rdi
	setg	%sil
	xorl	%eax, %eax
	addq	%r8, %rsi
	call	printf@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.globl	k
	.bss
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.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
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	fun
	.type	fun, @function
fun:
.LFB0:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	je	.L2
	movl	$1, %r9d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	subq	%rdx, %rdi
	addq	%rax, %r8
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	je	.L2
.L4:
	movq	%r9, %rax
	leaq	-1(%rsi), %rdi
	salq	%cl, %rax
	subq	$1, %rcx
	leaq	-2(%rax,%rax), %rdx
	cmpq	%rsi, %rdx
	jl	.L9
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	jne	.L4
.L2:
	xorl	%eax, %eax
	testq	%rsi, %rsi
	setg	%al
	addq	%r8, %rax
	ret
	.cfi_endproc
.LFE0:
	.size	fun, .-fun
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	k(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movq	n(%rip), %rcx
	movq	k(%rip), %rax
	xorl	%r8d, %r8d
	testq	%rcx, %rcx
	je	.L11
	movl	$1, %r9d
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r9, %rdx
	leaq	-1(%rax), %rdi
	salq	%cl, %rdx
	subq	$1, %rcx
	leaq	-2(%rdx,%rdx), %rsi
	cmpq	%rax, %rsi
	movq	%rdi, %rax
	jge	.L12
	subq	%rsi, %rax
	addq	%rdx, %r8
.L12:
	testq	%rcx, %rcx
	jne	.L13
.L11:
	xorl	%esi, %esi
	testq	%rax, %rax
	leaq	.LC1(%rip), %rdi
	setg	%sil
	xorl	%eax, %eax
	addq	%r8, %rsi
	call	printf@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.globl	k
	.bss
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.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:
```
```c
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}
main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}
main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}```

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:

50 3396494817772502
 2 1
 4 7
 0 1
 8 19
 6 19
 6 11
 6 14
 61 4321098765432109
 6 32

1698247408886243
 0
 3
 1
 7
 8
 4
 6
 2160549382716050
 15

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

```c
long n,k;long fun(long n, long x){if(n==0)return(x<=0?0:1);long p=(1LL<<n)-1;if(x<=2*p)return fun(n-1,x-1);return p+1+fun(n-1,x-1-2*p);}
main(){scanf("%ld%ld",&n,&k);printf("%ld\n",fun(n,k));}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	fun
	.type	fun, @function
fun:
.LFB0:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	je	.L2
	movl	$1, %r9d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	subq	%rdx, %rdi
	addq	%rax, %r8
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	je	.L2
.L4:
	movq	%r9, %rax
	leaq	-1(%rsi), %rdi
	salq	%cl, %rax
	subq	$1, %rcx
	leaq	-2(%rax,%rax), %rdx
	cmpq	%rsi, %rdx
	jl	.L9
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	jne	.L4
.L2:
	xorl	%eax, %eax
	testq	%rsi, %rsi
	setg	%al
	addq	%r8, %rax
	ret
	.cfi_endproc
.LFE0:
	.size	fun, .-fun
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	k(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movq	n(%rip), %rcx
	movq	k(%rip), %rax
	xorl	%r8d, %r8d
	testq	%rcx, %rcx
	je	.L11
	movl	$1, %r9d
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r9, %rdx
	leaq	-1(%rax), %rdi
	salq	%cl, %rdx
	subq	$1, %rcx
	leaq	-2(%rdx,%rdx), %rsi
	cmpq	%rax, %rsi
	movq	%rdi, %rax
	jge	.L12
	subq	%rsi, %rax
	addq	%rdx, %r8
.L12:
	testq	%rcx, %rcx
	jne	.L13
.L11:
	xorl	%esi, %esi
	testq	%rax, %rax
	leaq	.LC1(%rip), %rdi
	setg	%sil
	xorl	%eax, %eax
	addq	%r8, %rsi
	call	printf@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.globl	k
	.bss
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.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:
```

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	fun
	.type	fun, @function
fun:
.LFB0:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	xorl	%r8d, %r8d
	testq	%rdi, %rdi
	je	.L2
	movl	$1, %r9d
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	subq	%rdx, %rdi
	addq	%rax, %r8
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	je	.L2
.L4:
	movq	%r9, %rax
	leaq	-1(%rsi), %rdi
	salq	%cl, %rax
	subq	$1, %rcx
	leaq	-2(%rax,%rax), %rdx
	cmpq	%rsi, %rdx
	jl	.L9
	movq	%rdi, %rsi
	testq	%rcx, %rcx
	jne	.L4
.L2:
	xorl	%eax, %eax
	testq	%rsi, %rsi
	setg	%al
	addq	%r8, %rax
	ret
	.cfi_endproc
.LFE0:
	.size	fun, .-fun
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB1:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	k(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movq	n(%rip), %rcx
	movq	k(%rip), %rax
	xorl	%r8d, %r8d
	testq	%rcx, %rcx
	je	.L11
	movl	$1, %r9d
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%r9, %rdx
	leaq	-1(%rax), %rdi
	salq	%cl, %rdx
	subq	$1, %rcx
	leaq	-2(%rdx,%rdx), %rsi
	cmpq	%rax, %rsi
	movq	%rdi, %rax
	jge	.L12
	subq	%rsi, %rax
	addq	%rdx, %r8
.L12:
	testq	%rcx, %rcx
	jne	.L13
.L11:
	xorl	%esi, %esi
	testq	%rax, %rax
	leaq	.LC1(%rip), %rdi
	setg	%sil
	xorl	%eax, %eax
	addq	%r8, %rsi
	call	printf@PLT
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE1:
	.size	main, .-main
	.globl	k
	.bss
	.align 8
	.type	k, @object
	.size	k, 8
k:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.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:
```