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>

long n,p;

int check(long x){
   long i,s;

   s=1;
   for (i=0;i<n;i++) {
      s*=x;
      if (s>p) return 0;
   }
   if (p%s==0) {
      p=p/s;
      return 2;
   } else
      return 1;
}

int main(){
   long i,j;
   int k;

   scanf("%ld %ld",&n,&p);
   if (n==1) {
      printf("%ld\n",p);
      return 0;
   }
   j=1;
   for (i=2;(k=check(i))>0;) 
      if (k==2) {
         j=j*i;
         i=2;
      } else if (i==2) i=3;
      else i+=2;
   printf("%ld\n",j);
   return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$1, -8(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L5:
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	p(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L3
	movl	$0, %eax
	jmp	.L4
.L3:
	addq	$1, -16(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L5
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L6
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rax, p(%rip)
	movl	$2, %eax
	jmp	.L4
.L6:
	movl	$1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	n(%rip), %rax
	cmpq	$1, %rax
	jne	.L8
	movq	p(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L9
.L8:
	movq	$1, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L13:
	cmpl	$2, -20(%rbp)
	jne	.L11
	movq	-8(%rbp), %rax
	imulq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L11:
	cmpq	$2, -16(%rbp)
	jne	.L12
	movq	$3, -16(%rbp)
	jmp	.L10
.L12:
	addq	$2, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	check
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jg	.L13
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L9:
	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	check
	.type	check, @function
check:
.LFB23:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rsi
	movq	p(%rip), %rax
	testq	%rsi, %rsi
	jle	.L2
	movl	$1, %ecx
	xorl	%edx, %edx
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L10:
	addq	$1, %rdx
	cmpq	%rsi, %rdx
	je	.L9
.L4:
	imulq	%rdi, %rcx
	cmpq	%rcx, %rax
	jge	.L10
	xorl	%r8d, %r8d
.L1:
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L9:
	cqto
	movl	$1, %r8d
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L1
.L2:
	movl	$2, %r8d
	movq	%rax, p(%rip)
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	check, .-check
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	p(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movq	n(%rip), %r8
	cmpq	$1, %r8
	je	.L12
	movq	p(%rip), %rsi
	xorl	%r10d, %r10d
	movl	$1, %r9d
	movl	$2, %edi
.L13:
	testq	%r8, %r8
	jle	.L22
	xorl	%eax, %eax
	movl	$1, %ecx
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L29:
	addq	$1, %rax
	cmpq	%rax, %r8
	je	.L28
.L18:
	imulq	%rdi, %rcx
	cmpq	%rsi, %rcx
	jle	.L29
	testb	%r10b, %r10b
	je	.L20
	movq	%rsi, p(%rip)
.L20:
	movq	%r9, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L14:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L28:
	.cfi_restore_state
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	je	.L16
	cmpq	$2, %rdi
	je	.L21
	addq	$2, %rdi
	jmp	.L13
.L21:
	movl	$3, %edi
	jmp	.L13
.L22:
	movl	$1, %ecx
.L16:
	movq	%rsi, %rax
	imulq	%rdi, %r9
	movl	$1, %r10d
	movl	$2, %edi
	cqto
	idivq	%rcx
	movq	%rax, %rsi
	jmp	.L13
.L12:
	movq	p(%rip), %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L14
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.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
	.file	"temp.c"
	.text
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB23:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rsi
	movq	p(%rip), %rax
	testq	%rsi, %rsi
	jle	.L2
	movl	$1, %ecx
	xorl	%edx, %edx
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L10:
	addq	$1, %rdx
	cmpq	%rsi, %rdx
	je	.L9
.L4:
	imulq	%rdi, %rcx
	cmpq	%rcx, %rax
	jge	.L10
	xorl	%r8d, %r8d
.L1:
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L9:
	cqto
	movl	$1, %r8d
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L1
.L2:
	movl	$2, %r8d
	movq	%rax, p(%rip)
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	check, .-check
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	leaq	p(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movq	n(%rip), %r8
	cmpq	$1, %r8
	je	.L12
	movq	p(%rip), %rsi
	xorl	%r10d, %r10d
	movl	$1, %r9d
	movl	$2, %edi
.L13:
	testq	%r8, %r8
	jle	.L22
	xorl	%eax, %eax
	movl	$1, %ecx
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L29:
	addq	$1, %rax
	cmpq	%rax, %r8
	je	.L28
.L18:
	imulq	%rdi, %rcx
	cmpq	%rsi, %rcx
	jle	.L29
	testb	%r10b, %r10b
	je	.L20
	movq	%rsi, p(%rip)
.L20:
	movq	%r9, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L14:
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L28:
	.cfi_restore_state
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	je	.L16
	cmpq	$2, %rdi
	je	.L21
	addq	$2, %rdi
	jmp	.L13
.L21:
	movl	$3, %edi
	jmp	.L13
.L22:
	movl	$1, %ecx
.L16:
	movq	%rsi, %rax
	imulq	%rdi, %r9
	movl	$1, %r10d
	movl	$2, %edi
	cqto
	idivq	%rcx
	movq	%rax, %rsi
	jmp	.L13
.L12:
	movq	p(%rip), %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L14
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.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:

#include <stdio.h>

long n,p;

int check(long x){
   long i,s;

   s=1;
   for (i=0;i<n;i++) {
      s*=x;
      if (s>p) return 0;
   }
   if (p%s==0) {
      p=p/s;
      return 2;
   } else
      return 1;
}

int main(){
   long i,j;
   int k;

   scanf("%ld %ld",&n,&p);
   if (n==1) {
      printf("%ld\n",p);
      return 0;
   }
   j=1;
   for (i=2;(k=check(i))>0;) 
      if (k==2) {
         j=j*i;
         i=2;
      } else if (i==2) i=3;
      else i+=2;
   printf("%ld\n",j);
   return 0;
}

5 2
 1 972439611840
 1 110
 1 2
 1 534720932937
 1 18
 1 010
 1 3
 1 867963093279
 1 15

1
 972439611840
 110
 2
 534720932937
 18
 10
 3
 867963093279
 15

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>

long n,p;

int check(long x){
   long i,s;

   s=1;
   for (i=0;i<n;i++) {
      s*=x;
      if (s>p) return 0;
   }
   if (p%s==0) {
      p=p/s;
      return 2;
   } else
      return 1;
}

int main(){
   long i,j;
   int k;

   scanf("%ld %ld",&n,&p);
   if (n==1) {
      printf("%ld\n",p);
      return 0;
   }
   j=1;
   for (i=2;(k=check(i))>0;) 
      if (k==2) {
         j=j*i;
         i=2;
      } else if (i==2) i=3;
      else i+=2;
   printf("%ld\n",j);
   return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$1, -8(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L5:
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	p(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L3
	movl	$0, %eax
	jmp	.L4
.L3:
	addq	$1, -16(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L5
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L6
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rax, p(%rip)
	movl	$2, %eax
	jmp	.L4
.L6:
	movl	$1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	n(%rip), %rax
	cmpq	$1, %rax
	jne	.L8
	movq	p(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L9
.L8:
	movq	$1, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L13:
	cmpl	$2, -20(%rbp)
	jne	.L11
	movq	-8(%rbp), %rax
	imulq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L11:
	cmpq	$2, -16(%rbp)
	jne	.L12
	movq	$3, -16(%rbp)
	jmp	.L10
.L12:
	addq	$2, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	check
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jg	.L13
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L9:
	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	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.text
	.globl	check
	.type	check, @function
check:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$1, -8(%rbp)
	movq	$0, -16(%rbp)
	jmp	.L2
.L5:
	movq	-8(%rbp), %rax
	imulq	-24(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	p(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jle	.L3
	movl	$0, %eax
	jmp	.L4
.L3:
	addq	$1, -16(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -16(%rbp)
	jl	.L5
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L6
	movq	p(%rip), %rax
	cqto
	idivq	-8(%rbp)
	movq	%rax, p(%rip)
	movl	$2, %eax
	jmp	.L4
.L6:
	movl	$1, %eax
.L4:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%ld\n"
	.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
	leaq	p(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	n(%rip), %rax
	cmpq	$1, %rax
	jne	.L8
	movq	p(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L9
.L8:
	movq	$1, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L13:
	cmpl	$2, -20(%rbp)
	jne	.L11
	movq	-8(%rbp), %rax
	imulq	-16(%rbp), %rax
	movq	%rax, -8(%rbp)
	movq	$2, -16(%rbp)
	jmp	.L10
.L11:
	cmpq	$2, -16(%rbp)
	jne	.L12
	movq	$3, -16(%rbp)
	jmp	.L10
.L12:
	addq	$2, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	check
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jg	.L13
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L9:
	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:
