// File: gty980218[P]ee450/hospitalC.cpp
// Function: init(int)
Dist_list* init(int loc){                               // input the location #
    double** dist_map=readTxt("map.txt");                  //load the map.txt and create indice mapping and distance graph

    map<int, int>::iterator iter;
    iter=indice_map.find(loc);                          //find the indice mapped to location #
    if(iter!=indice_map.end()){                         //determine if the location exists
        int indice=iter->second;
        int size=indice_map.size();
        Dist_list *dist_list;
        dist_list=new Dist_list[size];                  //to store the shortest path from loc

        for(int i=0;i<size;i++){                         //initialize the dist_list
            if(dist_map[indice][i]==0){
                dist_list[i].val=-1;
            }else{
                dist_list[i].val=dist_map[indice][i];
            }
            dist_list[i].vstd=false;
        }
        dist_list[indice].vstd=true;
        
        while(true){                           
            double min=-1;
            int num=-1;
            for(int i=0;i<size;i++){                    //find the shortest path in each round
                if(!dist_list[i].vstd && dist_list[i].val!=-1){
                    if(min==-1){
                        min=dist_list[i].val;
                        num=i;
                    }else{
                        if(dist_list[i].val<min){
                            min=dist_list[i].val;
                            num=i;
                        }
                    }
                }
            }
            if(num==-1){                                 //done, time to quit the loop
                break;
            }
            dist_list[num].vstd=true;
            for(int i=0;i<size;i++){                     // according to the candidate points, update the dist_list
                if(dist_map[num][i]!=0 && !dist_list[i].vstd){
                    if(dist_list[i].val==-1 || (min+dist_map[num][i])<dist_list[i].val){
                        dist_list[i].val=min+dist_map[num][i];
                    }
                }
            }
        }
        dist_list[indice].val=0;
        return dist_list;
    }else{
        fprintf(stderr,"Location not found !\n");
        exit(1);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x4(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x2400
movq -0x98(%rbp), %rdx
leaq 0x3bd6(%rip), %rsi      # 0x6342
leaq -0x30(%rbp), %rdi
callq 0x3e80
jmp 0x2777
leaq -0x30(%rbp), %rdi
callq 0x3630
movq %rax, -0xa0(%rbp)
jmp 0x2789
leaq -0x30(%rbp), %rdi
callq 0x2150
leaq -0x31(%rbp), %rdi
callq 0x22c0
movq -0xa0(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3f30
leaq 0x6aa2(%rip), %rdi      # 0x9258
leaq -0x4(%rbp), %rsi
callq 0x3f50
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x6a86(%rip), %rdi      # 0x9258
callq 0x3fb0
movq %rax, -0x60(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3f80
testb $0x1, %al
jne 0x27f1
jmp 0x2b8f
leaq -0x50(%rbp), %rdi
callq 0x3fe0
movl 0x4(%rax), %eax
movl %eax, -0x64(%rbp)
leaq 0x6a51(%rip), %rdi      # 0x9258
callq 0x3e60
movl %eax, -0x68(%rbp)
movslq -0x68(%rbp), %rax
movl $0x10, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x2903
movq -0x10(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x74(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28ba
jp 0x28ba
movq -0x70(%rbp), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x3786(%rip), %xmm0     # 0x6008
movsd %xmm0, 0x8(%rax)
jmp 0x28e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x28ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2150
leaq -0x31(%rbp), %rdi
callq 0x22c0
jmp 0x2bb1
movq -0x10(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x74(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x70(%rbp), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq -0x70(%rbp), %rax
movslq -0x74(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x283f
movq -0x70(%rbp), %rax
movslq -0x64(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x1, (%rax)
movsd 0x36eb(%rip), %xmm0     # 0x6008
movsd %xmm0, -0x80(%rbp)
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x2a2f
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
testb $0x1, (%rax)
jne 0x2a19
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd 0x3689(%rip), %xmm1     # 0x6008
ucomisd %xmm1, %xmm0
jne 0x298c
jp 0x298c
jmp 0x2a19
movsd -0x80(%rbp), %xmm0
movsd 0x366f(%rip), %xmm1     # 0x6008
ucomisd %xmm1, %xmm0
jne 0x29cb
jp 0x29cb
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x2a17
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm1
movsd -0x80(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2a15
movq -0x70(%rbp), %rax
movslq -0x88(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x2a17
jmp 0x2a19
jmp 0x2a1b
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x2936
cmpl $-0x1, -0x84(%rbp)
jne 0x2a3d
jmp 0x2b6b
movq -0x70(%rbp), %rax
movslq -0x84(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x1, (%rax)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x2b66
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2a96
jp 0x2a96
jmp 0x2b50
movq -0x70(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
testb $0x1, (%rax)
jne 0x2b50
movq -0x70(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd 0x3538(%rip), %xmm1     # 0x6008
ucomisd %xmm1, %xmm0
jne 0x2ada
jp 0x2ada
jmp 0x2b17
movsd -0x80(%rbp), %xmm1
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8c(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm1
movq -0x70(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2b4e
movsd -0x80(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8c(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movq -0x70(%rbp), %rax
movslq -0x8c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
jmp 0x2b50
jmp 0x2b52
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x2a5c
jmp 0x2915
movq -0x70(%rbp), %rax
movslq -0x64(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x70(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq 0x6442(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x37aa(%rip), %rsi      # 0x634a
movb $0x0, %al
callq 0x2360
movl $0x1, %edi
callq 0x2300
movq -0x40(%rbp), %rdi
callq 0x23f0
nopw (%rax,%rax)