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>
#include <string.h>

#define N 100

int cost_table[N+1][N+1];

void reset_table();
void update_table(int a, int b, int cost);
int solve_lowest_cost(int n, int a, int b);

int main()
{
	while(1) {
		int n,k;
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) {
			break;
		}

		reset_table();

		for (; k > 0; k--) {
			int cmd;

			scanf("%d", &cmd);
			if (cmd == 0) {
				int a, b, cost;

				scanf("%d %d", &a, &b);
				cost = solve_lowest_cost(n, a, b);
				printf("%d\n", cost);

			} else if (cmd == 1) {
				int a, b, cost;

				scanf("%d %d %d", &a, &b, &cost);
				update_table(a, b, cost);
			}
		}

	}
	return 0;
}

void reset_table()
{
	memset(cost_table, 0, sizeof(cost_table));
}

void update_table(int a, int b, int cost)
{
	if (cost_table[a][b] == 0 || cost_table[a][b] > cost) {
		cost_table[a][b] = cost;
		cost_table[b][a] = cost;
	}
}

int solve_lowest_cost(int n, int a, int b)
{
	int i;
	int costs[N+1];
	int visited[N+1];

	for (i=1; i<=n; i++) {
		costs[i] = -1;
		visited[i] = 0;
	}
	costs[a] = 0;

	while (1) {
		int i;
		int min_cost, goal;
		min_cost = -1;
		goal = 0;
		for (i=1; i<=n; i++) {
			if (!visited[i] && costs[i] != -1 &&
					(min_cost == -1 || costs[i] < min_cost)) {
				min_cost = costs[i];
				goal = i;
			}
		}

		if (goal == 0) {
			break;
		}

		visited[goal] = 1;
		for (i=1; i<=n; i++) {
			int new_cost;
			if (visited[i] || cost_table[goal][i] == 0) {
				continue;
			}
			new_cost = costs[goal] + cost_table[goal][i];
			if (costs[i] == -1 || new_cost < costs[i]) {
				costs[i] = new_cost;
			}
		}
	}

	return costs[b];
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cost_table
	.bss
	.align 32
	.type	cost_table, @object
	.size	cost_table, 40804
cost_table:
	.zero	40804
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d %d %d"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L8:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	jmp	.L10
.L2:
	movl	$0, %eax
	call	reset_table
	jmp	.L4
.L7:
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jne	.L5
	leaq	-16(%rbp), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	solve_lowest_cost
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L6
.L5:
	movl	-28(%rbp), %eax
	cmpl	$1, %eax
	jne	.L6
	leaq	-16(%rbp), %rcx
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-24(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	update_table
.L6:
	movl	-32(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -32(%rbp)
.L4:
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jg	.L7
	jmp	.L8
.L10:
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	reset_table
	.type	reset_table, @function
reset_table:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$40804, %edx
	movl	$0, %esi
	leaq	cost_table(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	reset_table, .-reset_table
	.globl	update_table
	.type	update_table, @function
update_table:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L13
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L15
.L13:
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L15:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	update_table, .-update_table
	.globl	solve_lowest_cost
	.type	solve_lowest_cost, @function
solve_lowest_cost:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$880, %rsp
	movl	%edi, -868(%rbp)
	movl	%esi, -872(%rbp)
	movl	%edx, -876(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$1, -852(%rbp)
	jmp	.L17
.L18:
	movl	-852(%rbp), %eax
	cltq
	movl	$-1, -832(%rbp,%rax,4)
	movl	-852(%rbp), %eax
	cltq
	movl	$0, -416(%rbp,%rax,4)
	addl	$1, -852(%rbp)
.L17:
	movl	-852(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L18
	movl	-872(%rbp), %eax
	cltq
	movl	$0, -832(%rbp,%rax,4)
.L31:
	movl	$-1, -844(%rbp)
	movl	$0, -840(%rbp)
	movl	$1, -848(%rbp)
	jmp	.L19
.L22:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L20
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L20
	cmpl	$-1, -844(%rbp)
	je	.L21
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -844(%rbp)
	jle	.L20
.L21:
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movl	%eax, -844(%rbp)
	movl	-848(%rbp), %eax
	movl	%eax, -840(%rbp)
.L20:
	addl	$1, -848(%rbp)
.L19:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L22
	cmpl	$0, -840(%rbp)
	je	.L35
	movl	-840(%rbp), %eax
	cltq
	movl	$1, -416(%rbp,%rax,4)
	movl	$1, -848(%rbp)
	jmp	.L25
.L30:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L36
	movl	-848(%rbp), %eax
	movslq	%eax, %rcx
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L36
	movl	-840(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %ecx
	movl	-848(%rbp), %eax
	movslq	%eax, %rsi
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdi
	addq	%rdi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	movl	%eax, -836(%rbp)
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L29
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -836(%rbp)
	jge	.L28
.L29:
	movl	-848(%rbp), %eax
	cltq
	movl	-836(%rbp), %edx
	movl	%edx, -832(%rbp,%rax,4)
	jmp	.L28
.L36:
	nop
.L28:
	addl	$1, -848(%rbp)
.L25:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L30
	jmp	.L31
.L35:
	nop
	movl	-876(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	solve_lowest_cost, .-solve_lowest_cost
	.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	reset_table
	.type	reset_table, @function
reset_table:
.LFB52:
	.cfi_startproc
	endbr64
	movl	$40804, %edx
	xorl	%esi, %esi
	leaq	cost_table(%rip), %rdi
	jmp	memset@PLT
	.cfi_endproc
.LFE52:
	.size	reset_table, .-reset_table
	.p2align 4
	.globl	update_table
	.type	update_table, @function
update_table:
.LFB53:
	.cfi_startproc
	endbr64
	movslq	%edi, %rax
	movl	%edx, %ecx
	movslq	%esi, %r8
	leaq	(%rax,%rax,4), %rdx
	leaq	cost_table(%rip), %rsi
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,4), %rdx
	addq	%r8, %rdx
	movl	(%rsi,%rdx,4), %edx
	testl	%edx, %edx
	je	.L6
	cmpl	%ecx, %edx
	jle	.L3
.L6:
	leaq	(%rax,%rax,4), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,4), %rdx
	addq	%r8, %rdx
	movl	%ecx, (%rsi,%rdx,4)
	leaq	(%r8,%r8,4), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%r8,%rdx,4), %rdx
	addq	%rdx, %rax
	movl	%ecx, (%rsi,%rax,4)
.L3:
	ret
	.cfi_endproc
.LFE53:
	.size	update_table, .-update_table
	.p2align 4
	.globl	solve_lowest_cost
	.type	solve_lowest_cost, @function
solve_lowest_cost:
.LFB54:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movslq	%esi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movslq	%edx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edi, %ebx
	subq	$840, %rsp
	.cfi_def_cfa_offset 880
	movq	%fs:40, %rax
	movq	%rax, 824(%rsp)
	xorl	%eax, %eax
	testl	%edi, %edi
	jle	.L11
	movslq	%edi, %r13
	movl	$255, %esi
	leaq	4(%rsp), %rdi
	salq	$2, %r13
	movq	%r13, %rdx
	call	memset@PLT
	leaq	420(%rsp), %rdi
	movq	%r13, %rdx
	xorl	%esi, %esi
	call	memset@PLT
.L11:
	movl	$0, (%rsp,%r12,4)
	leal	1(%rbx), %esi
	leaq	416(%rsp), %rcx
	leaq	cost_table(%rip), %r10
	testl	%ebx, %ebx
	jle	.L12
	.p2align 4,,10
	.p2align 3
.L41:
	movl	$1, %eax
	xorl	%edi, %edi
	movl	$-1, %r9d
	.p2align 4,,10
	.p2align 3
.L15:
	movl	(%rcx,%rax,4), %r11d
	movl	%eax, %r8d
	testl	%r11d, %r11d
	jne	.L13
	movl	(%rsp,%rax,4), %edx
	cmpl	$-1, %edx
	je	.L13
	cmpl	%edx, %r9d
	jg	.L21
	cmpl	$-1, %r9d
	jne	.L13
.L21:
	movslq	%r8d, %rdi
	movl	%edx, %r9d
.L13:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L15
	testl	%edi, %edi
	je	.L12
	imulq	$404, %rdi, %r11
	movl	$1, %eax
	movl	$1, 416(%rsp,%rdi,4)
	addq	%r10, %r11
	.p2align 4,,10
	.p2align 3
.L18:
	movl	(%rcx,%rax,4), %edx
	testl	%edx, %edx
	jne	.L16
	movl	(%r11,%rax,4), %edx
	testl	%edx, %edx
	je	.L16
	movq	%rsp, %r8
	addl	(%rsp,%rdi,4), %edx
	movl	(%r8,%rax,4), %r9d
	cmpl	%edx, %r9d
	jg	.L22
	cmpl	$-1, %r9d
	jne	.L16
.L22:
	movl	%edx, (%r8,%rax,4)
.L16:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L18
	testl	%ebx, %ebx
	jg	.L41
.L12:
	movl	(%rsp,%rbp,4), %eax
	movq	824(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L42
	addq	$840, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L42:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE54:
	.size	solve_lowest_cost, .-solve_lowest_cost
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d %d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.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
	leaq	.LC0(%rip), %r14
	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	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L46:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	xorl	%eax, %eax
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movl	36(%rsp), %ecx
	movl	%ecx, %eax
	orl	32(%rsp), %eax
	movl	%ecx, 12(%rsp)
	je	.L44
	movl	$40804, %edx
	xorl	%esi, %esi
	leaq	40(%rsp), %rbx
	leaq	cost_table(%rip), %rdi
	leaq	52(%rsp), %r13
	call	memset@PLT
	movl	12(%rsp), %ecx
	leaq	48(%rsp), %r12
	leaq	.LC2(%rip), %r15
	testl	%ecx, %ecx
	jg	.L45
	jmp	.L46
	.p2align 4,,10
	.p2align 3
.L47:
	cmpl	$1, %eax
	je	.L61
.L48:
	movl	36(%rsp), %eax
	subl	$1, %eax
	movl	%eax, 36(%rsp)
	testl	%eax, %eax
	jle	.L46
.L45:
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	testl	%eax, %eax
	jne	.L47
	movq	%r13, %rdx
	movq	%r12, %rsi
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %edx
	movl	48(%rsp), %esi
	movl	32(%rsp), %edi
	call	solve_lowest_cost
	movq	%r15, %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L48
	.p2align 4,,10
	.p2align 3
.L61:
	leaq	44(%rsp), %rsi
	movq	%r13, %rcx
	movq	%r12, %rdx
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rdi
	call	__isoc99_scanf@PLT
	movslq	44(%rsp), %rax
	movslq	48(%rsp), %rdx
	leaq	cost_table(%rip), %rdi
	movl	52(%rsp), %esi
	leaq	(%rax,%rax,4), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,4), %rcx
	addq	%rdx, %rcx
	movl	(%rdi,%rcx,4), %ecx
	cmpl	%ecx, %esi
	jl	.L53
	testl	%ecx, %ecx
	jne	.L48
.L53:
	leaq	(%rax,%rax,4), %rcx
	leaq	cost_table(%rip), %rdi
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,4), %rcx
	addq	%rdx, %rcx
	movl	%esi, (%rdi,%rcx,4)
	leaq	(%rdx,%rdx,4), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rdx,%rcx,4), %rdx
	addq	%rdx, %rax
	movl	%esi, (%rdi,%rax,4)
	jmp	.L48
	.p2align 4,,10
	.p2align 3
.L44:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L62
	addq	$72, %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
.L62:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	cost_table
	.bss
	.align 32
	.type	cost_table, @object
	.size	cost_table, 40804
cost_table:
	.zero	40804
	.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	reset_table
	.type	reset_table, @function
reset_table:
.LFB52:
	.cfi_startproc
	endbr64
	movl	$40804, %edx
	xorl	%esi, %esi
	leaq	cost_table(%rip), %rdi
	jmp	memset@PLT
	.cfi_endproc
.LFE52:
	.size	reset_table, .-reset_table
	.p2align 4
	.globl	update_table
	.type	update_table, @function
update_table:
.LFB53:
	.cfi_startproc
	endbr64
	movslq	%edi, %rax
	movl	%edx, %ecx
	movslq	%esi, %r8
	leaq	(%rax,%rax,4), %rdx
	leaq	cost_table(%rip), %rsi
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,4), %rdx
	addq	%r8, %rdx
	movl	(%rsi,%rdx,4), %edx
	testl	%edx, %edx
	je	.L6
	cmpl	%ecx, %edx
	jle	.L3
.L6:
	leaq	(%rax,%rax,4), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%rax,%rdx,4), %rdx
	addq	%r8, %rdx
	movl	%ecx, (%rsi,%rdx,4)
	leaq	(%r8,%r8,4), %rdx
	leaq	(%rdx,%rdx,4), %rdx
	leaq	(%r8,%rdx,4), %rdx
	addq	%rdx, %rax
	movl	%ecx, (%rsi,%rax,4)
.L3:
	ret
	.cfi_endproc
.LFE53:
	.size	update_table, .-update_table
	.p2align 4
	.globl	solve_lowest_cost
	.type	solve_lowest_cost, @function
solve_lowest_cost:
.LFB54:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movslq	%esi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movslq	%edx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edi, %ebx
	subq	$840, %rsp
	.cfi_def_cfa_offset 880
	movq	%fs:40, %rax
	movq	%rax, 824(%rsp)
	xorl	%eax, %eax
	testl	%edi, %edi
	jle	.L11
	movslq	%edi, %r13
	movl	$255, %esi
	leaq	4(%rsp), %rdi
	salq	$2, %r13
	movq	%r13, %rdx
	call	memset@PLT
	leaq	420(%rsp), %rdi
	movq	%r13, %rdx
	xorl	%esi, %esi
	call	memset@PLT
.L11:
	movl	$0, (%rsp,%r12,4)
	leal	1(%rbx), %esi
	leaq	416(%rsp), %rcx
	leaq	cost_table(%rip), %r10
	testl	%ebx, %ebx
	jle	.L12
	.p2align 4,,10
	.p2align 3
.L41:
	movl	$1, %eax
	xorl	%edi, %edi
	movl	$-1, %r9d
	.p2align 4,,10
	.p2align 3
.L15:
	movl	(%rcx,%rax,4), %r11d
	movl	%eax, %r8d
	testl	%r11d, %r11d
	jne	.L13
	movl	(%rsp,%rax,4), %edx
	cmpl	$-1, %edx
	je	.L13
	cmpl	%edx, %r9d
	jg	.L21
	cmpl	$-1, %r9d
	jne	.L13
.L21:
	movslq	%r8d, %rdi
	movl	%edx, %r9d
.L13:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L15
	testl	%edi, %edi
	je	.L12
	imulq	$404, %rdi, %r11
	movl	$1, %eax
	movl	$1, 416(%rsp,%rdi,4)
	addq	%r10, %r11
	.p2align 4,,10
	.p2align 3
.L18:
	movl	(%rcx,%rax,4), %edx
	testl	%edx, %edx
	jne	.L16
	movl	(%r11,%rax,4), %edx
	testl	%edx, %edx
	je	.L16
	movq	%rsp, %r8
	addl	(%rsp,%rdi,4), %edx
	movl	(%r8,%rax,4), %r9d
	cmpl	%edx, %r9d
	jg	.L22
	cmpl	$-1, %r9d
	jne	.L16
.L22:
	movl	%edx, (%r8,%rax,4)
.L16:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L18
	testl	%ebx, %ebx
	jg	.L41
.L12:
	movl	(%rsp,%rbp,4), %eax
	movq	824(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L42
	addq	$840, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L42:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE54:
	.size	solve_lowest_cost, .-solve_lowest_cost
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d %d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.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
	leaq	.LC0(%rip), %r14
	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	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L46:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	xorl	%eax, %eax
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movl	36(%rsp), %ecx
	movl	%ecx, %eax
	orl	32(%rsp), %eax
	movl	%ecx, 12(%rsp)
	je	.L44
	movl	$40804, %edx
	xorl	%esi, %esi
	leaq	40(%rsp), %rbx
	leaq	cost_table(%rip), %rdi
	leaq	52(%rsp), %r13
	call	memset@PLT
	movl	12(%rsp), %ecx
	leaq	48(%rsp), %r12
	leaq	.LC2(%rip), %r15
	testl	%ecx, %ecx
	jg	.L45
	jmp	.L46
	.p2align 4,,10
	.p2align 3
.L47:
	cmpl	$1, %eax
	je	.L61
.L48:
	movl	36(%rsp), %eax
	subl	$1, %eax
	movl	%eax, 36(%rsp)
	testl	%eax, %eax
	jle	.L46
.L45:
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	40(%rsp), %eax
	testl	%eax, %eax
	jne	.L47
	movq	%r13, %rdx
	movq	%r12, %rsi
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %edx
	movl	48(%rsp), %esi
	movl	32(%rsp), %edi
	call	solve_lowest_cost
	movq	%r15, %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L48
	.p2align 4,,10
	.p2align 3
.L61:
	leaq	44(%rsp), %rsi
	movq	%r13, %rcx
	movq	%r12, %rdx
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rdi
	call	__isoc99_scanf@PLT
	movslq	44(%rsp), %rax
	movslq	48(%rsp), %rdx
	leaq	cost_table(%rip), %rdi
	movl	52(%rsp), %esi
	leaq	(%rax,%rax,4), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,4), %rcx
	addq	%rdx, %rcx
	movl	(%rdi,%rcx,4), %ecx
	cmpl	%ecx, %esi
	jl	.L53
	testl	%ecx, %ecx
	jne	.L48
.L53:
	leaq	(%rax,%rax,4), %rcx
	leaq	cost_table(%rip), %rdi
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rax,%rcx,4), %rcx
	addq	%rdx, %rcx
	movl	%esi, (%rdi,%rcx,4)
	leaq	(%rdx,%rdx,4), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	leaq	(%rdx,%rcx,4), %rdx
	addq	%rdx, %rax
	movl	%esi, (%rdi,%rax,4)
	jmp	.L48
	.p2align 4,,10
	.p2align 3
.L44:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L62
	addq	$72, %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
.L62:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	cost_table
	.bss
	.align 32
	.type	cost_table, @object
	.size	cost_table, 40804
cost_table:
	.zero	40804
	.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>
#include <string.h>

#define N 100

int cost_table[N+1][N+1];

void reset_table();
void update_table(int a, int b, int cost);
int solve_lowest_cost(int n, int a, int b);

int main()
{
	while(1) {
		int n,k;
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) {
			break;
		}

		reset_table();

		for (; k > 0; k--) {
			int cmd;

			scanf("%d", &cmd);
			if (cmd == 0) {
				int a, b, cost;

				scanf("%d %d", &a, &b);
				cost = solve_lowest_cost(n, a, b);
				printf("%d\n", cost);

			} else if (cmd == 1) {
				int a, b, cost;

				scanf("%d %d %d", &a, &b, &cost);
				update_table(a, b, cost);
			}
		}

	}
	return 0;
}

void reset_table()
{
	memset(cost_table, 0, sizeof(cost_table));
}

void update_table(int a, int b, int cost)
{
	if (cost_table[a][b] == 0 || cost_table[a][b] > cost) {
		cost_table[a][b] = cost;
		cost_table[b][a] = cost;
	}
}

int solve_lowest_cost(int n, int a, int b)
{
	int i;
	int costs[N+1];
	int visited[N+1];

	for (i=1; i<=n; i++) {
		costs[i] = -1;
		visited[i] = 0;
	}
	costs[a] = 0;

	while (1) {
		int i;
		int min_cost, goal;
		min_cost = -1;
		goal = 0;
		for (i=1; i<=n; i++) {
			if (!visited[i] && costs[i] != -1 &&
					(min_cost == -1 || costs[i] < min_cost)) {
				min_cost = costs[i];
				goal = i;
			}
		}

		if (goal == 0) {
			break;
		}

		visited[goal] = 1;
		for (i=1; i<=n; i++) {
			int new_cost;
			if (visited[i] || cost_table[goal][i] == 0) {
				continue;
			}
			new_cost = costs[goal] + cost_table[goal][i];
			if (costs[i] == -1 || new_cost < costs[i]) {
				costs[i] = new_cost;
			}
		}
	}

	return costs[b];
}
3 8
1 3 1 10
0 2 3
1 2 2 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 2 20
1 1 1 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 212055
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 2 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 150117
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 2
0 3 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 1 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 85440
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 1 843468
1 4 5 15934
0 2 1
0 4 2
0 1 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 2780
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 1 3
5 16
1 1 2 343750
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 5 843468
1 4 5 15934
0 2 1
0 4 1
0 3 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 85440
1 1 3 3343
1 1 4 347392
1 1 5 5497
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 1 843468
1 4 5 2961
0 2 1
0 4 1
0 1 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 20
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 85440
1 1 3 3343
1 1 4 347392
1 1 5 2257
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 1 843468
1 4 5 2961
0 2 1
0 4 1
0 1 2
0 4 2
0 4 3
0 5 3
0 0
 3 8
1 3 1 10
0 2 3
1 2 3 1
1 1 2 5
0 3 2
1 1 3 7
1 2 1 9
0 2 3
5 16
1 1 2 85440
1 1 3 3343
1 1 4 347392
1 1 5 2257
1 2 3 123394
1 2 4 545492
1 2 5 458
1 3 4 343983
1 3 1 843468
1 4 5 2961
0 2 1
0 4 1
0 1 2
0 4 2
0 4 3
0 5 3
0 0

-1
15
12
5955
21431
9298
16392
24774
8840
 -1
-1
16
5955
21431
9298
16392
24774
8840
 -1
15
12
5955
16392
9298
16392
24774
8840
 -1
15
12
5955
21431
5955
16392
24774
8840
 -1
15
12
5955
16392
5955
16392
24774
8840
 -1
15
12
5955
8277
9298
3238
11620
8840
 -1
15
7
5955
21431
9298
16392
24774
8840
 -1
15
12
5955
8458
5955
3419
11801
8840
 -1
15
12
2715
5218
2715
3419
8561
5600
 -1
1
1
2715
5218
2715
3419
8561
5600

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>
#include <string.h>

#define N 100

int cost_table[N+1][N+1];

void reset_table();
void update_table(int a, int b, int cost);
int solve_lowest_cost(int n, int a, int b);

int main()
{
	while(1) {
		int n,k;
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) {
			break;
		}

		reset_table();

		for (; k > 0; k--) {
			int cmd;

			scanf("%d", &cmd);
			if (cmd == 0) {
				int a, b, cost;

				scanf("%d %d", &a, &b);
				cost = solve_lowest_cost(n, a, b);
				printf("%d\n", cost);

			} else if (cmd == 1) {
				int a, b, cost;

				scanf("%d %d %d", &a, &b, &cost);
				update_table(a, b, cost);
			}
		}

	}
	return 0;
}

void reset_table()
{
	memset(cost_table, 0, sizeof(cost_table));
}

void update_table(int a, int b, int cost)
{
	if (cost_table[a][b] == 0 || cost_table[a][b] > cost) {
		cost_table[a][b] = cost;
		cost_table[b][a] = cost;
	}
}

int solve_lowest_cost(int n, int a, int b)
{
	int i;
	int costs[N+1];
	int visited[N+1];

	for (i=1; i<=n; i++) {
		costs[i] = -1;
		visited[i] = 0;
	}
	costs[a] = 0;

	while (1) {
		int i;
		int min_cost, goal;
		min_cost = -1;
		goal = 0;
		for (i=1; i<=n; i++) {
			if (!visited[i] && costs[i] != -1 &&
					(min_cost == -1 || costs[i] < min_cost)) {
				min_cost = costs[i];
				goal = i;
			}
		}

		if (goal == 0) {
			break;
		}

		visited[goal] = 1;
		for (i=1; i<=n; i++) {
			int new_cost;
			if (visited[i] || cost_table[goal][i] == 0) {
				continue;
			}
			new_cost = costs[goal] + cost_table[goal][i];
			if (costs[i] == -1 || new_cost < costs[i]) {
				costs[i] = new_cost;
			}
		}
	}

	return costs[b];
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cost_table
	.bss
	.align 32
	.type	cost_table, @object
	.size	cost_table, 40804
cost_table:
	.zero	40804
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d %d %d"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L8:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	jmp	.L10
.L2:
	movl	$0, %eax
	call	reset_table
	jmp	.L4
.L7:
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jne	.L5
	leaq	-16(%rbp), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	solve_lowest_cost
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L6
.L5:
	movl	-28(%rbp), %eax
	cmpl	$1, %eax
	jne	.L6
	leaq	-16(%rbp), %rcx
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-24(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	update_table
.L6:
	movl	-32(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -32(%rbp)
.L4:
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jg	.L7
	jmp	.L8
.L10:
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	reset_table
	.type	reset_table, @function
reset_table:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$40804, %edx
	movl	$0, %esi
	leaq	cost_table(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	reset_table, .-reset_table
	.globl	update_table
	.type	update_table, @function
update_table:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L13
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L15
.L13:
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L15:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	update_table, .-update_table
	.globl	solve_lowest_cost
	.type	solve_lowest_cost, @function
solve_lowest_cost:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$880, %rsp
	movl	%edi, -868(%rbp)
	movl	%esi, -872(%rbp)
	movl	%edx, -876(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$1, -852(%rbp)
	jmp	.L17
.L18:
	movl	-852(%rbp), %eax
	cltq
	movl	$-1, -832(%rbp,%rax,4)
	movl	-852(%rbp), %eax
	cltq
	movl	$0, -416(%rbp,%rax,4)
	addl	$1, -852(%rbp)
.L17:
	movl	-852(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L18
	movl	-872(%rbp), %eax
	cltq
	movl	$0, -832(%rbp,%rax,4)
.L31:
	movl	$-1, -844(%rbp)
	movl	$0, -840(%rbp)
	movl	$1, -848(%rbp)
	jmp	.L19
.L22:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L20
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L20
	cmpl	$-1, -844(%rbp)
	je	.L21
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -844(%rbp)
	jle	.L20
.L21:
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movl	%eax, -844(%rbp)
	movl	-848(%rbp), %eax
	movl	%eax, -840(%rbp)
.L20:
	addl	$1, -848(%rbp)
.L19:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L22
	cmpl	$0, -840(%rbp)
	je	.L35
	movl	-840(%rbp), %eax
	cltq
	movl	$1, -416(%rbp,%rax,4)
	movl	$1, -848(%rbp)
	jmp	.L25
.L30:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L36
	movl	-848(%rbp), %eax
	movslq	%eax, %rcx
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L36
	movl	-840(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %ecx
	movl	-848(%rbp), %eax
	movslq	%eax, %rsi
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdi
	addq	%rdi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	movl	%eax, -836(%rbp)
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L29
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -836(%rbp)
	jge	.L28
.L29:
	movl	-848(%rbp), %eax
	cltq
	movl	-836(%rbp), %edx
	movl	%edx, -832(%rbp,%rax,4)
	jmp	.L28
.L36:
	nop
.L28:
	addl	$1, -848(%rbp)
.L25:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L30
	jmp	.L31
.L35:
	nop
	movl	-876(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	solve_lowest_cost, .-solve_lowest_cost
	.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	cost_table
	.bss
	.align 32
	.type	cost_table, @object
	.size	cost_table, 40804
cost_table:
	.zero	40804
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%d"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d %d %d"
	.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	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L8:
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	jmp	.L10
.L2:
	movl	$0, %eax
	call	reset_table
	jmp	.L4
.L7:
	leaq	-28(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-28(%rbp), %eax
	testl	%eax, %eax
	jne	.L5
	leaq	-16(%rbp), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-36(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	solve_lowest_cost
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L6
.L5:
	movl	-28(%rbp), %eax
	cmpl	$1, %eax
	jne	.L6
	leaq	-16(%rbp), %rcx
	leaq	-20(%rbp), %rdx
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-16(%rbp), %edx
	movl	-20(%rbp), %ecx
	movl	-24(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	update_table
.L6:
	movl	-32(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -32(%rbp)
.L4:
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	jg	.L7
	jmp	.L8
.L10:
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	reset_table
	.type	reset_table, @function
reset_table:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$40804, %edx
	movl	$0, %esi
	leaq	cost_table(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	reset_table, .-reset_table
	.globl	update_table
	.type	update_table, @function
update_table:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	%edx, -12(%rbp)
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L13
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L15
.L13:
	movl	-8(%rbp), %eax
	movslq	%eax, %rcx
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movl	-8(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	cost_table(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L15:
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	update_table, .-update_table
	.globl	solve_lowest_cost
	.type	solve_lowest_cost, @function
solve_lowest_cost:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$880, %rsp
	movl	%edi, -868(%rbp)
	movl	%esi, -872(%rbp)
	movl	%edx, -876(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$1, -852(%rbp)
	jmp	.L17
.L18:
	movl	-852(%rbp), %eax
	cltq
	movl	$-1, -832(%rbp,%rax,4)
	movl	-852(%rbp), %eax
	cltq
	movl	$0, -416(%rbp,%rax,4)
	addl	$1, -852(%rbp)
.L17:
	movl	-852(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L18
	movl	-872(%rbp), %eax
	cltq
	movl	$0, -832(%rbp,%rax,4)
.L31:
	movl	$-1, -844(%rbp)
	movl	$0, -840(%rbp)
	movl	$1, -848(%rbp)
	jmp	.L19
.L22:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L20
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L20
	cmpl	$-1, -844(%rbp)
	je	.L21
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -844(%rbp)
	jle	.L20
.L21:
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movl	%eax, -844(%rbp)
	movl	-848(%rbp), %eax
	movl	%eax, -840(%rbp)
.L20:
	addl	$1, -848(%rbp)
.L19:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L22
	cmpl	$0, -840(%rbp)
	je	.L35
	movl	-840(%rbp), %eax
	cltq
	movl	$1, -416(%rbp,%rax,4)
	movl	$1, -848(%rbp)
	jmp	.L25
.L30:
	movl	-848(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L36
	movl	-848(%rbp), %eax
	movslq	%eax, %rcx
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rsi
	addq	%rsi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L36
	movl	-840(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %ecx
	movl	-848(%rbp), %eax
	movslq	%eax, %rsi
	movl	-840(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdi
	addq	%rdi, %rax
	salq	$2, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	cost_table(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	movl	%eax, -836(%rbp)
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	$-1, %eax
	je	.L29
	movl	-848(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	cmpl	%eax, -836(%rbp)
	jge	.L28
.L29:
	movl	-848(%rbp), %eax
	cltq
	movl	-836(%rbp), %edx
	movl	%edx, -832(%rbp,%rax,4)
	jmp	.L28
.L36:
	nop
.L28:
	addl	$1, -848(%rbp)
.L25:
	movl	-848(%rbp), %eax
	cmpl	-868(%rbp), %eax
	jle	.L30
	jmp	.L31
.L35:
	nop
	movl	-876(%rbp), %eax
	cltq
	movl	-832(%rbp,%rax,4), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	solve_lowest_cost, .-solve_lowest_cost
	.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:
