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>

int gcd(int x,int y){
  int n1,n2,k1;
  if(x>y){
    n1=x;  n2=y;
  }
  else{
    n1=y;  n2=x;
  }
  while((n1%n2)!=0){
    k1=n1;
    n1=n2;
    n2=(k1%n2);
  }
  return n2;
}

void main(){
  int i,j,k,n,g;
  long sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        g=gcd(i,j);
        g=gcd(g,k);
        sum+=g;
      }
    }
  }
  printf("%ld",sum);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	gcd
	.type	gcd, @function
gcd:
.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	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L2
	movl	-20(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L2:
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, -8(%rbp)
.L4:
	movl	-12(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, %eax
	testl	%eax, %eax
	jne	.L5
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -16(%rbp)
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -32(%rbp)
	jmp	.L8
.L13:
	movl	$1, -28(%rbp)
	jmp	.L9
.L12:
	movl	$1, -24(%rbp)
	jmp	.L10
.L11:
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -24(%rbp)
.L10:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L11
	addl	$1, -28(%rbp)
.L9:
	movl	-36(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L12
	addl	$1, -32(%rbp)
.L8:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L13
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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	gcd
	.type	gcd, @function
gcd:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movl	%esi, %edx
	cmpl	%esi, %edi
	jg	.L3
	movl	%esi, %eax
	movl	%edi, %edx
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%edx, %ecx
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L3
	ret
	.cfi_endproc
.LFE23:
	.size	gcd, .-gcd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r10d
	testl	%r10d, %r10d
	jle	.L16
	addl	$1, %r10d
	xorl	%r8d, %r8d
	movl	$1, %ebx
.L8:
	movl	$1, %r11d
	.p2align 4,,10
	.p2align 3
.L14:
	cmpl	%r11d, %ebx
	movl	%r11d, %r9d
	movl	%r11d, %edi
	movl	$1, %esi
	cmovge	%ebx, %r9d
	cmovle	%ebx, %edi
	.p2align 4,,10
	.p2align 3
.L12:
	movl	%edi, %edx
	movl	%r9d, %eax
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%edx, %ecx
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L9
	cmpl	%esi, %ecx
	movl	%esi, %edx
	cmovle	%ecx, %edx
	cmovle	%esi, %ecx
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%ecx, %eax
	movslq	%edx, %rcx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L11
	leal	1(%rsi), %eax
	addq	%rcx, %r8
	cmpl	%eax, %r10d
	je	.L22
	movl	%eax, %esi
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L22:
	leal	1(%r11), %eax
	cmpl	%esi, %r11d
	je	.L13
	movl	%eax, %r11d
	jmp	.L14
.L13:
	leal	1(%rbx), %eax
	cmpl	%r11d, %ebx
	je	.L7
	movl	%eax, %ebx
	jmp	.L8
.L16:
	xorl	%r8d, %r8d
.L7:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L23
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L23:
	.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
	.file	"temp.c"
	.text
	.p2align 4
	.globl	gcd
	.type	gcd, @function
gcd:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movl	%esi, %edx
	cmpl	%esi, %edi
	jg	.L3
	movl	%esi, %eax
	movl	%edi, %edx
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%edx, %ecx
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L3
	ret
	.cfi_endproc
.LFE23:
	.size	gcd, .-gcd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r10d
	testl	%r10d, %r10d
	jle	.L16
	addl	$1, %r10d
	xorl	%r8d, %r8d
	movl	$1, %ebx
.L8:
	movl	$1, %r11d
	.p2align 4,,10
	.p2align 3
.L14:
	cmpl	%r11d, %ebx
	movl	%r11d, %r9d
	movl	%r11d, %edi
	movl	$1, %esi
	cmovge	%ebx, %r9d
	cmovle	%ebx, %edi
	.p2align 4,,10
	.p2align 3
.L12:
	movl	%edi, %edx
	movl	%r9d, %eax
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%edx, %ecx
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L9
	cmpl	%esi, %ecx
	movl	%esi, %edx
	cmovle	%ecx, %edx
	cmovle	%esi, %ecx
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%ecx, %eax
	movslq	%edx, %rcx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L11
	leal	1(%rsi), %eax
	addq	%rcx, %r8
	cmpl	%eax, %r10d
	je	.L22
	movl	%eax, %esi
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L22:
	leal	1(%r11), %eax
	cmpl	%esi, %r11d
	je	.L13
	movl	%eax, %r11d
	jmp	.L14
.L13:
	leal	1(%rbx), %eax
	cmpl	%r11d, %ebx
	je	.L7
	movl	%eax, %ebx
	jmp	.L8
.L16:
	xorl	%r8d, %r8d
.L7:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L23
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L23:
	.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:

#include <stdio.h>

int gcd(int x,int y){
  int n1,n2,k1;
  if(x>y){
    n1=x;  n2=y;
  }
  else{
    n1=y;  n2=x;
  }
  while((n1%n2)!=0){
    k1=n1;
    n1=n2;
    n2=(k1%n2);
  }
  return n2;
}

void main(){
  int i,j,k,n,g;
  long sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        g=gcd(i,j);
        g=gcd(g,k);
        sum+=g;
      }
    }
  }
  printf("%ld",sum);
}
4
 8
 3
 5
 7
 0
 1
 10
 20
 9

76 624 30 141 400 0 1 1249 10248 885
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>

int gcd(int x,int y){
  int n1,n2,k1;
  if(x>y){
    n1=x;  n2=y;
  }
  else{
    n1=y;  n2=x;
  }
  while((n1%n2)!=0){
    k1=n1;
    n1=n2;
    n2=(k1%n2);
  }
  return n2;
}

void main(){
  int i,j,k,n,g;
  long sum=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++){
        g=gcd(i,j);
        g=gcd(g,k);
        sum+=g;
      }
    }
  }
  printf("%ld",sum);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	gcd
	.type	gcd, @function
gcd:
.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	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L2
	movl	-20(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L2:
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, -8(%rbp)
.L4:
	movl	-12(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, %eax
	testl	%eax, %eax
	jne	.L5
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -16(%rbp)
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -32(%rbp)
	jmp	.L8
.L13:
	movl	$1, -28(%rbp)
	jmp	.L9
.L12:
	movl	$1, -24(%rbp)
	jmp	.L10
.L11:
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -24(%rbp)
.L10:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L11
	addl	$1, -28(%rbp)
.L9:
	movl	-36(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L12
	addl	$1, -32(%rbp)
.L8:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L13
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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	gcd
	.type	gcd, @function
gcd:
.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	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L2
	movl	-20(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L2:
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-12(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, -8(%rbp)
.L4:
	movl	-12(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	%edx, %eax
	testl	%eax, %eax
	jne	.L5
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%ld"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -16(%rbp)
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -32(%rbp)
	jmp	.L8
.L13:
	movl	$1, -28(%rbp)
	jmp	.L9
.L12:
	movl	$1, -24(%rbp)
	jmp	.L10
.L11:
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-24(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, -20(%rbp)
	movl	-20(%rbp), %eax
	cltq
	addq	%rax, -16(%rbp)
	addl	$1, -24(%rbp)
.L10:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L11
	addl	$1, -28(%rbp)
.L9:
	movl	-36(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L12
	addl	$1, -32(%rbp)
.L8:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L13
	movq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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:
