// File: /workspace/github_cpp_makefile_star2_O3/suyunu[P]Discrete-Event-Simulation/MinQueuing.cpp
// Function: MinQueuing::simulate()
void MinQueuing::simulate(){
	Job current;
	
	while(!order.empty()){
		pop_heap(order.begin(),order.end(),greater1());
		current = order.back();
		order.pop_back();
		
		currentTime = current.timeToGo;
		
		if(current.cond == -1){
			work(current, 0);
		}
		else{
			int toGo = whereToGoMin(current);
			/* If the queue is not empty, the next job in the queue starts to be processed:
			 * The function calculates the check-out time for the job (currentTime + units[current.cond].procTime)
			 * and pushes it to the heap
			 */
			if(!units[current.cond].jobQ.empty()){
				units[current.cond].Jcounter++;
				Job temp = units[current.cond].jobQ.front();
				units[current.cond].jobQ.pop();
				
				temp.timeToGo = currentTime + units[current.cond].procTime;
				jobs[temp.no] = temp;
				
				order.push_back(temp);
				push_heap (order.begin(),order.end(),greater1());
			}
			// Sets the status of the unit as not working.
			else
				units[current.cond].isWorking = false;
			
			if(toGo != -1)
				work(current, toGo);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
leaq -0x70(%rbp), %rdi
callq 0x268c
leaq 0x28(%rbx), %r15
leaq -0x90(%rbp), %r12
movq 0x28(%rbx), %rdi
movq 0x30(%rbx), %rax
cmpq %rax, %rdi
je 0x449b
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x21, %rcx
jl 0x42cb
leaq -0x20(%rax), %rdx
movups -0x20(%rax), %xmm0
movups -0x10(%rax), %xmm1
movaps %xmm1, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movups (%rdi), %xmm0
movups 0xc(%rdi), %xmm1
movups %xmm1, -0x14(%rax)
movups %xmm0, -0x20(%rax)
subq %rdi, %rdx
sarq $0x5, %rdx
movaps -0xb0(%rbp), %xmm0
movaps -0xa0(%rbp), %xmm1
movaps %xmm0, -0x90(%rbp)
movaps %xmm1, -0x80(%rbp)
xorl %esi, %esi
movq %r12, %rcx
callq 0x3921
movq %r12, %rdi
callq 0x26a6
leaq -0xb0(%rbp), %rdi
callq 0x26a6
movq 0x30(%rbx), %rax
leaq -0x20(%rax), %rdi
movups -0x20(%rax), %xmm0
movupd -0x14(%rax), %xmm1
movupd %xmm1, -0x64(%rbp)
movaps %xmm0, -0x70(%rbp)
movq %rdi, 0x30(%rbx)
callq 0x26a6
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x8(%rbx)
movslq -0x58(%rbp), %r13
cmpq $-0x1, %r13
je 0x44b6
movq %rbx, %rdi
leaq -0x70(%rbp), %rsi
callq 0x4580
movl %eax, %r14d
movq 0x20(%rbx), %rax
imulq $0x70, %r13, %rdx
movq 0x20(%rax,%rdx), %rcx
cmpq %rcx, 0x40(%rax,%rdx)
je 0x43a4
leaq (%rax,%rdx), %rdi
addq $0x10, %rdi
incl 0x54(%rdi)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
callq 0x3a68
movsd 0x8(%rbx), %xmm0
movq 0x20(%rbx), %rax
movslq -0x58(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addsd 0x8(%rax,%rcx), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x18(%rbx), %rax
movslq -0x50(%rbp), %rcx
shlq $0x5, %rcx
movups -0x44(%rbp), %xmm0
movups %xmm0, 0xc(%rax,%rcx)
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rax,%rcx)
movq 0x30(%rbx), %rsi
cmpq 0x38(%rbx), %rsi
je 0x43ae
movaps -0x50(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
movq 0x30(%rbx), %rdx
addq $0x20, %rdx
movq %rdx, 0x30(%rbx)
jmp 0x43be
movb $0x0, 0x6c(%rax,%rdx)
jmp 0x4482
movq %r15, %rdi
leaq -0x50(%rbp), %rdx
callq 0x36e8
movq 0x30(%rbx), %rdx
movq (%r15), %rax
movups -0x20(%rdx), %xmm0
movups -0x10(%rdx), %xmm1
movaps %xmm1, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movq %rdx, %rsi
subq %rax, %rsi
sarq $0x5, %rsi
leaq -0x1(%rsi), %rcx
movupd -0x20(%rdx), %xmm0
movupd -0x10(%rdx), %xmm1
movapd %xmm0, -0x90(%rbp)
movapd %xmm1, -0x80(%rbp)
cmpq $0x2, %rsi
jl 0x4448
movsd -0x80(%rbp), %xmm0
leaq -0x1(%rcx), %rdx
movq %rdx, %rsi
shrq %rsi
movq %rsi, %rdi
shlq $0x5, %rdi
movsd 0x10(%rax,%rdi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4448
addq %rax, %rdi
shlq $0x5, %rcx
movupd (%rdi), %xmm1
movups 0xc(%rdi), %xmm2
movups %xmm2, 0xc(%rax,%rcx)
movupd %xmm1, (%rax,%rcx)
movq %rsi, %rcx
cmpq $0x1, %rdx
ja 0x4407
xorl %ecx, %ecx
shlq $0x5, %rcx
movups -0x84(%rbp), %xmm0
movups %xmm0, 0xc(%rax,%rcx)
movapd -0x90(%rbp), %xmm0
movupd %xmm0, (%rax,%rcx)
movq %r12, %rdi
callq 0x26a6
leaq -0xb0(%rbp), %rdi
callq 0x26a6
leaq -0x50(%rbp), %rdi
callq 0x26a6
cmpl $-0x1, %r14d
je 0x4243
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x4500
leaq -0x70(%rbp), %rdi
callq 0x26a6
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4500
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x44e3
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x26a6
leaq -0xb0(%rbp), %rdi
callq 0x26a6
jmp 0x44ef
jmp 0x44ec
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x26a6
movq %rbx, %rdi
callq 0x2250