// File: /workspace/github_cpp_makefile_star2_O3/gty980218[P]ee450/hospitalC.cpp
// Function: serve(int, Hospital&)
void serve(int sock,Hospital& hospital){
    char buff[64]={0};
    struct sockaddr_in cliaddr;                                                 //client address
    socklen_t clilen;
    int n;
    while(1){
        clilen=sizeof(cliaddr);
        memset(buff,0,sizeof(buff));
        n=recvfrom(sock,buff,sizeof(buff),0,(struct sockaddr*)&cliaddr,&clilen);
        if(n==-1){
            continue;
        }else if(n>0){
            string rev_str=buff;
            if(rev_str.compare("assigned")==0){                                 //assigned response
                hospital.occupancy+=1;
                double avil=1.0*(hospital.capacity-hospital.occupancy)/hospital.capacity;
                cout<<"Hospital C has been assigned to a client, occupancy updated to "<<hospital.occupancy<<", availability is updated to "<<avil<<endl;
            }else{                                                              //availability response
                int loc=atoi(buff);
                cout<<"Hospital C has received input from client at location "<<loc<<endl;
                double dist=-1;
                double avil=0;
                double score=0;
                if(loc!=hospital.location){
                    map<int, int>::iterator iter;
                    iter=indice_map.find(loc);
                    if(iter!=indice_map.end()){                                     //loc exits
                        dist=hospital.dist_list[iter->second].val;
                        avil=1.0*(hospital.capacity-hospital.occupancy)/hospital.capacity;
                        if(avil<0){
                            avil=-1;
                        }
                        score=1/(dist*(1.1-avil)); 
                        cout<<"Hospital C has capacity = "<<hospital.capacity<<" ,occupancy= "<<hospital.occupancy<<" , availability = "<<avil<<endl;
                        cout<<"Hospital C has found the shortest path to client,distance = "<<dist<<endl;
                        cout<<"Hospital C has the score = "<<score<<endl;
                    }else{
                        cout<<"Hospital C does not have the location "<<loc<<" in map"<<endl;
                        cout<<"Hospital C has sent \" location not found\" to the Scheduler"<<endl;
                    }                   
                }
                memset(buff,0,sizeof(buff));
                if(dist==-1 || avil==-1){
                    strcpy(buff,"-1 -1");
                }else{
                    stringstream ss;
                    ss<<score<<" "<<dist;
                    string str=ss.str();
                    strcpy(buff,str.c_str());
                    cout<<"Hospital C has sent score = "<<score<<" and distance= "<<dist<<" to the Scheduler"<<endl;
                }
                sendto(sock, buff, sizeof(buff), 0, (struct sockaddr*)&cliaddr, clilen);
            }    
        }
        cout<<"------------------------------------------------------------------------------------------------"<<endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, -0x30(%rbp)
movl %edi, -0x3c(%rbp)
movq 0x3531(%rip), %r13      # 0x5fd0
movl $0x10, -0x40(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movapd %xmm0, -0x80(%rbp)
movapd %xmm0, -0x70(%rbp)
movapd %xmm0, -0x60(%rbp)
movl $0x40, %edx
movl -0x3c(%rbp), %edi
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xf0(%rbp), %r8
leaq -0x40(%rbp), %r9
callq 0x2190
cmpl $-0x1, %eax
je 0x2a9f
testl %eax, %eax
jle 0x2d81
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0x2100
leaq (%rax,%rbp), %rdx
addq $-0x90, %rdx
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x36d2
movq %r14, %rdi
leaq 0x1647(%rip), %rsi      # 0x417a
callq 0x20d0
testl %eax, %eax
je 0x2cd0
movq %rbx, %rdi
callq 0x2290
movl %eax, %r12d
movl $0x36, %edx
movq %r13, %rdi
leaq 0x1687(%rip), %rsi      # 0x41e1
callq 0x2230
movq %r13, %rdi
movl %r12d, %esi
callq 0x22e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0x30(%rbp), %rax
cmpl 0x8(%rax), %r12d
je 0x2c7c
movq 0x3627(%rip), %rcx      # 0x61d0
testq %rcx, %rcx
je 0x2be2
leaq 0x3613(%rip), %rax      # 0x61c8
xorl %edx, %edx
cmpl %r12d, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0x2bb5
leaq 0x35f5(%rip), %rcx      # 0x61c8
cmpq %rcx, %rax
je 0x2be2
cmpl 0x20(%rax), %r12d
jge 0x2dc2
movl $0x26, %edx
movq %r13, %rdi
leaq 0x16bc(%rip), %rsi      # 0x42ad
callq 0x2230
movq %r13, %rdi
movl %r12d, %esi
callq 0x22e0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x16c1(%rip), %rsi      # 0x42d4
callq 0x2230
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movl $0x3a, %edx
movq %r13, %rdi
leaq 0x168d(%rip), %rsi      # 0x42dc
callq 0x2230
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
xorpd %xmm0, %xmm0
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, -0x70(%rbp)
movapd %xmm0, -0x80(%rbp)
movapd %xmm0, -0x90(%rbp)
movw $0x31, -0x8c(%rbp)
movl $0x2d20312d, -0x90(%rbp) # imm = 0x2D20312D
movl -0x40(%rbp), %r9d
movl $0x40, %edx
movl -0x3c(%rbp), %edi
leaq -0x90(%rbp), %rsi
xorl %ecx, %ecx
leaq -0xf0(%rbp), %r8
callq 0x2050
jmp 0x2d5f
movq -0x30(%rbp), %rax
movl (%rax), %ebx
movl 0x4(%rax), %r14d
incl %r14d
movl %r14d, 0x4(%rax)
movl $0x3f, %edx
movq %r13, %rdi
leaq 0x1493(%rip), %rsi      # 0x4183
callq 0x2230
movq -0x30(%rbp), %rax
movl 0x4(%rax), %esi
movq %r13, %rdi
callq 0x22e0
movq %rax, %r12
movl $0x1d, %edx
movq %rax, %rdi
leaq 0x14ad(%rip), %rsi      # 0x41c3
callq 0x2230
cvtsi2sd %ebx, %xmm1
subl %r14d, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x22c0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x2d81
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2200
movl $0x60, %edx
movq %r13, %rdi
leaq 0x1389(%rip), %rsi      # 0x4119
callq 0x2230
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
jmp 0x2a9f
movq -0x30(%rbp), %rdx
movq 0x10(%rdx), %rcx
movslq 0x24(%rax), %rax
shlq $0x4, %rax
movsd 0x8(%rcx,%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movl (%rdx), %r15d
movl %r15d, %ebx
subl 0x4(%rdx), %ebx
movl $0x1a, %edx
movq %r13, %rdi
leaq 0x1423(%rip), %rsi      # 0x4218
callq 0x2230
movq -0x30(%rbp), %rax
movl (%rax), %esi
movq %r13, %rdi
callq 0x22e0
movq %rax, %r14
movl $0xd, %edx
movq %rax, %rdi
leaq 0x1419(%rip), %rsi      # 0x4233
callq 0x2230
movq -0x30(%rbp), %rax
movl 0x4(%rax), %esi
movq %r14, %rdi
callq 0x22e0
movq %rax, %r12
movl $0x12, %edx
movq %rax, %rdi
leaq 0x1401(%rip), %rsi      # 0x4241
callq 0x2230
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r15d, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm2
cmpltsd 0x11be(%rip), %xmm2     # 0x4020
movapd %xmm2, %xmm1
andnpd %xmm0, %xmm1
movsd 0x1196(%rip), %xmm0     # 0x4008
andpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movq %r12, %rdi
movapd %xmm2, -0xe0(%rbp)
movapd %xmm2, %xmm0
callq 0x22c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movl $0x3c, %edx
movq %r13, %rdi
leaq 0x138d(%rip), %rsi      # 0x4254
callq 0x2230
movq %r13, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x22c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movl $0x1b, %edx
movq %r13, %rdi
leaq 0x137f(%rip), %rsi      # 0x4291
callq 0x2230
movsd 0x10f1(%rip), %xmm0     # 0x4010
subsd -0xe0(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movsd 0x10e4(%rip), %xmm1     # 0x4018
divsd %xmm0, %xmm1
movq %r13, %rdi
movsd %xmm1, -0x48(%rbp)
movapd %xmm1, %xmm0
callq 0x22c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
xorpd %xmm0, %xmm0
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, -0x70(%rbp)
movapd %xmm0, -0x80(%rbp)
movapd %xmm0, -0x90(%rbp)
movsd -0x38(%rbp), %xmm0
ucomisd 0x106d(%rip), %xmm0     # 0x4008
jne 0x2fa3
jnp 0x2c97
movapd -0xe0(%rbp), %xmm0
ucomisd 0x1055(%rip), %xmm0     # 0x4008
jne 0x2fbb
jnp 0x2c97
leaq -0x278(%rbp), %rdi
callq 0x2160
leaq -0x268(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
callq 0x22c0
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x12a5(%rip), %rsi      # 0x428f
callq 0x2230
movq %r14, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x22c0
leaq -0xd0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x22b0
movq -0xd0(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x21c0
movl $0x1c, %edx
movq %r13, %rdi
leaq 0x12ec(%rip), %rsi      # 0x431d
callq 0x2230
movq %r13, %rdi
movsd -0x48(%rbp), %xmm0
callq 0x22c0
movq %rax, %r14
movl $0xf, %edx
movq %rax, %rdi
leaq 0x12e5(%rip), %rsi      # 0x433a
callq 0x2230
movq %r14, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x22c0
movq %rax, %r12
movl $0x11, %edx
movq %rax, %rdi
leaq 0x128c(%rip), %rsi      # 0x4305
callq 0x2230
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x30c8
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2200
leaq -0x278(%rbp), %rdi
movq 0x2ee2(%rip), %rsi      # 0x5fb8
callq 0x2180
leaq -0x1f8(%rbp), %rdi
callq 0x20e0
jmp 0x2caa
jmp 0x30f0
jmp 0x3141
movq %rax, %rbx
jmp 0x311a
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x311a
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2200
movq 0x2e97(%rip), %rsi      # 0x5fb8
leaq -0x278(%rbp), %rdi
callq 0x2180
leaq -0x1f8(%rbp), %rdi
callq 0x20e0
jmp 0x3144
jmp 0x3141
jmp 0x3141
jmp 0x3141
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3166
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x22f0