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 <limits.h>
  
struct edge_t {
    int from;
    int to;
    int cost;
};

typedef struct edge_t Edge;
  
int main(void) {
    int num, i, k, from, to, cost, update;
    int nedge = 0;
    int dis[10000];
    Edge *edges, *p;
  
    edges = malloc(sizeof(Edge) * 500000);
  
    scanf("%d", &num);
  
    for (i = 0; i < num; i++){
        scanf("%d %d", &from, &k);
  
        while(k--){
            scanf("%d %d", &to, &cost);
  
            p = &edges[nedge++];
            p->from = from;
            p->to = to;
            p->cost = cost;
        }
        dis[i] = INT_MAX;
    }
    dis[0] = 0;
  
    update = 1;
    while(update){
        update = 0;
        for(i = 0; i < nedge; i++){
            from = edges[i].from;
            to = edges[i].to;
            cost = edges[i].cost;
            if(dis[from] < INT_MAX && dis[to] > cost + dis[from]){
                dis[to] = cost + dis[from];
                update = 1;
            }
        }
    }
    for(i = 0; i < num; i++){
        printf("%d %d\n", i, dis[i]);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-36864(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -40036(%rbp)
	movl	$6000000, %edi
	call	malloc@PLT
	movq	%rax, -40032(%rbp)
	leaq	-40064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40044(%rbp)
	jmp	.L2
.L5:
	leaq	-40060(%rbp), %rdx
	leaq	-40056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	leaq	-40048(%rbp), %rdx
	leaq	-40052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40036(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -40036(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -40024(%rbp)
	movl	-40056(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, (%rax)
	movl	-40052(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 4(%rax)
	movl	-40048(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 8(%rax)
.L3:
	movl	-40060(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40060(%rbp)
	testl	%eax, %eax
	jne	.L4
	movl	-40044(%rbp), %eax
	cltq
	movl	$2147483647, -40016(%rbp,%rax,4)
	addl	$1, -40044(%rbp)
.L2:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L5
	movl	$0, -40016(%rbp)
	movl	$1, -40040(%rbp)
	jmp	.L6
.L10:
	movl	$0, -40040(%rbp)
	movl	$0, -40044(%rbp)
	jmp	.L7
.L9:
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -40056(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %eax
	movl	%eax, -40052(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	8(%rax), %eax
	movl	%eax, -40048(%rbp)
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %eax
	cmpl	$2147483647, %eax
	je	.L8
	movl	-40052(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %eax
	addl	%ecx, %eax
	cmpl	%eax, %edx
	jle	.L8
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %edx
	movl	-40052(%rbp), %eax
	addl	%ecx, %edx
	cltq
	movl	%edx, -40016(%rbp,%rax,4)
	movl	$1, -40040(%rbp)
.L8:
	addl	$1, -40044(%rbp)
.L7:
	movl	-40044(%rbp), %eax
	cmpl	-40036(%rbp), %eax
	jl	.L9
.L6:
	cmpl	$0, -40040(%rbp)
	jne	.L10
	movl	$0, -40044(%rbp)
	jmp	.L11
.L12:
	movl	-40044(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40044(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40044(%rbp)
.L11:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d %d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.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	-36864(%rsp), %r11
	.cfi_def_cfa 11, 36920
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3240, %rsp
	.cfi_def_cfa_offset 40160
	movl	$6000000, %edi
	movq	%fs:40, %rax
	movq	%rax, 40088(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	.LC0(%rip), %rdi
	leaq	60(%rsp), %rsi
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	60(%rsp), %edi
	testl	%edi, %edi
	jle	.L15
	leaq	64(%rsp), %rax
	movl	%ebx, 36(%rsp)
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
	movq	%rax, 16(%rsp)
	leaq	68(%rsp), %rax
	leaq	76(%rsp), %r15
	movq	%rax, 24(%rsp)
	leaq	80(%rsp), %rax
	leaq	.LC1(%rip), %r13
	movq	%rax, (%rsp)
	.p2align 4,,10
	.p2align 3
.L5:
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	64(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 64(%rsp)
	testl	%eax, %eax
	je	.L3
	movq	8(%rsp), %rdi
	movslq	%ebp, %rax
	leaq	72(%rsp), %rbx
	leaq	(%rax,%rax,2), %rax
	leaq	(%rdi,%rax,4), %r14
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r15, %rdx
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	76(%rsp), %eax
	addl	$1, %ebp
	addq	$12, %r14
	movd	68(%rsp), %xmm0
	movd	72(%rsp), %xmm1
	movl	%eax, -4(%r14)
	movl	64(%rsp), %eax
	punpckldq	%xmm1, %xmm0
	leal	-1(%rax), %edx
	movq	%xmm0, -12(%r14)
	movl	%edx, 64(%rsp)
	testl	%eax, %eax
	jne	.L4
.L3:
	movq	(%rsp), %rax
	movl	60(%rsp), %edi
	movl	$2147483647, (%rax,%r12,4)
	addq	$1, %r12
	cmpl	%r12d, %edi
	jg	.L5
	movl	36(%rsp), %ebx
.L2:
	xorl	%ecx, %ecx
	movl	$0, 80(%rsp)
	movl	40(%rsp), %esi
	xorl	%eax, %eax
	movl	44(%rsp), %r8d
	movq	8(%rsp), %r11
	xorl	%r9d, %r9d
	cmpl	%ebp, %ecx
	jge	.L41
	.p2align 4,,10
	.p2align 3
.L9:
	movslq	%ecx, %rax
	leaq	(%rax,%rax,2), %rax
	leaq	(%r11,%rax,4), %rax
.L8:
	movslq	(%rax), %rdx
	movl	4(%rax), %esi
	addl	$1, %ecx
	movl	8(%rax), %r8d
	movq	%rdx, %rbx
	movl	80(%rsp,%rdx,4), %edx
	cmpl	$2147483647, %edx
	je	.L7
	movslq	%esi, %r10
	addl	%r8d, %edx
	cmpl	%edx, 80(%rsp,%r10,4)
	jle	.L7
	movl	%edx, 80(%rsp,%r10,4)
	addq	$12, %rax
	movl	$1, %r9d
	cmpl	%ecx, %ebp
	jg	.L8
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L7:
	movl	$1, %eax
	cmpl	%ebp, %ecx
	jl	.L9
.L41:
	testl	%r9d, %r9d
	je	.L39
	testl	%ebp, %ebp
	je	.L39
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L39:
	testb	%al, %al
	je	.L11
	movl	%r8d, 76(%rsp)
	movl	%esi, 72(%rsp)
	movl	%ebx, 68(%rsp)
.L11:
	leaq	80(%rsp), %rax
	xorl	%ebx, %ebx
	leaq	.LC2(%rip), %rbp
	movq	%rax, (%rsp)
	movq	%rax, %r12
	testl	%edi, %edi
	jle	.L13
	.p2align 4,,10
	.p2align 3
.L12:
	movl	(%r12,%rbx,4), %ecx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__printf_chk@PLT
	cmpl	%ebx, 60(%rsp)
	jg	.L12
.L13:
	movq	40088(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L42
	addq	$40104, %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
.L15:
	.cfi_restore_state
	xorl	%ebp, %ebp
	jmp	.L2
.L42:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d %d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.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	-36864(%rsp), %r11
	.cfi_def_cfa 11, 36920
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3240, %rsp
	.cfi_def_cfa_offset 40160
	movl	$6000000, %edi
	movq	%fs:40, %rax
	movq	%rax, 40088(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	.LC0(%rip), %rdi
	leaq	60(%rsp), %rsi
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	60(%rsp), %edi
	testl	%edi, %edi
	jle	.L15
	leaq	64(%rsp), %rax
	movl	%ebx, 36(%rsp)
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
	movq	%rax, 16(%rsp)
	leaq	68(%rsp), %rax
	leaq	76(%rsp), %r15
	movq	%rax, 24(%rsp)
	leaq	80(%rsp), %rax
	leaq	.LC1(%rip), %r13
	movq	%rax, (%rsp)
	.p2align 4,,10
	.p2align 3
.L5:
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	64(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 64(%rsp)
	testl	%eax, %eax
	je	.L3
	movq	8(%rsp), %rdi
	movslq	%ebp, %rax
	leaq	72(%rsp), %rbx
	leaq	(%rax,%rax,2), %rax
	leaq	(%rdi,%rax,4), %r14
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r15, %rdx
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	76(%rsp), %eax
	addl	$1, %ebp
	addq	$12, %r14
	movd	68(%rsp), %xmm0
	movd	72(%rsp), %xmm1
	movl	%eax, -4(%r14)
	movl	64(%rsp), %eax
	punpckldq	%xmm1, %xmm0
	leal	-1(%rax), %edx
	movq	%xmm0, -12(%r14)
	movl	%edx, 64(%rsp)
	testl	%eax, %eax
	jne	.L4
.L3:
	movq	(%rsp), %rax
	movl	60(%rsp), %edi
	movl	$2147483647, (%rax,%r12,4)
	addq	$1, %r12
	cmpl	%r12d, %edi
	jg	.L5
	movl	36(%rsp), %ebx
.L2:
	xorl	%ecx, %ecx
	movl	$0, 80(%rsp)
	movl	40(%rsp), %esi
	xorl	%eax, %eax
	movl	44(%rsp), %r8d
	movq	8(%rsp), %r11
	xorl	%r9d, %r9d
	cmpl	%ebp, %ecx
	jge	.L41
	.p2align 4,,10
	.p2align 3
.L9:
	movslq	%ecx, %rax
	leaq	(%rax,%rax,2), %rax
	leaq	(%r11,%rax,4), %rax
.L8:
	movslq	(%rax), %rdx
	movl	4(%rax), %esi
	addl	$1, %ecx
	movl	8(%rax), %r8d
	movq	%rdx, %rbx
	movl	80(%rsp,%rdx,4), %edx
	cmpl	$2147483647, %edx
	je	.L7
	movslq	%esi, %r10
	addl	%r8d, %edx
	cmpl	%edx, 80(%rsp,%r10,4)
	jle	.L7
	movl	%edx, 80(%rsp,%r10,4)
	addq	$12, %rax
	movl	$1, %r9d
	cmpl	%ecx, %ebp
	jg	.L8
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L7:
	movl	$1, %eax
	cmpl	%ebp, %ecx
	jl	.L9
.L41:
	testl	%r9d, %r9d
	je	.L39
	testl	%ebp, %ebp
	je	.L39
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L39:
	testb	%al, %al
	je	.L11
	movl	%r8d, 76(%rsp)
	movl	%esi, 72(%rsp)
	movl	%ebx, 68(%rsp)
.L11:
	leaq	80(%rsp), %rax
	xorl	%ebx, %ebx
	leaq	.LC2(%rip), %rbp
	movq	%rax, (%rsp)
	movq	%rax, %r12
	testl	%edi, %edi
	jle	.L13
	.p2align 4,,10
	.p2align 3
.L12:
	movl	(%r12,%rbx,4), %ecx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__printf_chk@PLT
	cmpl	%ebx, 60(%rsp)
	jg	.L12
.L13:
	movq	40088(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L42
	addq	$40104, %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
.L15:
	.cfi_restore_state
	xorl	%ebp, %ebp
	jmp	.L2
.L42:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
  
struct edge_t {
    int from;
    int to;
    int cost;
};

typedef struct edge_t Edge;
  
int main(void) {
    int num, i, k, from, to, cost, update;
    int nedge = 0;
    int dis[10000];
    Edge *edges, *p;
  
    edges = malloc(sizeof(Edge) * 500000);
  
    scanf("%d", &num);
  
    for (i = 0; i < num; i++){
        scanf("%d %d", &from, &k);
  
        while(k--){
            scanf("%d %d", &to, &cost);
  
            p = &edges[nedge++];
            p->from = from;
            p->to = to;
            p->cost = cost;
        }
        dis[i] = INT_MAX;
    }
    dis[0] = 0;
  
    update = 1;
    while(update){
        update = 0;
        for(i = 0; i < nedge; i++){
            from = edges[i].from;
            to = edges[i].to;
            cost = edges[i].cost;
            if(dis[from] < INT_MAX && dis[to] > cost + dis[from]){
                dis[to] = cost + dis[from];
                update = 1;
            }
        }
    }
    for(i = 0; i < num; i++){
        printf("%d %d\n", i, dis[i]);
    }

    return 0;
}
5
0 3 2 3 3 1 1 1
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
 5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 1 4 3
4 2 2 1 3 3
 5
0 3 2 3 3 2 1 1
1 2 0 2 4 4
2 3 0 3 0 2 4 1
3 4 2 1 0 0 1 4 4 3
4 2 2 1 3 3
 5
0 3 2 3 3 1 1 1
1 2 0 2 0 4
2 3 0 3 0 1 4 1
3 4 2 0 0 1 1 4 4 3
4 2 2 1 3 3
 5
0 3 2 3 3 2 1 1
1 2 0 2 4 4
2 3 0 3 0 2 4 2
3 4 2 1 0 0 1 4 4 3
4 2 2 1 3 3
 5
0 3 1 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 2 1 4 1
3 4 2 0 0 1 1 1 4 3
4 2 2 1 3 3
 5
0 3 2 4 3 1 1 2
1 2 3 2 3 4
2 3 0 3 3 2 4 1
3 4 0 1 0 0 1 0 4 3
4 2 0 1 3 3
 5
0 3 2 3 3 1 2 2
1 2 0 2 3 4
2 3 0 3 3 2 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
 5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 2 4 1
3 4 2 2 0 1 1 4 4 3
4 2 0 1 3 3
 5
0 3 2 4 3 1 1 2
1 2 3 3 3 4
2 3 0 3 3 2 4 1
3 4 0 1 0 -1 1 0 3 3
4 2 0 1 3 3

0 0
1 1
2 2
3 1
4 3
 0 0
1 2
2 2
3 1
4 3
 0 0
1 1
2 3
3 2
4 4
 0 0
1 1
2 1
3 1
4 2
 0 0
1 1
2 3
3 2
4 5
 0 0
1 2
2 1
3 1
4 2
 0 0
1 1
2 4
3 1
4 4
 0 0
1 5
2 2
3 1
4 3
 0 0
1 2
2 3
3 1
4 4
 0 0
1 1
2 4
3 1
4 5

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 <limits.h>
  
struct edge_t {
    int from;
    int to;
    int cost;
};

typedef struct edge_t Edge;
  
int main(void) {
    int num, i, k, from, to, cost, update;
    int nedge = 0;
    int dis[10000];
    Edge *edges, *p;
  
    edges = malloc(sizeof(Edge) * 500000);
  
    scanf("%d", &num);
  
    for (i = 0; i < num; i++){
        scanf("%d %d", &from, &k);
  
        while(k--){
            scanf("%d %d", &to, &cost);
  
            p = &edges[nedge++];
            p->from = from;
            p->to = to;
            p->cost = cost;
        }
        dis[i] = INT_MAX;
    }
    dis[0] = 0;
  
    update = 1;
    while(update){
        update = 0;
        for(i = 0; i < nedge; i++){
            from = edges[i].from;
            to = edges[i].to;
            cost = edges[i].cost;
            if(dis[from] < INT_MAX && dis[to] > cost + dis[from]){
                dis[to] = cost + dis[from];
                update = 1;
            }
        }
    }
    for(i = 0; i < num; i++){
        printf("%d %d\n", i, dis[i]);
    }

    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-36864(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -40036(%rbp)
	movl	$6000000, %edi
	call	malloc@PLT
	movq	%rax, -40032(%rbp)
	leaq	-40064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40044(%rbp)
	jmp	.L2
.L5:
	leaq	-40060(%rbp), %rdx
	leaq	-40056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	leaq	-40048(%rbp), %rdx
	leaq	-40052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40036(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -40036(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -40024(%rbp)
	movl	-40056(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, (%rax)
	movl	-40052(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 4(%rax)
	movl	-40048(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 8(%rax)
.L3:
	movl	-40060(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40060(%rbp)
	testl	%eax, %eax
	jne	.L4
	movl	-40044(%rbp), %eax
	cltq
	movl	$2147483647, -40016(%rbp,%rax,4)
	addl	$1, -40044(%rbp)
.L2:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L5
	movl	$0, -40016(%rbp)
	movl	$1, -40040(%rbp)
	jmp	.L6
.L10:
	movl	$0, -40040(%rbp)
	movl	$0, -40044(%rbp)
	jmp	.L7
.L9:
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -40056(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %eax
	movl	%eax, -40052(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	8(%rax), %eax
	movl	%eax, -40048(%rbp)
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %eax
	cmpl	$2147483647, %eax
	je	.L8
	movl	-40052(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %eax
	addl	%ecx, %eax
	cmpl	%eax, %edx
	jle	.L8
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %edx
	movl	-40052(%rbp), %eax
	addl	%ecx, %edx
	cltq
	movl	%edx, -40016(%rbp,%rax,4)
	movl	$1, -40040(%rbp)
.L8:
	addl	$1, -40044(%rbp)
.L7:
	movl	-40044(%rbp), %eax
	cmpl	-40036(%rbp), %eax
	jl	.L9
.L6:
	cmpl	$0, -40040(%rbp)
	jne	.L10
	movl	$0, -40044(%rbp)
	jmp	.L11
.L12:
	movl	-40044(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40044(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40044(%rbp)
.L11:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-36864(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -40036(%rbp)
	movl	$6000000, %edi
	call	malloc@PLT
	movq	%rax, -40032(%rbp)
	leaq	-40064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -40044(%rbp)
	jmp	.L2
.L5:
	leaq	-40060(%rbp), %rdx
	leaq	-40056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L3
.L4:
	leaq	-40048(%rbp), %rdx
	leaq	-40052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40036(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -40036(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -40024(%rbp)
	movl	-40056(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, (%rax)
	movl	-40052(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 4(%rax)
	movl	-40048(%rbp), %edx
	movq	-40024(%rbp), %rax
	movl	%edx, 8(%rax)
.L3:
	movl	-40060(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40060(%rbp)
	testl	%eax, %eax
	jne	.L4
	movl	-40044(%rbp), %eax
	cltq
	movl	$2147483647, -40016(%rbp,%rax,4)
	addl	$1, -40044(%rbp)
.L2:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L5
	movl	$0, -40016(%rbp)
	movl	$1, -40040(%rbp)
	jmp	.L6
.L10:
	movl	$0, -40040(%rbp)
	movl	$0, -40044(%rbp)
	jmp	.L7
.L9:
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -40056(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	4(%rax), %eax
	movl	%eax, -40052(%rbp)
	movl	-40044(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	movq	-40032(%rbp), %rax
	addq	%rdx, %rax
	movl	8(%rax), %eax
	movl	%eax, -40048(%rbp)
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %eax
	cmpl	$2147483647, %eax
	je	.L8
	movl	-40052(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %eax
	addl	%ecx, %eax
	cmpl	%eax, %edx
	jle	.L8
	movl	-40056(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %ecx
	movl	-40048(%rbp), %edx
	movl	-40052(%rbp), %eax
	addl	%ecx, %edx
	cltq
	movl	%edx, -40016(%rbp,%rax,4)
	movl	$1, -40040(%rbp)
.L8:
	addl	$1, -40044(%rbp)
.L7:
	movl	-40044(%rbp), %eax
	cmpl	-40036(%rbp), %eax
	jl	.L9
.L6:
	cmpl	$0, -40040(%rbp)
	jne	.L10
	movl	$0, -40044(%rbp)
	jmp	.L11
.L12:
	movl	-40044(%rbp), %eax
	cltq
	movl	-40016(%rbp,%rax,4), %edx
	movl	-40044(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -40044(%rbp)
.L11:
	movl	-40064(%rbp), %eax
	cmpl	%eax, -40044(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
