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(){
	int i,j,k,p,check=0,min=2147483647,N,C,D[30][30],color[3][30]={0};
	scanf("%d",&N);
	scanf("%d",&C);

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			scanf("%d",&D[i][j]);
		}
	}

	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			scanf("%d",&k);
			p=(i+j)%3;
			color[p][k-1]++;
		}
	}

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			if(i==j)continue;
			for(k=0;k<C;k++){
				if(k==i || k==j)continue;

				for(p=0;p<C;p++){
					if(p==i)continue;
					check+=color[0][p]*D[p][i];
				}
				for(p=0;p<C;p++){
					if(p==j)continue;
					check+=color[1][p]*D[p][j];
				}
				for(p=0;p<C;p++){
					if(p==k)continue;
					check+=color[2][p]*D[p][k];
				}

				if(min>check)min=check;
				check=0;
			}
		}
	}
	printf("%d",min);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
	.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
	subq	$4016, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -3992(%rbp)
	movl	$2147483647, -3988(%rbp)
	leaq	-3984(%rbp), %rdx
	movl	$0, %eax
	movl	$45, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-4012(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4008(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -4004(%rbp)
	jmp	.L2
.L5:
	movl	$0, -4000(%rbp)
	jmp	.L3
.L4:
	leaq	-3616(%rbp), %rcx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-4004(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4000(%rbp)
.L3:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L4
	addl	$1, -4004(%rbp)
.L2:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L5
	movl	$0, -4004(%rbp)
	jmp	.L6
.L9:
	movl	$0, -4000(%rbp)
	jmp	.L7
.L8:
	leaq	-4016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-4004(%rbp), %edx
	movl	-4000(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	imulq	$1431655766, %rdx, %rdx
	shrq	$32, %rdx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	movl	%edx, -3996(%rbp)
	movl	-3996(%rbp), %ecx
	movl	%ecx, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, -3996(%rbp)
	movl	-4016(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$4, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3984(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%ecx, -3984(%rbp,%rax,4)
	addl	$1, -4000(%rbp)
.L7:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L8
	addl	$1, -4004(%rbp)
.L6:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L9
	movl	$0, -4004(%rbp)
	jmp	.L10
.L33:
	movl	$0, -4000(%rbp)
	jmp	.L11
.L32:
	movl	-4004(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L36
	movl	$0, -4016(%rbp)
	jmp	.L14
.L31:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	je	.L37
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	je	.L37
	movl	$0, -3996(%rbp)
	jmp	.L18
.L21:
	movl	-3996(%rbp), %eax
	cmpl	-4004(%rbp), %eax
	je	.L38
	movl	-3996(%rbp), %eax
	cltq
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4004(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L20
.L38:
	nop
.L20:
	addl	$1, -3996(%rbp)
.L18:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L21
	movl	$0, -3996(%rbp)
	jmp	.L22
.L25:
	movl	-3996(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L39
	movl	-3996(%rbp), %eax
	cltq
	addq	$30, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L24
.L39:
	nop
.L24:
	addl	$1, -3996(%rbp)
.L22:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L25
	movl	$0, -3996(%rbp)
	jmp	.L26
.L29:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	je	.L40
	movl	-3996(%rbp), %eax
	cltq
	addq	$60, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4016(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L28
.L40:
	nop
.L28:
	addl	$1, -3996(%rbp)
.L26:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L29
	movl	-3988(%rbp), %eax
	cmpl	-3992(%rbp), %eax
	jle	.L30
	movl	-3992(%rbp), %eax
	movl	%eax, -3988(%rbp)
.L30:
	movl	$0, -3992(%rbp)
	jmp	.L17
.L37:
	nop
.L17:
	movl	-4016(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4016(%rbp)
.L14:
	movl	-4016(%rbp), %edx
	movl	-4008(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L31
	jmp	.L13
.L36:
	nop
.L13:
	addl	$1, -4000(%rbp)
.L11:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L32
	addl	$1, -4004(%rbp)
.L10:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L33
	movl	-3988(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	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	"%d"
	.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
	movl	$45, %ecx
	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
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$4024, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4008(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rbx
	leaq	24(%rsp), %rsi
	movq	%rbx, %rdi
	rep stosq
	movq	%rbp, %rdi
	call	__isoc99_scanf@PLT
	leaq	28(%rsp), %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	movq	%rbx, (%rsp)
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
	leaq	400(%rsp), %r15
.L26:
	leaq	(%r15,%r14,4), %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %r9d
	addq	$4, %rbx
	cmpl	%r12d, %r9d
	jg	.L3
	addl	$1, %r13d
	cmpl	%r13d, %r9d
	jle	.L50
	addq	$30, %r14
	jmp	.L26
.L2:
	cmpl	$0, 24(%rsp)
	jle	.L24
.L23:
	xorl	%r13d, %r13d
	leaq	20(%rsp), %r15
	movl	$2863311531, %r14d
.L8:
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbp, %rdi
	movq	%r15, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leal	(%r12,%r13), %eax
	movl	20(%rsp), %edi
	addl	$1, %r12d
	movq	%rax, %rdx
	imulq	%r14, %rax
	shrq	$33, %rax
	leal	(%rax,%rax,2), %ecx
	movl	%edx, %eax
	leal	-1(%rdi), %edx
	subl	%ecx, %eax
	movslq	%edx, %rdx
	cltq
	movq	%rax, %rcx
	salq	$4, %rcx
	subq	%rax, %rcx
	leaq	(%rdx,%rcx,2), %rax
	addl	$1, 32(%rsp,%rax,4)
	movl	24(%rsp), %eax
	cmpl	%r12d, %eax
	jg	.L6
	addl	$1, %r13d
	cmpl	%r13d, %eax
	jle	.L48
	testl	%eax, %eax
	jg	.L8
.L48:
	movl	28(%rsp), %r9d
.L5:
	testl	%r9d, %r9d
	jle	.L24
	movl	12(%rsp), %edx
	movl	$2147483647, %r10d
	xorl	%r8d, %r8d
	movslq	%r9d, %rcx
	leaq	400(%rsp), %rax
	movq	%rax, (%rsp)
	movq	%rax, %r13
	xorl	%eax, %eax
.L21:
	movq	(%rsp), %r12
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L20:
	cmpl	%edi, %r8d
	je	.L11
	movq	(%rsp), %r11
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L19:
	cmpl	%esi, %edi
	je	.L12
	cmpl	%esi, %r8d
	je	.L12
	movq	%r13, %r15
	xorl	%edx, %edx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L14:
	cmpl	%edx, %r8d
	je	.L13
	movl	(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L13:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rdx, %rcx
	jne	.L14
	movq	%r12, %r15
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L16:
	cmpl	%edx, %edi
	je	.L15
	movl	120(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L15:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rcx, %rdx
	jne	.L16
	movq	%r11, %r15
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L18:
	cmpl	%edx, %esi
	je	.L17
	movl	240(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L17:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rdx, %rcx
	jne	.L18
	cmpl	%eax, %r10d
	cmovg	%eax, %r10d
.L12:
	addl	$1, %esi
	addq	$4, %r11
	cmpl	%r9d, %esi
	jne	.L19
	movl	%r9d, %edx
	movl	$1, %eax
.L11:
	addl	$1, %edi
	addq	$4, %r12
	cmpl	%edi, %r9d
	jne	.L20
	addl	$1, %r8d
	addq	$4, %r13
	cmpl	%r8d, %r9d
	jne	.L21
	testb	%al, %al
	je	.L10
	movl	%edx, 20(%rsp)
.L10:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	4008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L51
	addq	$4024, %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
.L24:
	.cfi_restore_state
	movl	$2147483647, %r10d
	jmp	.L10
.L51:
	call	__stack_chk_fail@PLT
.L50:
	cmpl	$0, 24(%rsp)
	movq	(%rsp), %rbx
	jg	.L23
	jmp	.L5
	.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	"%d"
	.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
	movl	$45, %ecx
	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
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$4024, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4008(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rbx
	leaq	24(%rsp), %rsi
	movq	%rbx, %rdi
	rep stosq
	movq	%rbp, %rdi
	call	__isoc99_scanf@PLT
	leaq	28(%rsp), %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	movq	%rbx, (%rsp)
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
	leaq	400(%rsp), %r15
.L26:
	leaq	(%r15,%r14,4), %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	addl	$1, %r12d
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %r9d
	addq	$4, %rbx
	cmpl	%r12d, %r9d
	jg	.L3
	addl	$1, %r13d
	cmpl	%r13d, %r9d
	jle	.L50
	addq	$30, %r14
	jmp	.L26
.L2:
	cmpl	$0, 24(%rsp)
	jle	.L24
.L23:
	xorl	%r13d, %r13d
	leaq	20(%rsp), %r15
	movl	$2863311531, %r14d
.L8:
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%rbp, %rdi
	movq	%r15, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leal	(%r12,%r13), %eax
	movl	20(%rsp), %edi
	addl	$1, %r12d
	movq	%rax, %rdx
	imulq	%r14, %rax
	shrq	$33, %rax
	leal	(%rax,%rax,2), %ecx
	movl	%edx, %eax
	leal	-1(%rdi), %edx
	subl	%ecx, %eax
	movslq	%edx, %rdx
	cltq
	movq	%rax, %rcx
	salq	$4, %rcx
	subq	%rax, %rcx
	leaq	(%rdx,%rcx,2), %rax
	addl	$1, 32(%rsp,%rax,4)
	movl	24(%rsp), %eax
	cmpl	%r12d, %eax
	jg	.L6
	addl	$1, %r13d
	cmpl	%r13d, %eax
	jle	.L48
	testl	%eax, %eax
	jg	.L8
.L48:
	movl	28(%rsp), %r9d
.L5:
	testl	%r9d, %r9d
	jle	.L24
	movl	12(%rsp), %edx
	movl	$2147483647, %r10d
	xorl	%r8d, %r8d
	movslq	%r9d, %rcx
	leaq	400(%rsp), %rax
	movq	%rax, (%rsp)
	movq	%rax, %r13
	xorl	%eax, %eax
.L21:
	movq	(%rsp), %r12
	xorl	%edi, %edi
	.p2align 4,,10
	.p2align 3
.L20:
	cmpl	%edi, %r8d
	je	.L11
	movq	(%rsp), %r11
	xorl	%esi, %esi
	.p2align 4,,10
	.p2align 3
.L19:
	cmpl	%esi, %edi
	je	.L12
	cmpl	%esi, %r8d
	je	.L12
	movq	%r13, %r15
	xorl	%edx, %edx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L14:
	cmpl	%edx, %r8d
	je	.L13
	movl	(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L13:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rdx, %rcx
	jne	.L14
	movq	%r12, %r15
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L16:
	cmpl	%edx, %edi
	je	.L15
	movl	120(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L15:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rcx, %rdx
	jne	.L16
	movq	%r11, %r15
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L18:
	cmpl	%edx, %esi
	je	.L17
	movl	240(%rbx,%rdx,4), %r14d
	imull	(%r15), %r14d
	addl	%r14d, %eax
.L17:
	addq	$1, %rdx
	addq	$120, %r15
	cmpq	%rdx, %rcx
	jne	.L18
	cmpl	%eax, %r10d
	cmovg	%eax, %r10d
.L12:
	addl	$1, %esi
	addq	$4, %r11
	cmpl	%r9d, %esi
	jne	.L19
	movl	%r9d, %edx
	movl	$1, %eax
.L11:
	addl	$1, %edi
	addq	$4, %r12
	cmpl	%edi, %r9d
	jne	.L20
	addl	$1, %r8d
	addq	$4, %r13
	cmpl	%r8d, %r9d
	jne	.L21
	testb	%al, %al
	je	.L10
	movl	%edx, 20(%rsp)
.L10:
	xorl	%eax, %eax
	movl	%r10d, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	4008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L51
	addq	$4024, %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
.L24:
	.cfi_restore_state
	movl	$2147483647, %r10d
	jmp	.L10
.L51:
	call	__stack_chk_fail@PLT
.L50:
	cmpl	$0, 24(%rsp)
	movq	(%rsp), %rbx
	jg	.L23
	jmp	.L5
	.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(){
	int i,j,k,p,check=0,min=2147483647,N,C,D[30][30],color[3][30]={0};
	scanf("%d",&N);
	scanf("%d",&C);

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			scanf("%d",&D[i][j]);
		}
	}

	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			scanf("%d",&k);
			p=(i+j)%3;
			color[p][k-1]++;
		}
	}

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			if(i==j)continue;
			for(k=0;k<C;k++){
				if(k==i || k==j)continue;

				for(p=0;p<C;p++){
					if(p==i)continue;
					check+=color[0][p]*D[p][i];
				}
				for(p=0;p<C;p++){
					if(p==j)continue;
					check+=color[1][p]*D[p][j];
				}
				for(p=0;p<C;p++){
					if(p==k)continue;
					check+=color[2][p]*D[p][k];
				}

				if(min>check)min=check;
				check=0;
			}
		}
	}
	printf("%d",min);
	return 0;
}
2 3
0 1 1
1 1 1
1 4 0
1 2
3 3
 2 3
0 1 1
1 1 1
2 4 0
1 2
3 3
 2 3
0 1 1
1 0 1
1 4 0
1 2
1 3
 2 3
0 2 1
1 1 1
2 4 0
1 2
3 3
 2 3
0 1 1
1 0 1
1 4 0
1 2
2 3
 2 3
0 1 1
1 0 1
1 4 -1
1 2
2 3
 2 3
0 2 1
1 1 1
2 2 -1
1 2
3 3
 4 3
0 0 71
81 0 53
14 92 0
1 1 2 1
2 1 1 2
2 2 1 3
1 1 2 2
 2 3
1 3 1
1 1 1
2 4 0
1 2
3 3
 2 3
-2 1 1
1 0 1
1 4 0
1 2
2 3

3 4 1 4 0 0 2 392 4 0
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(){
	int i,j,k,p,check=0,min=2147483647,N,C,D[30][30],color[3][30]={0};
	scanf("%d",&N);
	scanf("%d",&C);

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			scanf("%d",&D[i][j]);
		}
	}

	for(i=0;i<N;i++){
		for(j=0;j<N;j++){
			scanf("%d",&k);
			p=(i+j)%3;
			color[p][k-1]++;
		}
	}

	for(i=0;i<C;i++){
		for(j=0;j<C;j++){
			if(i==j)continue;
			for(k=0;k<C;k++){
				if(k==i || k==j)continue;

				for(p=0;p<C;p++){
					if(p==i)continue;
					check+=color[0][p]*D[p][i];
				}
				for(p=0;p<C;p++){
					if(p==j)continue;
					check+=color[1][p]*D[p][j];
				}
				for(p=0;p<C;p++){
					if(p==k)continue;
					check+=color[2][p]*D[p][k];
				}

				if(min>check)min=check;
				check=0;
			}
		}
	}
	printf("%d",min);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
	.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
	subq	$4016, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -3992(%rbp)
	movl	$2147483647, -3988(%rbp)
	leaq	-3984(%rbp), %rdx
	movl	$0, %eax
	movl	$45, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-4012(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4008(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -4004(%rbp)
	jmp	.L2
.L5:
	movl	$0, -4000(%rbp)
	jmp	.L3
.L4:
	leaq	-3616(%rbp), %rcx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-4004(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4000(%rbp)
.L3:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L4
	addl	$1, -4004(%rbp)
.L2:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L5
	movl	$0, -4004(%rbp)
	jmp	.L6
.L9:
	movl	$0, -4000(%rbp)
	jmp	.L7
.L8:
	leaq	-4016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-4004(%rbp), %edx
	movl	-4000(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	imulq	$1431655766, %rdx, %rdx
	shrq	$32, %rdx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	movl	%edx, -3996(%rbp)
	movl	-3996(%rbp), %ecx
	movl	%ecx, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, -3996(%rbp)
	movl	-4016(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$4, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3984(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%ecx, -3984(%rbp,%rax,4)
	addl	$1, -4000(%rbp)
.L7:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L8
	addl	$1, -4004(%rbp)
.L6:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L9
	movl	$0, -4004(%rbp)
	jmp	.L10
.L33:
	movl	$0, -4000(%rbp)
	jmp	.L11
.L32:
	movl	-4004(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L36
	movl	$0, -4016(%rbp)
	jmp	.L14
.L31:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	je	.L37
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	je	.L37
	movl	$0, -3996(%rbp)
	jmp	.L18
.L21:
	movl	-3996(%rbp), %eax
	cmpl	-4004(%rbp), %eax
	je	.L38
	movl	-3996(%rbp), %eax
	cltq
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4004(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L20
.L38:
	nop
.L20:
	addl	$1, -3996(%rbp)
.L18:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L21
	movl	$0, -3996(%rbp)
	jmp	.L22
.L25:
	movl	-3996(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L39
	movl	-3996(%rbp), %eax
	cltq
	addq	$30, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L24
.L39:
	nop
.L24:
	addl	$1, -3996(%rbp)
.L22:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L25
	movl	$0, -3996(%rbp)
	jmp	.L26
.L29:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	je	.L40
	movl	-3996(%rbp), %eax
	cltq
	addq	$60, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4016(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L28
.L40:
	nop
.L28:
	addl	$1, -3996(%rbp)
.L26:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L29
	movl	-3988(%rbp), %eax
	cmpl	-3992(%rbp), %eax
	jle	.L30
	movl	-3992(%rbp), %eax
	movl	%eax, -3988(%rbp)
.L30:
	movl	$0, -3992(%rbp)
	jmp	.L17
.L37:
	nop
.L17:
	movl	-4016(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4016(%rbp)
.L14:
	movl	-4016(%rbp), %edx
	movl	-4008(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L31
	jmp	.L13
.L36:
	nop
.L13:
	addl	$1, -4000(%rbp)
.L11:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L32
	addl	$1, -4004(%rbp)
.L10:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L33
	movl	-3988(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	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.
val
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
	.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
	subq	$4016, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -3992(%rbp)
	movl	$2147483647, -3988(%rbp)
	leaq	-3984(%rbp), %rdx
	movl	$0, %eax
	movl	$45, %ecx
	movq	%rdx, %rdi
	rep stosq
	leaq	-4012(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4008(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -4004(%rbp)
	jmp	.L2
.L5:
	movl	$0, -4000(%rbp)
	jmp	.L3
.L4:
	leaq	-3616(%rbp), %rcx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-4004(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4000(%rbp)
.L3:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L4
	addl	$1, -4004(%rbp)
.L2:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L5
	movl	$0, -4004(%rbp)
	jmp	.L6
.L9:
	movl	$0, -4000(%rbp)
	jmp	.L7
.L8:
	leaq	-4016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-4004(%rbp), %edx
	movl	-4000(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	imulq	$1431655766, %rdx, %rdx
	shrq	$32, %rdx
	movl	%eax, %ecx
	sarl	$31, %ecx
	subl	%ecx, %edx
	movl	%edx, -3996(%rbp)
	movl	-3996(%rbp), %ecx
	movl	%ecx, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, -3996(%rbp)
	movl	-4016(%rbp), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$4, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3984(%rbp,%rax,4), %eax
	leal	1(%rax), %ecx
	movslq	%edx, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%ecx, -3984(%rbp,%rax,4)
	addl	$1, -4000(%rbp)
.L7:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L8
	addl	$1, -4004(%rbp)
.L6:
	movl	-4012(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L9
	movl	$0, -4004(%rbp)
	jmp	.L10
.L33:
	movl	$0, -4000(%rbp)
	jmp	.L11
.L32:
	movl	-4004(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L36
	movl	$0, -4016(%rbp)
	jmp	.L14
.L31:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	je	.L37
	movl	-4016(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	je	.L37
	movl	$0, -3996(%rbp)
	jmp	.L18
.L21:
	movl	-3996(%rbp), %eax
	cmpl	-4004(%rbp), %eax
	je	.L38
	movl	-3996(%rbp), %eax
	cltq
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4004(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L20
.L38:
	nop
.L20:
	addl	$1, -3996(%rbp)
.L18:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L21
	movl	$0, -3996(%rbp)
	jmp	.L22
.L25:
	movl	-3996(%rbp), %eax
	cmpl	-4000(%rbp), %eax
	je	.L39
	movl	-3996(%rbp), %eax
	cltq
	addq	$30, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4000(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L24
.L39:
	nop
.L24:
	addl	$1, -3996(%rbp)
.L22:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L25
	movl	$0, -3996(%rbp)
	jmp	.L26
.L29:
	movl	-4016(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	je	.L40
	movl	-3996(%rbp), %eax
	cltq
	addq	$60, %rax
	movl	-3984(%rbp,%rax,4), %ecx
	movl	-4016(%rbp), %eax
	movslq	%eax, %rsi
	movl	-3996(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$4, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-3616(%rbp,%rax,4), %eax
	imull	%ecx, %eax
	addl	%eax, -3992(%rbp)
	jmp	.L28
.L40:
	nop
.L28:
	addl	$1, -3996(%rbp)
.L26:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -3996(%rbp)
	jl	.L29
	movl	-3988(%rbp), %eax
	cmpl	-3992(%rbp), %eax
	jle	.L30
	movl	-3992(%rbp), %eax
	movl	%eax, -3988(%rbp)
.L30:
	movl	$0, -3992(%rbp)
	jmp	.L17
.L37:
	nop
.L17:
	movl	-4016(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4016(%rbp)
.L14:
	movl	-4016(%rbp), %edx
	movl	-4008(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L31
	jmp	.L13
.L36:
	nop
.L13:
	addl	$1, -4000(%rbp)
.L11:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4000(%rbp)
	jl	.L32
	addl	$1, -4004(%rbp)
.L10:
	movl	-4008(%rbp), %eax
	cmpl	%eax, -4004(%rbp)
	jl	.L33
	movl	-3988(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	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:
