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>
int matrixChainOrder(int*,int);
int main(void)
{
  int i;//counter
  int n;//the number of matrix
  int *p;//array of each row(column)
  scanf("%d",&n);
  p=(int*)malloc(sizeof(int)*(n+1));
  for(i=0;i<n;i++) scanf("%d%d",&p[i],&p[i+1]);
  printf("%d\n",matrixChainOrder(p,n));
  free(p);
  return 0;
}
int matrixChainOrder(int *p,int n)
{
  int i,j;//counter
  int begin,mid,end;//counter
  int **m;//m[i][j]: the number of multiplication from matrix i to matrix j
  int tempMin;//temporary minimum value
  int cur;//current value
  m=(int**)malloc(sizeof(int*)*n);
  for(i=0;i<n;i++) m[i]=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) m[i][i]=0;
  for(i=1;i<n;i++)
    {
      for(begin=0,end=i;end<n;begin++,end++)
	{
	  //printf("--\n");
	  for(mid=begin;mid<end;mid++)
	    {
	      //printf("[%d,%d,%d]->",begin,mid,end);
	      cur=m[begin][mid]+m[mid+1][end]+p[begin]*p[mid+1]*p[end+1];
	      //printf("%d+%d+%d*%d*%d=%d\n",m[begin][mid],m[mid+1][end],p[begin],p[mid+1],p[end+1],cur);
	      if(mid==begin) tempMin=cur;
	      else if(cur<tempMin) tempMin=cur;
	    }
	  m[begin][end]=tempMin;
	  //printf("m[%d][%d]=%d\n",begin,end,m[begin][end]);
	}
    }
  return m[0][n-1];
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\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
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-20(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L2:
	movl	-24(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L3
	movl	-24(%rbp), %edx
	movq	-16(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	matrixChainOrder
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	matrixChainOrder
	.type	matrixChainOrder, @function
matrixChainOrder:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%rdi, -56(%rbp)
	movl	%esi, -60(%rbp)
	movl	-60(%rbp), %eax
	cltq
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -48(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	movl	-48(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-24(%rbp), %rdx
	leaq	(%rcx,%rdx), %rbx
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, (%rbx)
	addl	$1, -48(%rbp)
.L7:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L8
	movl	$0, -48(%rbp)
	jmp	.L9
.L10:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-48(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -48(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L10
	movl	$1, -48(%rbp)
	jmp	.L11
.L18:
	movl	$0, -44(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L12
.L17:
	movl	-44(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L13
.L16:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rcx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	leal	(%rdx,%rax), %ecx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%eax, %edx
	movl	-36(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jne	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L15
.L14:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L15
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
.L15:
	addl	$1, -40(%rbp)
.L13:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L16
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	movl	-32(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
	addl	$1, -36(%rbp)
.L12:
	movl	-36(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L17
	addl	$1, -48(%rbp)
.L11:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L18
	movq	-24(%rbp), %rax
	movq	(%rax), %rdx
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	subq	$4, %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	matrixChainOrder, .-matrixChainOrder
	.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	matrixChainOrder
	.type	matrixChainOrder, @function
matrixChainOrder:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%esi, %r15
	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
	movq	%rdi, %rbp
	leaq	0(,%r15,8), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%r15, 8(%rsp)
	call	malloc@PLT
	movq	%rax, %r12
	leaq	0(,%r15,4), %rax
	movq	%rax, 16(%rsp)
	testl	%r15d, %r15d
	jle	.L3
	movq	%r15, %r13
	movl	%r15d, %eax
	movl	%ebx, 28(%rsp)
	movq	16(%rsp), %rbx
	movq	%rax, (%rsp)
	leaq	(%r12,%rax,8), %r15
	movl	%r13d, %eax
	movq	%rbp, %r13
	movl	%eax, %r14d
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%rbx, %rdi
	addq	$8, %rbp
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	cmpq	%r15, %rbp
	jne	.L5
	movq	%r13, %rbp
	movl	%r14d, %r13d
	movq	(%rsp), %r14
	movl	28(%rsp), %ebx
	xorl	%eax, %eax
	salq	$2, %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movq	(%r12,%rax,2), %rdx
	movl	$0, (%rdx,%rax)
	addq	$4, %rax
	cmpq	%rax, %r14
	jne	.L6
	cmpl	$1, %r13d
	jle	.L3
	movq	$1, (%rsp)
	.p2align 4,,10
	.p2align 3
.L13:
	movq	(%rsp), %r14
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L14:
	movq	(%r12,%r15,8), %rsi
	leaq	0(,%r14,4), %rcx
	movl	%r14d, %r8d
	movl	%r15d, %edi
	cmpl	%r15d, %r14d
	jle	.L12
	movl	0(%rbp,%r15,4), %r10d
	movl	4(%rbp,%r14,4), %r9d
	movq	%r15, %rdx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	8(%r12,%rdx,8), %r11
	movl	(%rsi,%rdx,4), %eax
	addl	(%r11,%rcx), %eax
	movl	4(%rbp,%rdx,4), %r11d
	imull	%r10d, %r11d
	imull	%r9d, %r11d
	addl	%r11d, %eax
	cmpl	%eax, %ebx
	cmovg	%eax, %ebx
	cmpl	%edx, %edi
	cmove	%eax, %ebx
	addq	$1, %rdx
	cmpl	%edx, %r8d
	jg	.L9
.L12:
	addq	$1, %r14
	movl	%ebx, (%rsi,%rcx)
	addq	$1, %r15
	cmpl	%r14d, %r13d
	jg	.L14
	addq	$1, (%rsp)
	movq	(%rsp), %rax
	cmpq	8(%rsp), %rax
	jne	.L13
.L3:
	movq	(%r12), %rax
	movq	16(%rsp), %rdi
	movl	-4(%rax,%rdi), %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	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
	.cfi_endproc
.LFE40:
	.size	matrixChainOrder, .-matrixChainOrder
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r12d
	leal	1(%r12), %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r14
	testl	%r12d, %r12d
	jle	.L24
	movq	%rax, %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%rbx, %rsi
	addq	$4, %rbx
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%rbx, %rdx
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r12d
	cmpl	%ebp, %r12d
	jg	.L25
.L24:
	movl	%r12d, %esi
	movq	%r14, %rdi
	call	matrixChainOrder
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L29:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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	matrixChainOrder
	.type	matrixChainOrder, @function
matrixChainOrder:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%esi, %r15
	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
	movq	%rdi, %rbp
	leaq	0(,%r15,8), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%r15, 8(%rsp)
	call	malloc@PLT
	movq	%rax, %r12
	leaq	0(,%r15,4), %rax
	movq	%rax, 16(%rsp)
	testl	%r15d, %r15d
	jle	.L3
	movq	%r15, %r13
	movl	%r15d, %eax
	movl	%ebx, 28(%rsp)
	movq	16(%rsp), %rbx
	movq	%rax, (%rsp)
	leaq	(%r12,%rax,8), %r15
	movl	%r13d, %eax
	movq	%rbp, %r13
	movl	%eax, %r14d
	movq	%r12, %rbp
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%rbx, %rdi
	addq	$8, %rbp
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	cmpq	%r15, %rbp
	jne	.L5
	movq	%r13, %rbp
	movl	%r14d, %r13d
	movq	(%rsp), %r14
	movl	28(%rsp), %ebx
	xorl	%eax, %eax
	salq	$2, %r14
	.p2align 4,,10
	.p2align 3
.L6:
	movq	(%r12,%rax,2), %rdx
	movl	$0, (%rdx,%rax)
	addq	$4, %rax
	cmpq	%rax, %r14
	jne	.L6
	cmpl	$1, %r13d
	jle	.L3
	movq	$1, (%rsp)
	.p2align 4,,10
	.p2align 3
.L13:
	movq	(%rsp), %r14
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L14:
	movq	(%r12,%r15,8), %rsi
	leaq	0(,%r14,4), %rcx
	movl	%r14d, %r8d
	movl	%r15d, %edi
	cmpl	%r15d, %r14d
	jle	.L12
	movl	0(%rbp,%r15,4), %r10d
	movl	4(%rbp,%r14,4), %r9d
	movq	%r15, %rdx
	.p2align 4,,10
	.p2align 3
.L9:
	movq	8(%r12,%rdx,8), %r11
	movl	(%rsi,%rdx,4), %eax
	addl	(%r11,%rcx), %eax
	movl	4(%rbp,%rdx,4), %r11d
	imull	%r10d, %r11d
	imull	%r9d, %r11d
	addl	%r11d, %eax
	cmpl	%eax, %ebx
	cmovg	%eax, %ebx
	cmpl	%edx, %edi
	cmove	%eax, %ebx
	addq	$1, %rdx
	cmpl	%edx, %r8d
	jg	.L9
.L12:
	addq	$1, %r14
	movl	%ebx, (%rsi,%rcx)
	addq	$1, %r15
	cmpl	%r14d, %r13d
	jg	.L14
	addq	$1, (%rsp)
	movq	(%rsp), %rax
	cmpq	8(%rsp), %rax
	jne	.L13
.L3:
	movq	(%r12), %rax
	movq	16(%rsp), %rdi
	movl	-4(%rax,%rdi), %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	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
	.cfi_endproc
.LFE40:
	.size	matrixChainOrder, .-matrixChainOrder
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r12d
	leal	1(%r12), %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r14
	testl	%r12d, %r12d
	jle	.L24
	movq	%rax, %rbx
	xorl	%ebp, %ebp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%rbx, %rsi
	addq	$4, %rbx
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%rbx, %rdx
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %r12d
	cmpl	%ebp, %r12d
	jg	.L25
.L24:
	movl	%r12d, %esi
	movq	%r14, %rdi
	call	matrixChainOrder
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L29:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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>
#include<stdlib.h>
int matrixChainOrder(int*,int);
int main(void)
{
  int i;//counter
  int n;//the number of matrix
  int *p;//array of each row(column)
  scanf("%d",&n);
  p=(int*)malloc(sizeof(int)*(n+1));
  for(i=0;i<n;i++) scanf("%d%d",&p[i],&p[i+1]);
  printf("%d\n",matrixChainOrder(p,n));
  free(p);
  return 0;
}
int matrixChainOrder(int *p,int n)
{
  int i,j;//counter
  int begin,mid,end;//counter
  int **m;//m[i][j]: the number of multiplication from matrix i to matrix j
  int tempMin;//temporary minimum value
  int cur;//current value
  m=(int**)malloc(sizeof(int*)*n);
  for(i=0;i<n;i++) m[i]=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) m[i][i]=0;
  for(i=1;i<n;i++)
    {
      for(begin=0,end=i;end<n;begin++,end++)
	{
	  //printf("--\n");
	  for(mid=begin;mid<end;mid++)
	    {
	      //printf("[%d,%d,%d]->",begin,mid,end);
	      cur=m[begin][mid]+m[mid+1][end]+p[begin]*p[mid+1]*p[end+1];
	      //printf("%d+%d+%d*%d*%d=%d\n",m[begin][mid],m[mid+1][end],p[begin],p[mid+1],p[end+1],cur);
	      if(mid==begin) tempMin=cur;
	      else if(cur<tempMin) tempMin=cur;
	    }
	  m[begin][end]=tempMin;
	  //printf("m[%d][%d]=%d\n",begin,end,m[begin][end]);
	}
    }
  return m[0][n-1];
}


6
10 35
35 15
15 5
5 10
10 20
20 25
 6
1 35
35 15
15 5
5 10
10 20
20 25
 6
30 35
35 15
15 5
5 10
10 20
20 29
 6
2 35
35 15
15 5
5 10
10 20
20 25
 6
2 35
35 15
15 5
5 10
10 20
20 24
 6
30 35
35 15
15 5
5 10
10 20
20 27
 6
30 35
35 15
15 5
5 10
10 20
20 8
 6
30 35
35 15
15 5
5 10
10 20
20 7
 6
2 35
35 15
15 5
5 10
10 20
20 34
 6
29 35
35 15
15 5
5 10
10 20
20 7

9125
 1350
 16125
 2700
 2660
 15625
 10875
 10625
 3060
 10415

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>
int matrixChainOrder(int*,int);
int main(void)
{
  int i;//counter
  int n;//the number of matrix
  int *p;//array of each row(column)
  scanf("%d",&n);
  p=(int*)malloc(sizeof(int)*(n+1));
  for(i=0;i<n;i++) scanf("%d%d",&p[i],&p[i+1]);
  printf("%d\n",matrixChainOrder(p,n));
  free(p);
  return 0;
}
int matrixChainOrder(int *p,int n)
{
  int i,j;//counter
  int begin,mid,end;//counter
  int **m;//m[i][j]: the number of multiplication from matrix i to matrix j
  int tempMin;//temporary minimum value
  int cur;//current value
  m=(int**)malloc(sizeof(int*)*n);
  for(i=0;i<n;i++) m[i]=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) m[i][i]=0;
  for(i=1;i<n;i++)
    {
      for(begin=0,end=i;end<n;begin++,end++)
	{
	  //printf("--\n");
	  for(mid=begin;mid<end;mid++)
	    {
	      //printf("[%d,%d,%d]->",begin,mid,end);
	      cur=m[begin][mid]+m[mid+1][end]+p[begin]*p[mid+1]*p[end+1];
	      //printf("%d+%d+%d*%d*%d=%d\n",m[begin][mid],m[mid+1][end],p[begin],p[mid+1],p[end+1],cur);
	      if(mid==begin) tempMin=cur;
	      else if(cur<tempMin) tempMin=cur;
	    }
	  m[begin][end]=tempMin;
	  //printf("m[%d][%d]=%d\n",begin,end,m[begin][end]);
	}
    }
  return m[0][n-1];
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\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
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-20(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L2:
	movl	-24(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L3
	movl	-24(%rbp), %edx
	movq	-16(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	matrixChainOrder
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	matrixChainOrder
	.type	matrixChainOrder, @function
matrixChainOrder:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%rdi, -56(%rbp)
	movl	%esi, -60(%rbp)
	movl	-60(%rbp), %eax
	cltq
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -48(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	movl	-48(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-24(%rbp), %rdx
	leaq	(%rcx,%rdx), %rbx
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, (%rbx)
	addl	$1, -48(%rbp)
.L7:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L8
	movl	$0, -48(%rbp)
	jmp	.L9
.L10:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-48(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -48(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L10
	movl	$1, -48(%rbp)
	jmp	.L11
.L18:
	movl	$0, -44(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L12
.L17:
	movl	-44(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L13
.L16:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rcx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	leal	(%rdx,%rax), %ecx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%eax, %edx
	movl	-36(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jne	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L15
.L14:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L15
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
.L15:
	addl	$1, -40(%rbp)
.L13:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L16
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	movl	-32(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
	addl	$1, -36(%rbp)
.L12:
	movl	-36(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L17
	addl	$1, -48(%rbp)
.L11:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L18
	movq	-24(%rbp), %rax
	movq	(%rax), %rdx
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	subq	$4, %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	matrixChainOrder, .-matrixChainOrder
	.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
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d"
.LC2:
	.string	"%d\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
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-20(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L2:
	movl	-24(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L3
	movl	-24(%rbp), %edx
	movq	-16(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	matrixChainOrder
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-16(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	matrixChainOrder
	.type	matrixChainOrder, @function
matrixChainOrder:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%rdi, -56(%rbp)
	movl	%esi, -60(%rbp)
	movl	-60(%rbp), %eax
	cltq
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -48(%rbp)
	jmp	.L7
.L8:
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	movl	-48(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-24(%rbp), %rdx
	leaq	(%rcx,%rdx), %rbx
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, (%rbx)
	addl	$1, -48(%rbp)
.L7:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L8
	movl	$0, -48(%rbp)
	jmp	.L9
.L10:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-48(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -48(%rbp)
.L9:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L10
	movl	$1, -48(%rbp)
	jmp	.L11
.L18:
	movl	$0, -44(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L12
.L17:
	movl	-44(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L13
.L16:
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rcx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	leal	(%rdx,%rax), %ecx
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-56(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-40(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%eax, %edx
	movl	-36(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rsi
	movq	-56(%rbp), %rax
	addq	%rsi, %rax
	movl	(%rax), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -28(%rbp)
	movl	-40(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jne	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L15
.L14:
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L15
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
.L15:
	addl	$1, -40(%rbp)
.L13:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L16
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rdx
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rax, %rdx
	movl	-32(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
	addl	$1, -36(%rbp)
.L12:
	movl	-36(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L17
	addl	$1, -48(%rbp)
.L11:
	movl	-48(%rbp), %eax
	cmpl	-60(%rbp), %eax
	jl	.L18
	movq	-24(%rbp), %rax
	movq	(%rax), %rdx
	movl	-60(%rbp), %eax
	cltq
	salq	$2, %rax
	subq	$4, %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	matrixChainOrder, .-matrixChainOrder
	.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:
