// File: 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
subq $0x320, %rsp            # imm = 0x320
movl %edi, -0x4(%rbp)
leaq 0x192e(%rip), %rsi      # 0x4103
leaq -0x208(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
movl $0x10, %edx
callq 0x2210
movq -0x2b0(%rbp), %rdi
callq 0x22c0
jmp 0x27fb
leaq -0x260(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x2110
movl $0x0, -0x27c(%rbp)
jmp 0x281a
movl $0x10, -0x274(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x230(%rbp)
movaps %xmm0, -0x240(%rbp)
movaps %xmm0, -0x250(%rbp)
movaps %xmm0, -0x260(%rbp)
movl -0x4(%rbp), %edi
leaq -0x260(%rbp), %rsi
movl $0x40, %edx
xorl %ecx, %ecx
leaq -0x270(%rbp), %r8
leaq -0x274(%rbp), %r9
callq 0x2180
movq %rax, -0x2b8(%rbp)
jmp 0x2870
movq -0x2b8(%rbp), %rax
movl %eax, -0x278(%rbp)
cmpl $-0x1, -0x278(%rbp)
jne 0x28ab
jmp 0x2818
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x210(%rbp)
movl %eax, -0x214(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x2300
jmp 0x2ba7
cmpl $0x0, -0x278(%rbp)
jle 0x2b8b
leaq -0x260(%rbp), %rdi
leaq 0x1dc5(%rip), %rsi      # 0x468b
callq 0x2330
movq %rax, -0x288(%rbp)
movq -0x288(%rbp), %rdi
callq 0x2320
movl %eax, -0x28c(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x1d9c(%rip), %rsi      # 0x468b
callq 0x2330
movq %rax, -0x288(%rbp)
movq -0x288(%rbp), %rdi
callq 0x2320
movl %eax, -0x290(%rbp)
movzwl -0x26e(%rbp), %edi
callq 0x23a0
movzwl %ax, %eax
cmpl $0x75ec, %eax           # imm = 0x75EC
jne 0x29b9
movl $0x0, -0x294(%rbp)
movq 0x3698(%rip), %rdi      # 0x5fd0
leaq 0x1daf(%rip), %rsi      # 0x46ee
callq 0x21d0
movq %rax, -0x2c0(%rbp)
jmp 0x294d
movq -0x2c0(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x2360
movq %rax, -0x2c8(%rbp)
jmp 0x2968
movq -0x2c8(%rbp), %rdi
leaq 0x1dc2(%rip), %rsi      # 0x4738
callq 0x21d0
movq %rax, -0x2d0(%rbp)
jmp 0x2984
movq -0x2d0(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x2360
movq %rax, -0x2d8(%rbp)
jmp 0x299f
movq -0x2d8(%rbp), %rdi
movq 0x3613(%rip), %rsi      # 0x5fc0
callq 0x21e0
jmp 0x29b4
jmp 0x2af6
movzwl -0x26e(%rbp), %edi
callq 0x23a0
movzwl %ax, %eax
cmpl $0x79d4, %eax           # imm = 0x79D4
jne 0x2a65
movl $0x1, -0x294(%rbp)
movq 0x35ec(%rip), %rdi      # 0x5fd0
leaq 0x1d68(%rip), %rsi      # 0x4753
callq 0x21d0
movq %rax, -0x2e0(%rbp)
jmp 0x29f9
movq -0x2e0(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x2360
movq %rax, -0x2e8(%rbp)
jmp 0x2a14
movq -0x2e8(%rbp), %rdi
leaq 0x1d16(%rip), %rsi      # 0x4738
callq 0x21d0
movq %rax, -0x2f0(%rbp)
jmp 0x2a30
movq -0x2f0(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x2360
movq %rax, -0x2f8(%rbp)
jmp 0x2a4b
movq -0x2f8(%rbp), %rdi
movq 0x3567(%rip), %rsi      # 0x5fc0
callq 0x21e0
jmp 0x2a60
jmp 0x2af4
movl $0x2, -0x294(%rbp)
movq 0x355a(%rip), %rdi      # 0x5fd0
leaq 0x1d20(%rip), %rsi      # 0x479d
callq 0x21d0
movq %rax, -0x300(%rbp)
jmp 0x2a8b
movq -0x300(%rbp), %rdi
movl -0x28c(%rbp), %esi
callq 0x2360
movq %rax, -0x308(%rbp)
jmp 0x2aa6
movq -0x308(%rbp), %rdi
leaq 0x1c84(%rip), %rsi      # 0x4738
callq 0x21d0
movq %rax, -0x310(%rbp)
jmp 0x2ac2
movq -0x310(%rbp), %rdi
movl -0x290(%rbp), %esi
callq 0x2360
movq %rax, -0x318(%rbp)
jmp 0x2add
movq -0x318(%rbp), %rdi
movq 0x34d5(%rip), %rsi      # 0x5fc0
callq 0x21e0
jmp 0x2af2
jmp 0x2af4
jmp 0x2af6
movq 0x34d3(%rip), %rdi      # 0x5fd0
leaq 0x1b89(%rip), %rsi      # 0x468d
callq 0x21d0
movq %rax, -0x320(%rbp)
jmp 0x2b12
movq -0x320(%rbp), %rdi
movq 0x34a0(%rip), %rsi      # 0x5fc0
callq 0x21e0
jmp 0x2b27
movl -0x294(%rbp), %esi
movl -0x28c(%rbp), %edx
movl -0x290(%rbp), %ecx
movq -0x270(%rbp), %rax
movq %rax, -0x2a4(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x29c(%rbp)
movq -0x2a4(%rbp), %r8
movq -0x29c(%rbp), %r9
leaq 0x36ae(%rip), %rdi      # 0x6218
callq 0x2520
movl -0x27c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27c(%rbp)
cmpl $0x3, -0x27c(%rbp)
jne 0x2b89
jmp 0x2b92
jmp 0x2b8b
jmp 0x2b8d
jmp 0x2818
leaq -0x208(%rbp), %rdi
callq 0x2300
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0x210(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)