// File: /workspace/github_cpp_makefile_star2_O2/gty980218[P]ee450/scheduler.cpp
// Function: init_sche(int)
void init_sche(int sock){
    ofstream out_file("info.txt",ios::out);                         //when start scheduler,clean the info.txt
    out_file.close();

    char buff[64]={0};
    struct sockaddr_in hosaddr;
    socklen_t hoslen;
    int n;
    int init_times=0;
    while(1){                                                       //waiting for hospital A/B/C to send their capability and occupancy
        hoslen=sizeof(hosaddr);
        memset(buff,0,sizeof(buff));
        n=recvfrom(sock,buff,sizeof(buff),0,(struct sockaddr*)&hosaddr,&hoslen); //get initialized info from hospitals and get their IP and port #
        if(n==-1){
           continue;
        }else if(n>0){
            char *pch;
            pch=strtok(buff," ");
            int cpblt=atoi(pch);
            pch=strtok(NULL," ");
            int ocpt=atoi(pch);
            int port;
            if(ntohs(hosaddr.sin_port)==30188){
                port=0;
                cout<<"The Scheduler has received information from Hospital A:total capacity is "<<cpblt<<" and initial occupancy is "<<ocpt<<endl;
            }else if(ntohs(hosaddr.sin_port)==31188){
                port=1;
                cout<<"The Scheduler has received information from Hospital B:total capacity is "<<cpblt<<" and initial occupancy is "<<ocpt<<endl;
            }else{
                port=2;
                cout<<"The Scheduler has received information from Hospital C:total capacity is "<<cpblt<<" and initial occupancy is "<<ocpt<<endl;
            }
            cout<<"------------------------------------------------------------------------------------------------"<<endl;
            scheduler.init_info(port,cpblt,ocpt,hosaddr);
            init_times+=1;
            if(init_times==3){
                break;
            }
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movl %edi, %ebx
leaq 0x1ba8(%rip), %rsi      # 0x4103
leaq -0x2a0(%rbp), %r14
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x2170
movq %r14, %rdi
callq 0x21c0
xorl %eax, %eax
leaq -0xa0(%rbp), %r14
pushq $0x40
popq %r15
leaq -0x58(%rbp), %r12
leaq -0x3c(%rbp), %r13
movq %rax, -0x48(%rbp)
movl $0x10, -0x3c(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
movq %r12, %r8
movq %r13, %r9
callq 0x2120
cmpl $-0x1, %eax
je 0x258e
testl %eax, %eax
jle 0x258e
movq %r14, %rdi
leaq 0x20b5(%rip), %rsi      # 0x468b
callq 0x2210
movq %rax, %rdi
callq 0x2200
movl %eax, -0x30(%rbp)
xorl %edi, %edi
leaq 0x209c(%rip), %rsi      # 0x468b
callq 0x2210
movq %rax, %rdi
callq 0x2200
movl %eax, -0x2c(%rbp)
movzwl -0x56(%rbp), %eax
rolw $0x8, %ax
cmpw $0x79d4, %ax            # imm = 0x79D4
je 0x2668
movzwl %ax, %eax
cmpl $0x75ec, %eax           # imm = 0x75EC
jne 0x26b1
movq 0x39ae(%rip), %rdi      # 0x5fd0
leaq 0x20c5(%rip), %rsi      # 0x46ee
callq 0x2160
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x2230
movq %rax, %rdi
leaq 0x20f5(%rip), %rsi      # 0x4738
callq 0x2160
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x2230
movq %rax, %rdi
callq 0x20e0
movq $0x0, -0x38(%rbp)
jmp 0x26f8
movq 0x3961(%rip), %rdi      # 0x5fd0
leaq 0x20dd(%rip), %rsi      # 0x4753
callq 0x2160
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x2230
movq %rax, %rdi
leaq 0x20a8(%rip), %rsi      # 0x4738
callq 0x2160
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x2230
movq %rax, %rdi
callq 0x20e0
pushq $0x1
popq %rax
movq %rax, -0x38(%rbp)
jmp 0x26f8
movq 0x3918(%rip), %rdi      # 0x5fd0
leaq 0x20de(%rip), %rsi      # 0x479d
callq 0x2160
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x2230
movq %rax, %rdi
leaq 0x205f(%rip), %rsi      # 0x4738
callq 0x2160
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x2230
movq %rax, %rdi
callq 0x20e0
pushq $0x2
popq %rax
movq %rax, -0x38(%rbp)
movq 0x38d1(%rip), %rdi      # 0x5fd0
leaq 0x1f87(%rip), %rsi      # 0x468d
callq 0x2160
movq %rax, %rdi
callq 0x20e0
movups -0x58(%rbp), %xmm0
imulq $0x28, -0x38(%rbp), %rax
leaq 0x3a4d(%rip), %rcx      # 0x6170
movl -0x30(%rbp), %edx
movl %edx, 0x10(%rax,%rcx)
movl -0x2c(%rbp), %edx
movl %edx, 0x14(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
movq %rdx, 0x18(%rax,%rcx)
movq -0x48(%rbp), %rax
incl %eax
cmpl $0x3, %eax
jne 0x258a
leaq -0x2a0(%rbp), %rdi
callq 0x21e0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2775
jmp 0x2775
movq %rax, %rbx
leaq -0x2a0(%rbp), %rdi
callq 0x21e0
movq %rbx, %rdi
callq 0x2240