// File: /workspace/github_cpp_makefile_star2_O3/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 $0x268, %rsp            # imm = 0x268
movl %edi, %ebx
leaq 0x1af0(%rip), %rsi      # 0x4103
leaq -0x290(%rbp), %r14
movq %r14, %rdi
movl $0x10, %edx
callq 0x2190
movq %r14, %rdi
callq 0x2200
xorl %r13d, %r13d
leaq -0x90(%rbp), %r14
leaq -0x50(%rbp), %r15
leaq -0x34(%rbp), %r12
movl $0x10, -0x34(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x60(%rbp)
movl $0x40, %edx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
movq %r15, %r8
movq %r12, %r9
callq 0x2120
cmpl $-0x1, %eax
je 0x2641
testl %eax, %eax
jle 0x2641
movq %r13, -0x40(%rbp)
movq %r14, %rdi
leaq 0x1fff(%rip), %r13      # 0x468b
movq %r13, %rsi
callq 0x2260
movq %rax, %rdi
callq 0x2250
movl %eax, -0x30(%rbp)
xorl %edi, %edi
movq %r13, %rsi
callq 0x2260
movq %rax, %rdi
callq 0x2250
movl %eax, -0x2c(%rbp)
movzwl -0x4e(%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %eax
cmpl $0x79d4, %eax           # imm = 0x79D4
je 0x2750
cmpl $0x75ec, %eax           # imm = 0x75EC
jne 0x27cb
movl $0x49, %edx
movq 0x38ef(%rip), %rdi      # 0x5fd0
leaq 0x2006(%rip), %rsi      # 0x46ee
callq 0x21c0
movq 0x38dc(%rip), %rdi      # 0x5fd0
movl -0x30(%rbp), %esi
callq 0x2280
movq %rax, %r13
movl $0x1a, %edx
movq %rax, %rdi
leaq 0x202a(%rip), %rsi      # 0x4738
callq 0x21c0
movq %r13, %rdi
movl -0x2c(%rbp), %esi
callq 0x2280
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
xorl %r13d, %r13d
jmp 0x2844
movl $0x49, %edx
movq 0x3874(%rip), %rdi      # 0x5fd0
leaq 0x1ff0(%rip), %rsi      # 0x4753
callq 0x21c0
movq 0x3861(%rip), %rdi      # 0x5fd0
movl -0x30(%rbp), %esi
callq 0x2280
movq %rax, %r13
movl $0x1a, %edx
movq %rax, %rdi
leaq 0x1faf(%rip), %rsi      # 0x4738
callq 0x21c0
movq %r13, %rdi
movl -0x2c(%rbp), %esi
callq 0x2280
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movl $0x1, %r13d
movq %rax, %rdi
callq 0x2100
jmp 0x2844
movl $0x49, %edx
movq 0x37f9(%rip), %rdi      # 0x5fd0
leaq 0x1fbf(%rip), %rsi      # 0x479d
callq 0x21c0
movq 0x37e6(%rip), %rdi      # 0x5fd0
movl -0x30(%rbp), %esi
callq 0x2280
movq %rax, %r13
movl $0x1a, %edx
movq %rax, %rdi
leaq 0x1f34(%rip), %rsi      # 0x4738
callq 0x21c0
movq %r13, %rdi
movl -0x2c(%rbp), %esi
callq 0x2280
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movl $0x2, %r13d
movq %rax, %rdi
callq 0x2100
movl $0x60, %edx
movq 0x3780(%rip), %rdi      # 0x5fd0
leaq 0x1e36(%rip), %rsi      # 0x468d
callq 0x21c0
movq 0x376d(%rip), %rcx      # 0x5fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0x374f(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x2100
movups -0x50(%rbp), %xmm0
leaq (,%r13,4), %rax
addq %r13, %rax
leaq 0x38f4(%rip), %rcx      # 0x6198
movl -0x30(%rbp), %edx
movl %edx, 0x10(%rcx,%rax,8)
movl -0x2c(%rbp), %edx
movl %edx, 0x14(%rcx,%rax,8)
movups %xmm0, (%rcx,%rax,8)
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
movq %rdx, 0x18(%rcx,%rax,8)
movq -0x40(%rbp), %rax
incl %eax
cmpl $0x3, %eax
movq %rax, %r13
jne 0x2641
movq 0x36ea(%rip), %rax      # 0x5fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x288(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x290(%rbp,%rcx)
callq 0x2140
leaq -0x198(%rbp), %rdi
callq 0x20b0
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2923
jmp 0x2923
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x2290