// File: MUST-Quick-Fry[P]Process-Scheduler/scheduler.cpp
// Function: Project::Scheduler::driveSJF2()
void Scheduler::driveSJF2(){

    // create a schedule
    queue<Job> pq_arr; 
    priority_queue<Job,vector<Job>,greater<Job> > wait_q; 
    int len = get_job_num();

    // clear -1
    for(int i = 0; i < len; ++i){
        if(job_queue[i].get_dur_time()==-1){ 
            int t = 0;
            find_dur_time(job_queue[i], t);
            //cout << t << endl;
            job_queue[i].set_dur_time(t);
        }
    }
         
    sort(job_queue.begin(), job_queue.end(), [](const Job &a, const Job &b)->bool
    {   if(a.get_arr_time() == b.get_arr_time()){return a.get_dur_time() < b.get_dur_time();}
        else{return a.get_arr_time() < b.get_arr_time();}
    });
         
    for(int i = 0; i < len; ++i){
        pq_arr.emplace(job_queue[i]);  
    }
       
      
    int time = 0;
    Job con;
    con.ID = 0;
    unordered_map<int, int> jobmap;
    Job lastjob = con;
    
    while(true){                                          
        while(!pq_arr.empty() && time == pq_arr.front().get_arr_time()){
            Job tmp = pq_arr.front();
            pq_arr.pop(); 
            
            if(!wait_q.empty() && tmp.get_dur_time() < wait_q.top().get_dur_time() && wait_q.top().ID == lastjob.ID)
                wait_q.pop();
            wait_q.emplace(tmp);         
        }
        
   
        if(!wait_q.empty()){
            
            Job it = wait_q.top();
            wait_q.pop();
            
            if(lastjob.ID == it.ID || lastjob.ID == 0){
            
                if(jobmap[it.ID] == 0){
                    scheduler.emplace(it);
                    jobmap[it.ID] = 1;
                }
            
                it.has_exp_time++;
                it.set_dur_time(it.get_dur_time()-1);
                           
                if(it.get_dur_time() == 0){
                    scheduler.back().set_dur_time(it.has_exp_time);
                    scheduler.back().service_time_left = 2;
                    //cout << scheduler.back().ID << " arr " << scheduler.back().get_arr_time() << " dur "<< scheduler.back().get_dur_time()<< endl;
                    jobmap[it.ID] = 0;
                    lastjob = con;
                }
                else{ 
                    if(wait_q.empty() || it.get_dur_time() < wait_q.top().get_dur_time())
                        wait_q.emplace(it); 
                        
                    lastjob = it;
                }
                
            }
            else{
                scheduler.back().set_dur_time(lastjob.has_exp_time);
                //cout << scheduler.back().ID << " arr " << scheduler.back().get_arr_time() << " dur "<< scheduler.back().get_dur_time()<< endl;
                jobmap[lastjob.ID] = 0;
                lastjob.has_exp_time = 0;
                lastjob.set_arr_time(time);
                wait_q.emplace(lastjob);
                
             
                if(jobmap[it.ID] == 0){
                    scheduler.emplace(it);
                    jobmap[it.ID] = 1;
                }
            
                it.has_exp_time++;
                it.set_dur_time(it.get_dur_time()-1);
                
                
                if(it.get_dur_time() == 0){
                    scheduler.back().set_dur_time(it.has_exp_time);
                    scheduler.back().service_time_left = 2;
                    //cout << scheduler.back().ID << " arr " << scheduler.back().get_arr_time() << " dur "<< scheduler.back().get_dur_time()<< endl;
                    jobmap[it.ID] = 0;
                    lastjob = con;
                }
                else{ 
                    if(wait_q.empty() || it.get_dur_time() < wait_q.top().get_dur_time())
                        wait_q.emplace(it); 
                        
                    lastjob = it;
                }            
                
            }
                
                
        }
        
        time++;
        //cout << "now is " << time << " " << wait_q.size() << endl;
        if(wait_q.empty() && pq_arr.empty()){break;}    
    }
    
       
    // copy
    set_total_time(time);
    real_job_queue = scheduler;
    cout << endl;
    cout << endl;
    cout << endl;
    
    // execute
    cout << "==================================================="<< endl;
    cout << "Now start the Scheduler !!!"<< endl;
    cout << "==================================================="<< endl;
    
    int realtime = 0;
    int pid = 1;
   
    while(!stop_flag){
     
        cout << "now time: " << realtime << " s" << endl;    
        
        while(!scheduler.empty() && realtime >= scheduler.front().get_arr_time()){
            auto it = scheduler.front();
            scheduler.pop();
                        
            if(monitor_map[it.ID]==0){
                pid = fork();
                if(pid == 0){
                    Monitor* monitor = new Monitor(it);                       
                    cout << "Terminate the Parent Process: " << getpid() <<endl;     
                    
                    //kill(getpid(), SIGKILL);
                    exit(0);
  
                }
                else{ 
                    monitor_map[it.ID]=pid;
                }
            }
            
            
            if(pid !=0){     
                                           
                     if(allow_preem){                 
                         allow_preem = false;                                  
                         this_job = it;
                         
                         kill(monitor_map[it.ID], SIGCONT);
                         signal(SIGALRM, signal_preemSJF);
                         alarm(it.get_dur_time());
 
                     }
                     else{
                         wait_queue.emplace(it);
                         kill(monitor_map[it.ID], SIGTSTP);
                         std::cout<<"Child Process Suspend" << std::endl;
                     }
                 
             }
        }
        
        
        if(pid!=0){       
             sleep(1); 
             realtime++;
                          
        }
                        
    }
    
    if(pid !=0){ 
        cout << "now time: " << realtime << " s" << endl;       
        sleep(2);
        cout << endl;
        cout << endl;
        
        // draw Gantt diagram
        Display(real_job_queue);

    }
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x580, %rsp            # imm = 0x580
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x3c0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4230
leaq -0x78(%rbp), %rdi
callq 0xf9d0
jmp 0xa73e
movq -0x3c0(%rbp), %rdi
callq 0x86a0
movl %eax, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0xa877
movslq -0x8c(%rbp), %rsi
leaq 0x19106(%rip), %rdi     # 0x23880
callq 0xf730
movq %rax, %rdi
callq 0x5b30
movl %eax, -0x3c4(%rbp)
jmp 0xa78f
movl -0x3c4(%rbp), %eax
cmpl $-0x1, %eax
jne 0xa861
movl $0x0, -0x90(%rbp)
movslq -0x8c(%rbp), %rsi
leaq 0x190ca(%rip), %rdi     # 0x23880
callq 0xf730
movq %rax, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x5c00
jmp 0xa7cc
movq -0x3c0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x9240
jmp 0xa7e8
leaq -0xe8(%rbp), %rdi
callq 0x4190
movslq -0x8c(%rbp), %rsi
leaq 0x1907e(%rip), %rdi     # 0x23880
callq 0xf730
movq %rax, %rdi
movl -0x90(%rbp), %esi
callq 0x5aa0
jmp 0xa817
jmp 0xa861
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb6db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb6d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4190
jmp 0xb6d2
jmp 0xa863
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xa75a
leaq 0x19002(%rip), %rdi     # 0x23880
movq %rdi, -0x3d0(%rbp)
callq 0xf800
movq -0x3d0(%rbp), %rdi
movq %rax, -0xf0(%rbp)
callq 0xf830
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0xccf0
jmp 0xa8b9
movl $0x0, -0x100(%rbp)
movl -0x100(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0xa905
movslq -0x100(%rbp), %rsi
leaq 0x18fa1(%rip), %rdi     # 0x23880
callq 0xf730
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0xf860
jmp 0xa8f2
jmp 0xa8f4
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0xa8c3
movl $0x0, -0x104(%rbp)
leaq -0x160(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x4160
movl $0x0, -0x134(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x4280
movq -0x3d8(%rbp), %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x5c00
jmp 0xa94d
jmp 0xa94f
jmp 0xa951
jmp 0xa953
leaq -0x58(%rbp), %rdi
callq 0xf8c0
movb %al, -0x3d9(%rbp)
jmp 0xa964
movb -0x3d9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3da(%rbp)
jne 0xa9c2
jmp 0xa979
movl -0x104(%rbp), %eax
movl %eax, -0x3ec(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xf8e0
movq %rax, -0x3e8(%rbp)
jmp 0xa997
movq -0x3e8(%rbp), %rdi
callq 0x5b10
movl %eax, -0x3f0(%rbp)
jmp 0xa9ab
movl -0x3ec(%rbp), %eax
movl -0x3f0(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x3da(%rbp)
movb -0x3da(%rbp), %al
testb $0x1, %al
jne 0xa9d1
jmp 0xab0a
leaq -0x58(%rbp), %rdi
callq 0xf8e0
movq %rax, -0x3f8(%rbp)
jmp 0xa9e3
movq -0x3f8(%rbp), %rsi
leaq -0x248(%rbp), %rdi
callq 0x5c00
jmp 0xa9f8
leaq -0x58(%rbp), %rdi
callq 0xf900
jmp 0xaa03
leaq -0x78(%rbp), %rdi
callq 0xfa00
movb %al, -0x3f9(%rbp)
jmp 0xaa14
movb -0x3f9(%rbp), %al
testb $0x1, %al
jne 0xaae7
jmp 0xaa24
leaq -0x248(%rbp), %rdi
callq 0x5b30
movl %eax, -0x400(%rbp)
jmp 0xaa38
leaq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x408(%rbp)
jmp 0xaa4a
movq -0x408(%rbp), %rdi
callq 0x5b30
movl %eax, -0x40c(%rbp)
jmp 0xaa5e
movl -0x400(%rbp), %eax
movl -0x40c(%rbp), %ecx
cmpl %ecx, %eax
jge 0xaae7
leaq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x418(%rbp)
jmp 0xaa80
movq -0x418(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x1c4(%rbp), %eax
jne 0xaae7
leaq -0x78(%rbp), %rdi
callq 0xfa40
jmp 0xaa9d
jmp 0xaae7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb6ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb6ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x4190
jmp 0xb6ae
leaq -0x78(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xfa90
jmp 0xaaf9
leaq -0x248(%rbp), %rdi
callq 0x4190
jmp 0xa953
leaq -0x78(%rbp), %rdi
callq 0xfa00
movb %al, -0x419(%rbp)
jmp 0xab1b
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0xaff3
jmp 0xab2b
leaq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x428(%rbp)
jmp 0xab3d
movq -0x428(%rbp), %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x5c00
jmp 0xab52
leaq -0x78(%rbp), %rdi
callq 0xfa40
jmp 0xab5d
movl -0x1c4(%rbp), %eax
cmpl -0x274(%rbp), %eax
je 0xab78
cmpl $0x0, -0x1c4(%rbp)
jne 0xad81
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x430(%rbp)
jmp 0xab94
movq -0x430(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xac00
leaq 0x18cf1(%rip), %rdi     # 0x23898
leaq -0x2a0(%rbp), %rsi
callq 0xf860
jmp 0xabb5
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x438(%rbp)
jmp 0xabd1
movq -0x438(%rbp), %rax
movl $0x1, (%rax)
jmp 0xac00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x4190
jmp 0xb6ae
movl -0x26c(%rbp), %eax
incl %eax
movl %eax, -0x26c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x43c(%rbp)
jmp 0xac22
movl -0x43c(%rbp), %esi
decl %esi
leaq -0x2a0(%rbp), %rdi
callq 0x5aa0
jmp 0xac38
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x440(%rbp)
jmp 0xac4c
movl -0x440(%rbp), %eax
cmpl $0x0, %eax
jne 0xacea
leaq 0x18c36(%rip), %rdi     # 0x23898
callq 0xfb00
movq %rax, -0x448(%rbp)
jmp 0xac70
movq -0x448(%rbp), %rdi
movl -0x26c(%rbp), %esi
callq 0x5aa0
jmp 0xac84
leaq 0x18c0d(%rip), %rdi     # 0x23898
callq 0xfb00
movq %rax, -0x450(%rbp)
jmp 0xac99
movq -0x450(%rbp), %rax
movl $0x2, 0x30(%rax)
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x458(%rbp)
jmp 0xacc3
movq -0x458(%rbp), %rax
movl $0x0, (%rax)
leaq -0x1f0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xf950
jmp 0xace5
jmp 0xad7c
leaq -0x78(%rbp), %rdi
callq 0xfa00
movb %al, -0x459(%rbp)
jmp 0xacfb
movb -0x459(%rbp), %al
testb $0x1, %al
jne 0xad51
jmp 0xad07
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x460(%rbp)
jmp 0xad1b
leaq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x468(%rbp)
jmp 0xad2d
movq -0x468(%rbp), %rdi
callq 0x5b30
movl %eax, -0x46c(%rbp)
jmp 0xad41
movl -0x460(%rbp), %eax
movl -0x46c(%rbp), %ecx
cmpl %ecx, %eax
jge 0xad65
leaq -0x78(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xfa90
jmp 0xad63
jmp 0xad65
leaq -0x1f0(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xf950
jmp 0xad7a
jmp 0xad7c
jmp 0xafe7
leaq 0x18b10(%rip), %rdi     # 0x23898
callq 0xfb00
movq %rax, -0x478(%rbp)
jmp 0xad96
movq -0x478(%rbp), %rdi
movl -0x1bc(%rbp), %esi
callq 0x5aa0
jmp 0xadaa
leaq -0x1c4(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x480(%rbp)
jmp 0xadc6
movq -0x480(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x1bc(%rbp)
movl -0x104(%rbp), %esi
leaq -0x1f0(%rbp), %rdi
callq 0x5a80
jmp 0xadf1
leaq -0x78(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0xfa90
jmp 0xae03
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x488(%rbp)
jmp 0xae1f
movq -0x488(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xae69
leaq 0x18a66(%rip), %rdi     # 0x23898
leaq -0x2a0(%rbp), %rsi
callq 0xf860
jmp 0xae40
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x490(%rbp)
jmp 0xae5c
movq -0x490(%rbp), %rax
movl $0x1, (%rax)
movl -0x26c(%rbp), %eax
incl %eax
movl %eax, -0x26c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x494(%rbp)
jmp 0xae8b
movl -0x494(%rbp), %esi
decl %esi
leaq -0x2a0(%rbp), %rdi
callq 0x5aa0
jmp 0xaea1
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x498(%rbp)
jmp 0xaeb5
movl -0x498(%rbp), %eax
cmpl $0x0, %eax
jne 0xaf53
leaq 0x189cd(%rip), %rdi     # 0x23898
callq 0xfb00
movq %rax, -0x4a0(%rbp)
jmp 0xaed9
movq -0x4a0(%rbp), %rdi
movl -0x26c(%rbp), %esi
callq 0x5aa0
jmp 0xaeed
leaq 0x189a4(%rip), %rdi     # 0x23898
callq 0xfb00
movq %rax, -0x4a8(%rbp)
jmp 0xaf02
movq -0x4a8(%rbp), %rax
movl $0x2, 0x30(%rax)
leaq -0x274(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0xf920
movq %rax, -0x4b0(%rbp)
jmp 0xaf2c
movq -0x4b0(%rbp), %rax
movl $0x0, (%rax)
leaq -0x1f0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0xf950
jmp 0xaf4e
jmp 0xafe5
leaq -0x78(%rbp), %rdi
callq 0xfa00
movb %al, -0x4b1(%rbp)
jmp 0xaf64
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0xafba
jmp 0xaf70
leaq -0x2a0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x4b8(%rbp)
jmp 0xaf84
leaq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x4c0(%rbp)
jmp 0xaf96
movq -0x4c0(%rbp), %rdi
callq 0x5b30
movl %eax, -0x4c4(%rbp)
jmp 0xafaa
movl -0x4b8(%rbp), %eax
movl -0x4c4(%rbp), %ecx
cmpl %ecx, %eax
jge 0xafce
leaq -0x78(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xfa90
jmp 0xafcc
jmp 0xafce
leaq -0x1f0(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0xf950
jmp 0xafe3
jmp 0xafe5
jmp 0xafe7
leaq -0x2a0(%rbp), %rdi
callq 0x4190
movl -0x104(%rbp), %eax
incl %eax
movl %eax, -0x104(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xfa00
movb %al, -0x4c5(%rbp)
jmp 0xb012
movb -0x4c5(%rbp), %al
testb $0x1, %al
jne 0xb01e
jmp 0xb03d
leaq -0x58(%rbp), %rdi
callq 0xf8c0
movb %al, -0x4c6(%rbp)
jmp 0xb02f
movb -0x4c6(%rbp), %al
testb $0x1, %al
jne 0xb03b
jmp 0xb03d
jmp 0xb042
jmp 0xa94f
movq -0x3c0(%rbp), %rdi
movl -0x104(%rbp), %esi
callq 0x8660
leaq 0x188dd(%rip), %rdi     # 0x23938
leaq 0x18836(%rip), %rsi     # 0x23898
callq 0xf890
jmp 0xb069
movq 0x17f50(%rip), %rdi     # 0x22fc0
movq 0x17f39(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb07e
movq 0x17f3b(%rip), %rdi     # 0x22fc0
movq 0x17f24(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb093
movq 0x17f26(%rip), %rdi     # 0x22fc0
movq 0x17f0f(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb0a8
movq 0x17f11(%rip), %rdi     # 0x22fc0
leaq 0xe24b(%rip), %rsi      # 0x19301
callq 0x3270
movq %rax, -0x4d0(%rbp)
jmp 0xb0c4
movq -0x4d0(%rbp), %rdi
movq 0x17ede(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb0d9
movq 0x17ee0(%rip), %rdi     # 0x22fc0
leaq 0xe186(%rip), %rsi      # 0x1926d
callq 0x3270
movq %rax, -0x4d8(%rbp)
jmp 0xb0f5
movq -0x4d8(%rbp), %rdi
movq 0x17ead(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb10a
movq 0x17eaf(%rip), %rdi     # 0x22fc0
leaq 0xe1e9(%rip), %rsi      # 0x19301
callq 0x3270
movq %rax, -0x4e0(%rbp)
jmp 0xb126
movq -0x4e0(%rbp), %rdi
movq 0x17e7c(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb13b
movl $0x0, -0x2a4(%rbp)
movl $0x1, -0x2a8(%rbp)
movb 0x188a3(%rip), %al      # 0x239f8
xorb $-0x1, %al
testb $0x1, %al
jne 0xb160
jmp 0xb56f
movq 0x17e59(%rip), %rdi     # 0x22fc0
leaq 0xe11b(%rip), %rsi      # 0x19289
callq 0x3270
movq %rax, -0x4e8(%rbp)
jmp 0xb17c
movq -0x4e8(%rbp), %rdi
movl -0x2a4(%rbp), %esi
callq 0x3440
movq %rax, -0x4f0(%rbp)
jmp 0xb197
movq -0x4f0(%rbp), %rdi
leaq 0xe0ef(%rip), %rsi      # 0x19294
callq 0x3270
movq %rax, -0x4f8(%rbp)
jmp 0xb1b3
movq -0x4f8(%rbp), %rdi
movq 0x17def(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb1c8
jmp 0xb1ca
leaq 0x186c7(%rip), %rdi     # 0x23898
callq 0xf8c0
movb %al, -0x4f9(%rbp)
jmp 0xb1de
movb -0x4f9(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x4fa(%rbp)
jne 0xb23f
jmp 0xb1f3
movl -0x2a4(%rbp), %eax
movl %eax, -0x50c(%rbp)
leaq 0x18692(%rip), %rdi     # 0x23898
callq 0xf8e0
movq %rax, -0x508(%rbp)
jmp 0xb214
movq -0x508(%rbp), %rdi
callq 0x5b10
movl %eax, -0x510(%rbp)
jmp 0xb228
movl -0x50c(%rbp), %eax
movl -0x510(%rbp), %ecx
cmpl %ecx, %eax
setge %al
movb %al, -0x4fa(%rbp)
movb -0x4fa(%rbp), %al
testb $0x1, %al
jne 0xb24e
jmp 0xb546
leaq 0x18643(%rip), %rdi     # 0x23898
callq 0xf8e0
movq %rax, -0x518(%rbp)
jmp 0xb263
movq -0x518(%rbp), %rsi
leaq -0x300(%rbp), %rdi
callq 0x5c00
jmp 0xb278
leaq 0x18619(%rip), %rdi     # 0x23898
callq 0xf900
jmp 0xb286
leaq -0x2d4(%rbp), %rsi
leaq 0x1872c(%rip), %rdi     # 0x239c0
callq 0xf920
movq %rax, -0x520(%rbp)
jmp 0xb2a2
movq -0x520(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xb418
callq 0x30a0
movl %eax, -0x2a8(%rbp)
cmpl $0x0, -0x2a8(%rbp)
jne 0xb3df
movl $0xd0, %edi
callq 0x3280
movq %rax, -0x528(%rbp)
jmp 0xb2dd
movb $0x1, -0x361(%rbp)
leaq -0x360(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x5c00
jmp 0xb2f9
movq -0x528(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x5ec0
jmp 0xb30e
movb $0x0, -0x361(%rbp)
leaq -0x360(%rbp), %rdi
callq 0x4190
movq -0x528(%rbp), %rax
movq %rax, -0x308(%rbp)
movq 0x17c8a(%rip), %rdi     # 0x22fc0
leaq 0xdf5a(%rip), %rsi      # 0x19297
callq 0x3270
movq %rax, -0x530(%rbp)
jmp 0xb34b
callq 0x3390
movq -0x530(%rbp), %rdi
movl %eax, %esi
callq 0x3440
movq %rax, -0x538(%rbp)
jmp 0xb367
movq -0x538(%rbp), %rdi
movq 0x17c3b(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb37c
xorl %edi, %edi
callq 0x32e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb3c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x360(%rbp), %rdi
callq 0x4190
testb $0x1, -0x361(%rbp)
jne 0xb3ce
jmp 0xb3da
movq -0x528(%rbp), %rdi
callq 0x3250
jmp 0xb535
movl -0x2a8(%rbp), %eax
movl %eax, -0x544(%rbp)
leaq -0x2d4(%rbp), %rsi
leaq 0x185c7(%rip), %rdi     # 0x239c0
callq 0xf920
movq %rax, -0x540(%rbp)
jmp 0xb407
movq -0x540(%rbp), %rax
movl -0x544(%rbp), %ecx
movl %ecx, (%rax)
jmp 0xb418
cmpl $0x0, -0x2a8(%rbp)
je 0xb524
testb $0x1, 0x17e5c(%rip)     # 0x23288
je 0xb4ab
movb $0x0, 0x17e53(%rip)     # 0x23288
leaq 0x183ec(%rip), %rdi     # 0x23828
leaq -0x300(%rbp), %rsi
callq 0xf950
jmp 0xb44a
leaq -0x2d4(%rbp), %rsi
leaq 0x18568(%rip), %rdi     # 0x239c0
callq 0xf920
movq %rax, -0x550(%rbp)
jmp 0xb466
movq -0x550(%rbp), %rax
movl (%rax), %edi
movl $0x12, %esi
callq 0x3360
leaq 0x18b0(%rip), %rsi      # 0xcd30
movl $0xe, %edi
callq 0x32d0
leaq -0x300(%rbp), %rdi
callq 0x5b30
movl %eax, -0x554(%rbp)
jmp 0xb49e
movl -0x554(%rbp), %edi
callq 0x3480
jmp 0xb522
leaq 0x18436(%rip), %rdi     # 0x238e8
leaq -0x300(%rbp), %rsi
callq 0xf860
jmp 0xb4c0
leaq -0x2d4(%rbp), %rsi
leaq 0x184f2(%rip), %rdi     # 0x239c0
callq 0xf920
movq %rax, -0x560(%rbp)
jmp 0xb4dc
movq -0x560(%rbp), %rax
movl (%rax), %edi
movl $0x14, %esi
callq 0x3360
movq 0x17aca(%rip), %rdi     # 0x22fc0
leaq 0xddb9(%rip), %rsi      # 0x192b6
callq 0x3270
movq %rax, -0x568(%rbp)
jmp 0xb50b
movq -0x568(%rbp), %rdi
movq 0x17a97(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb520
jmp 0xb522
jmp 0xb524
leaq -0x300(%rbp), %rdi
callq 0x4190
jmp 0xb1ca
leaq -0x300(%rbp), %rdi
callq 0x4190
jmp 0xb6ae
cmpl $0x0, -0x2a8(%rbp)
je 0xb56a
movl $0x1, %edi
callq 0x31e0
jmp 0xb55b
movl -0x2a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a4(%rbp)
jmp 0xb14f
cmpl $0x0, -0x2a8(%rbp)
je 0xb66f
movq 0x17a3d(%rip), %rdi     # 0x22fc0
leaq 0xdcff(%rip), %rsi      # 0x19289
callq 0x3270
movq %rax, -0x570(%rbp)
jmp 0xb598
movq -0x570(%rbp), %rdi
movl -0x2a4(%rbp), %esi
callq 0x3440
movq %rax, -0x578(%rbp)
jmp 0xb5b3
movq -0x578(%rbp), %rdi
leaq 0xdcd3(%rip), %rsi      # 0x19294
callq 0x3270
movq %rax, -0x580(%rbp)
jmp 0xb5cf
movq -0x580(%rbp), %rdi
movq 0x179d3(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb5e4
movl $0x2, %edi
callq 0x31e0
jmp 0xb5f0
movq 0x179c9(%rip), %rdi     # 0x22fc0
movq 0x179b2(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb605
movq 0x179b4(%rip), %rdi     # 0x22fc0
movq 0x1799d(%rip), %rsi     # 0x22fb0
callq 0x3290
jmp 0xb61a
leaq 0x18317(%rip), %rsi     # 0x23938
leaq -0x3b8(%rbp), %rdi
callq 0xf9a0
jmp 0xb62f
movq -0x3c0(%rbp), %rdi
leaq -0x3b8(%rbp), %rsi
callq 0xc530
jmp 0xb644
leaq -0x3b8(%rbp), %rdi
callq 0x4260
jmp 0xb66f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x4260
jmp 0xb6ae
leaq -0x1f0(%rbp), %rdi
callq 0x4190
leaq -0x198(%rbp), %rdi
callq 0x42a0
leaq -0x160(%rbp), %rdi
callq 0x4190
leaq -0x78(%rbp), %rdi
callq 0xfae0
leaq -0x58(%rbp), %rdi
callq 0x4260
addq $0x580, %rsp            # imm = 0x580
popq %rbp
retq
leaq -0x1f0(%rbp), %rdi
callq 0x4190
leaq -0x198(%rbp), %rdi
callq 0x42a0
leaq -0x160(%rbp), %rdi
callq 0x4190
leaq -0x78(%rbp), %rdi
callq 0xfae0
leaq -0x58(%rbp), %rdi
callq 0x4260
movq -0x80(%rbp), %rdi
callq 0x3450
nopl (%rax)