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 main(){
  long int A[300][300],B[300][300],n,i,j,k,t,x=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++)for(j=0;j<n;j++){scanf("%ld",&A[i][j]);B[i][j]=A[i][j];}
  for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(B[i][j]>B[i][k]+B[k][j])B[i][j]=B[i][k]+B[k][j];
  for(i=0;i<n;i++)for(j=0;j<n;j++)if(A[i][j]!=B[i][j]){printf("-1");return 0;}
  for(i=0;i<n;i++)for(j=i+1;j<n;j++){t=1;for(k=0;k<n;k++)if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])t=0;if(t)x+=A[i][j];}
  printf("%ld",x);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1437696(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1440024(%rbp)
	leaq	-1440064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1440056(%rbp)
	jmp	.L2
.L5:
	movq	$0, -1440048(%rbp)
	jmp	.L3
.L4:
	leaq	-1440016(%rbp), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440048(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, -720016(%rbp,%rdx,8)
	addq	$1, -1440048(%rbp)
.L3:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L4
	addq	$1, -1440056(%rbp)
.L2:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L5
	movq	$0, -1440040(%rbp)
	jmp	.L6
.L12:
	movq	$0, -1440056(%rbp)
	jmp	.L7
.L11:
	movq	$0, -1440048(%rbp)
	jmp	.L8
.L10:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-720016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-720016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jle	.L9
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440040(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rdx
	movq	-1440040(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	addq	%rax, %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, -720016(%rbp,%rax,8)
.L9:
	addq	$1, -1440048(%rbp)
.L8:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L10
	addq	$1, -1440056(%rbp)
.L7:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L11
	addq	$1, -1440040(%rbp)
.L6:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L12
	movq	$0, -1440056(%rbp)
	jmp	.L13
.L18:
	movq	$0, -1440048(%rbp)
	jmp	.L14
.L17:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	je	.L15
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L16
.L15:
	addq	$1, -1440048(%rbp)
.L14:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L17
	addq	$1, -1440056(%rbp)
.L13:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L18
	movq	$0, -1440056(%rbp)
	jmp	.L19
.L26:
	movq	-1440056(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -1440048(%rbp)
	jmp	.L20
.L25:
	movq	$1, -1440032(%rbp)
	movq	$0, -1440040(%rbp)
	jmp	.L21
.L23:
	movq	-1440056(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440048(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-1440016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-1440016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jne	.L22
	movq	$0, -1440032(%rbp)
.L22:
	addq	$1, -1440040(%rbp)
.L21:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L23
	cmpq	$0, -1440032(%rbp)
	je	.L24
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	addq	%rax, -1440024(%rbp)
.L24:
	addq	$1, -1440048(%rbp)
.L20:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L25
	addq	$1, -1440056(%rbp)
.L19:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L26
	movq	-1440024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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"
.LC1:
	.string	"-1"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1437696(%rsp), %r11
	.cfi_def_cfa 11, 1437752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2376, %rsp
	.cfi_def_cfa_offset 1440128
	leaq	.LC0(%rip), %r15
	movq	%r15, %rdi
	movq	%fs:40, %rax
	movq	%rax, 1440056(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, 40(%rsp)
	jle	.L26
	leaq	720048(%rsp), %rbp
	leaq	48(%rsp), %rax
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
	movq	%rbp, 16(%rsp)
	movq	%rbp, 24(%rsp)
	movq	$0, (%rsp)
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L22:
	movq	8(%rsp), %r13
	xorl	%r12d, %r12d
	subq	%rbx, %r13
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r13, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	0(%r13,%rbx), %rax
	movq	40(%rsp), %rdx
	addq	$8, %r13
	movq	(%rax,%r14), %rax
	movq	%rax, 0(%rbp,%r12,8)
	addq	$1, %r12
	cmpq	%r12, %rdx
	jg	.L4
	addq	$1, (%rsp)
	movq	(%rsp), %rax
	cmpq	%rax, %rdx
	jle	.L50
	subq	$2400, %rbx
	addq	$2400, %r14
	addq	$2400, %rbp
	jmp	.L22
.L26:
	xorl	%r13d, %r13d
.L21:
	movq	%r13, %rdx
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movq	1440056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L51
	addq	$1440072, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.L51:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
.L50:
	testq	%rdx, %rdx
	jle	.L26
	movq	16(%rsp), %rax
	imulq	$-2400, %rdx, %rbx
	movq	24(%rsp), %r12
	xorl	%r10d, %r10d
	leaq	0(,%rdx,8), %r11
	leaq	(%rax,%r11), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r12, %r9
	movq	%rbp, %r8
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L8:
	movq	%r8, %rcx
	subq	%r11, %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	leaq	(%rcx,%rdi), %rsi
	movq	(%r9), %rax
	addq	(%rsi,%r10), %rax
	movq	(%rcx), %rsi
	cmpq	%rsi, %rax
	cmovg	%rsi, %rax
	addq	$8, %rcx
	movq	%rax, -8(%rcx)
	cmpq	%r8, %rcx
	jne	.L7
	subq	$2400, %rdi
	leaq	2400(%rcx), %r8
	addq	$2400, %r9
	cmpq	%rbx, %rdi
	jne	.L8
	addq	$8, %r12
	addq	$2400, %r10
	cmpq	%rbp, %r12
	jne	.L9
	imulq	$2408, %rdx, %rsi
	movq	8(%rsp), %rdi
	movq	16(%rsp), %r8
	movq	%r11, %rcx
.L10:
	movq	%rcx, %rax
	subq	%r11, %rax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L11:
	addq	$8, %rax
	cmpq	%rcx, %rax
	je	.L52
.L13:
	movq	(%r8,%rax), %rbx
	cmpq	%rbx, (%rdi,%rax)
	je	.L11
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L12
.L52:
	leaq	2400(%rax), %rcx
	cmpq	%rsi, %rcx
	jne	.L10
	cmpq	$1, %rdx
	je	.L26
	leaq	-1(%rdx), %rax
	movq	8(%rsp), %r12
	leaq	56(%rsp), %r8
	xorl	%ebp, %ebp
	movq	%rax, (%rsp)
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
	xorl	%ebx, %ebx
.L20:
	movq	%r14, %r10
	addq	$1, %r14
	movq	%r8, %r11
	movq	%r14, %r9
	.p2align 4,,10
	.p2align 3
.L16:
	leaq	(%r11,%rbp), %rcx
	movl	$1, %edi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L18:
	cmpq	%rax, %r10
	je	.L17
	cmpq	%rax, %r9
	je	.L17
	movq	(%rcx), %rsi
	addq	(%r12,%rax,8), %rsi
	cmpq	%rsi, (%r11)
	cmove	%rbx, %rdi
.L17:
	addq	$1, %rax
	addq	$2400, %rcx
	cmpq	%rax, %rdx
	jne	.L18
	testq	%rdi, %rdi
	je	.L19
	addq	(%r11), %r13
.L19:
	addq	$1, %r9
	addq	$8, %r11
	cmpq	%r9, %rdx
	jg	.L16
	addq	$2400, %r12
	addq	$2408, %r8
	subq	$2400, %rbp
	cmpq	%r14, (%rsp)
	jne	.L20
	jmp	.L21
	.cfi_endproc
.LFE23:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"-1"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1437696(%rsp), %r11
	.cfi_def_cfa 11, 1437752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2376, %rsp
	.cfi_def_cfa_offset 1440128
	leaq	.LC0(%rip), %r15
	movq	%r15, %rdi
	movq	%fs:40, %rax
	movq	%rax, 1440056(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, 40(%rsp)
	jle	.L26
	leaq	720048(%rsp), %rbp
	leaq	48(%rsp), %rax
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
	movq	%rbp, 16(%rsp)
	movq	%rbp, 24(%rsp)
	movq	$0, (%rsp)
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L22:
	movq	8(%rsp), %r13
	xorl	%r12d, %r12d
	subq	%rbx, %r13
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r13, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	0(%r13,%rbx), %rax
	movq	40(%rsp), %rdx
	addq	$8, %r13
	movq	(%rax,%r14), %rax
	movq	%rax, 0(%rbp,%r12,8)
	addq	$1, %r12
	cmpq	%r12, %rdx
	jg	.L4
	addq	$1, (%rsp)
	movq	(%rsp), %rax
	cmpq	%rax, %rdx
	jle	.L50
	subq	$2400, %rbx
	addq	$2400, %r14
	addq	$2400, %rbp
	jmp	.L22
.L26:
	xorl	%r13d, %r13d
.L21:
	movq	%r13, %rdx
	movq	%r15, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movq	1440056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L51
	addq	$1440072, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.L51:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
.L50:
	testq	%rdx, %rdx
	jle	.L26
	movq	16(%rsp), %rax
	imulq	$-2400, %rdx, %rbx
	movq	24(%rsp), %r12
	xorl	%r10d, %r10d
	leaq	0(,%rdx,8), %r11
	leaq	(%rax,%r11), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r12, %r9
	movq	%rbp, %r8
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L8:
	movq	%r8, %rcx
	subq	%r11, %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	leaq	(%rcx,%rdi), %rsi
	movq	(%r9), %rax
	addq	(%rsi,%r10), %rax
	movq	(%rcx), %rsi
	cmpq	%rsi, %rax
	cmovg	%rsi, %rax
	addq	$8, %rcx
	movq	%rax, -8(%rcx)
	cmpq	%r8, %rcx
	jne	.L7
	subq	$2400, %rdi
	leaq	2400(%rcx), %r8
	addq	$2400, %r9
	cmpq	%rbx, %rdi
	jne	.L8
	addq	$8, %r12
	addq	$2400, %r10
	cmpq	%rbp, %r12
	jne	.L9
	imulq	$2408, %rdx, %rsi
	movq	8(%rsp), %rdi
	movq	16(%rsp), %r8
	movq	%r11, %rcx
.L10:
	movq	%rcx, %rax
	subq	%r11, %rax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L11:
	addq	$8, %rax
	cmpq	%rcx, %rax
	je	.L52
.L13:
	movq	(%r8,%rax), %rbx
	cmpq	%rbx, (%rdi,%rax)
	je	.L11
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L12
.L52:
	leaq	2400(%rax), %rcx
	cmpq	%rsi, %rcx
	jne	.L10
	cmpq	$1, %rdx
	je	.L26
	leaq	-1(%rdx), %rax
	movq	8(%rsp), %r12
	leaq	56(%rsp), %r8
	xorl	%ebp, %ebp
	movq	%rax, (%rsp)
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
	xorl	%ebx, %ebx
.L20:
	movq	%r14, %r10
	addq	$1, %r14
	movq	%r8, %r11
	movq	%r14, %r9
	.p2align 4,,10
	.p2align 3
.L16:
	leaq	(%r11,%rbp), %rcx
	movl	$1, %edi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L18:
	cmpq	%rax, %r10
	je	.L17
	cmpq	%rax, %r9
	je	.L17
	movq	(%rcx), %rsi
	addq	(%r12,%rax,8), %rsi
	cmpq	%rsi, (%r11)
	cmove	%rbx, %rdi
.L17:
	addq	$1, %rax
	addq	$2400, %rcx
	cmpq	%rax, %rdx
	jne	.L18
	testq	%rdi, %rdi
	je	.L19
	addq	(%r11), %r13
.L19:
	addq	$1, %r9
	addq	$8, %r11
	cmpq	%r9, %rdx
	jg	.L16
	addq	$2400, %r12
	addq	$2408, %r8
	subq	$2400, %rbp
	cmpq	%r14, (%rsp)
	jne	.L20
	jmp	.L21
	.cfi_endproc
.LFE23:
	.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 main(){
  long int A[300][300],B[300][300],n,i,j,k,t,x=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++)for(j=0;j<n;j++){scanf("%ld",&A[i][j]);B[i][j]=A[i][j];}
  for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(B[i][j]>B[i][k]+B[k][j])B[i][j]=B[i][k]+B[k][j];
  for(i=0;i<n;i++)for(j=0;j<n;j++)if(A[i][j]!=B[i][j]){printf("-1");return 0;}
  for(i=0;i<n;i++)for(j=i+1;j<n;j++){t=1;for(k=0;k<n;k++)if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])t=0;if(t)x+=A[i][j];}
  printf("%ld",x);
}

3
0 1 3
1 0 1
3 0 0
 3
-1 1 3
1 0 1
3 0 0
 3
-1 1 3
1 0 1
5 0 0
 3
0 1 3
1 0 1
5 0 0
 3
0 0 3
1 0 1
3 1 0
 3
0 1 5
1 0 1
3 0 0
 3
0 1 3
1 0 1
5 0 -1
 3
0 0 3
1 -1 1
3 1 0
 3
1 1 3
1 0 1
5 0 -1
 3
0 0 3
1 -1 1
3 0 0

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
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 main(){
  long int A[300][300],B[300][300],n,i,j,k,t,x=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++)for(j=0;j<n;j++){scanf("%ld",&A[i][j]);B[i][j]=A[i][j];}
  for(k=0;k<n;k++)for(i=0;i<n;i++)for(j=0;j<n;j++)if(B[i][j]>B[i][k]+B[k][j])B[i][j]=B[i][k]+B[k][j];
  for(i=0;i<n;i++)for(j=0;j<n;j++)if(A[i][j]!=B[i][j]){printf("-1");return 0;}
  for(i=0;i<n;i++)for(j=i+1;j<n;j++){t=1;for(k=0;k<n;k++)if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])t=0;if(t)x+=A[i][j];}
  printf("%ld",x);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1437696(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1440024(%rbp)
	leaq	-1440064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1440056(%rbp)
	jmp	.L2
.L5:
	movq	$0, -1440048(%rbp)
	jmp	.L3
.L4:
	leaq	-1440016(%rbp), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440048(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, -720016(%rbp,%rdx,8)
	addq	$1, -1440048(%rbp)
.L3:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L4
	addq	$1, -1440056(%rbp)
.L2:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L5
	movq	$0, -1440040(%rbp)
	jmp	.L6
.L12:
	movq	$0, -1440056(%rbp)
	jmp	.L7
.L11:
	movq	$0, -1440048(%rbp)
	jmp	.L8
.L10:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-720016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-720016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jle	.L9
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440040(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rdx
	movq	-1440040(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	addq	%rax, %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, -720016(%rbp,%rax,8)
.L9:
	addq	$1, -1440048(%rbp)
.L8:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L10
	addq	$1, -1440056(%rbp)
.L7:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L11
	addq	$1, -1440040(%rbp)
.L6:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L12
	movq	$0, -1440056(%rbp)
	jmp	.L13
.L18:
	movq	$0, -1440048(%rbp)
	jmp	.L14
.L17:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	je	.L15
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L16
.L15:
	addq	$1, -1440048(%rbp)
.L14:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L17
	addq	$1, -1440056(%rbp)
.L13:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L18
	movq	$0, -1440056(%rbp)
	jmp	.L19
.L26:
	movq	-1440056(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -1440048(%rbp)
	jmp	.L20
.L25:
	movq	$1, -1440032(%rbp)
	movq	$0, -1440040(%rbp)
	jmp	.L21
.L23:
	movq	-1440056(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440048(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-1440016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-1440016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jne	.L22
	movq	$0, -1440032(%rbp)
.L22:
	addq	$1, -1440040(%rbp)
.L21:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L23
	cmpq	$0, -1440032(%rbp)
	je	.L24
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	addq	%rax, -1440024(%rbp)
.L24:
	addq	$1, -1440048(%rbp)
.L20:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L25
	addq	$1, -1440056(%rbp)
.L19:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L26
	movq	-1440024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"-1"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1437696(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1440024(%rbp)
	leaq	-1440064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1440056(%rbp)
	jmp	.L2
.L5:
	movq	$0, -1440048(%rbp)
	jmp	.L3
.L4:
	leaq	-1440016(%rbp), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440048(%rbp), %rdx
	addq	%rcx, %rdx
	movq	%rax, -720016(%rbp,%rdx,8)
	addq	$1, -1440048(%rbp)
.L3:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L4
	addq	$1, -1440056(%rbp)
.L2:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L5
	movq	$0, -1440040(%rbp)
	jmp	.L6
.L12:
	movq	$0, -1440056(%rbp)
	jmp	.L7
.L11:
	movq	$0, -1440048(%rbp)
	jmp	.L8
.L10:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-720016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-720016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jle	.L9
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440040(%rbp), %rax
	addq	%rdx, %rax
	movq	-720016(%rbp,%rax,8), %rdx
	movq	-1440040(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	addq	%rax, %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, -720016(%rbp,%rax,8)
.L9:
	addq	$1, -1440048(%rbp)
.L8:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L10
	addq	$1, -1440056(%rbp)
.L7:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L11
	addq	$1, -1440040(%rbp)
.L6:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L12
	movq	$0, -1440056(%rbp)
	jmp	.L13
.L18:
	movq	$0, -1440048(%rbp)
	jmp	.L14
.L17:
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rdx
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rcx
	movq	-1440048(%rbp), %rax
	addq	%rcx, %rax
	movq	-720016(%rbp,%rax,8), %rax
	cmpq	%rax, %rdx
	je	.L15
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L16
.L15:
	addq	$1, -1440048(%rbp)
.L14:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L17
	addq	$1, -1440056(%rbp)
.L13:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L18
	movq	$0, -1440056(%rbp)
	jmp	.L19
.L26:
	movq	-1440056(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -1440048(%rbp)
	jmp	.L20
.L25:
	movq	$1, -1440032(%rbp)
	movq	$0, -1440040(%rbp)
	jmp	.L21
.L23:
	movq	-1440056(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440048(%rbp), %rax
	cmpq	-1440040(%rbp), %rax
	je	.L22
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	movq	-1440056(%rbp), %rdx
	imulq	$300, %rdx, %rcx
	movq	-1440040(%rbp), %rdx
	addq	%rcx, %rdx
	movq	-1440016(%rbp,%rdx,8), %rcx
	movq	-1440040(%rbp), %rdx
	imulq	$300, %rdx, %rsi
	movq	-1440048(%rbp), %rdx
	addq	%rsi, %rdx
	movq	-1440016(%rbp,%rdx,8), %rdx
	addq	%rcx, %rdx
	cmpq	%rdx, %rax
	jne	.L22
	movq	$0, -1440032(%rbp)
.L22:
	addq	$1, -1440040(%rbp)
.L21:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440040(%rbp)
	jl	.L23
	cmpq	$0, -1440032(%rbp)
	je	.L24
	movq	-1440056(%rbp), %rax
	imulq	$300, %rax, %rdx
	movq	-1440048(%rbp), %rax
	addq	%rdx, %rax
	movq	-1440016(%rbp,%rax,8), %rax
	addq	%rax, -1440024(%rbp)
.L24:
	addq	$1, -1440048(%rbp)
.L20:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440048(%rbp)
	jl	.L25
	addq	$1, -1440056(%rbp)
.L19:
	movq	-1440064(%rbp), %rax
	cmpq	%rax, -1440056(%rbp)
	jl	.L26
	movq	-1440024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L16:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
