// File: /workspace/github_cpp_makefile_star2_O1/suyunu[P]Discrete-Event-Simulation/RandQueuing.cpp
// Function: RandQueuing::simulate()
void RandQueuing::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 = whereToGoRand(current);
			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());
			}
			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 $0x98, %rsp
movq %rdi, %rbx
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0x268c
leaq 0x28(%rbx), %rax
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %r12
leaq -0xb0(%rbp), %r13
movq 0x28(%rbx), %rdi
movq 0x30(%rbx), %rax
cmpq %rax, %rdi
je 0x318c
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x21, %rcx
jl 0x2fae
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 0x3934
movq %r12, %rdi
callq 0x26a6
movq %r13, %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)
cmpl $-0x1, -0x58(%rbp)
je 0x31a7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3272
movl %eax, %r15d
movq 0x20(%rbx), %rax
movslq -0x58(%rbp), %rcx
imulq $0x70, %rcx, %rcx
movq 0x40(%rax,%rcx), %rdx
cmpq 0x20(%rax,%rcx), %rdx
je 0x3087
leaq (%rax,%rcx), %rdi
addq $0x10, %rdi
incl 0x54(%rdi)
movq 0x10(%rdi), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
callq 0x3a7c
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 0x3091
movaps -0x50(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x20, 0x30(%rbx)
jmp 0x30a1
movb $0x0, 0x6c(%rax,%rcx)
jmp 0x3173
movq -0xb8(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x36dc
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
movups -0x20(%rcx), %xmm0
movups -0x10(%rcx), %xmm1
movaps %xmm1, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movupd -0x20(%rcx), %xmm0
movupd -0x10(%rcx), %xmm1
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
leaq -0x1(%rdx), %rcx
movapd %xmm0, -0x90(%rbp)
movapd %xmm1, -0x80(%rbp)
cmpq $0x2, %rdx
jl 0x313a
movsd -0x80(%rbp), %xmm0
leaq -0x1(%rcx), %rdx
shrq $0x3f, %rdx
addq %rcx, %rdx
decq %rdx
sarq %rdx
movq %rdx, %rsi
shlq $0x5, %rsi
movsd 0x10(%rax,%rsi), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x313a
addq %rax, %rsi
movq %rcx, %rdi
shlq $0x5, %rdi
movupd (%rsi), %xmm1
movups 0xc(%rsi), %xmm2
movups %xmm2, 0xc(%rax,%rdi)
movupd %xmm1, (%rax,%rdi)
cmpq $0x2, %rcx
movq %rdx, %rcx
jg 0x30ef
jmp 0x313d
movq %rcx, %rdx
shlq $0x5, %rdx
movups -0x84(%rbp), %xmm0
movups %xmm0, 0xc(%rax,%rdx)
movapd -0x90(%rbp), %xmm0
movupd %xmm0, (%rax,%rdx)
movq %r12, %rdi
callq 0x26a6
movq %r13, %rdi
callq 0x26a6
leaq -0x50(%rbp), %rdi
callq 0x26a6
cmpl $-0x1, %r15d
je 0x2f2e
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x31f2
leaq -0x70(%rbp), %rdi
callq 0x26a6
addq $0x98, %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 0x31f2
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x31d4
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x26a6
leaq -0xb0(%rbp), %rdi
callq 0x26a6
jmp 0x31e0
jmp 0x31dd
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x26a6
movq %rbx, %rdi
callq 0x2250
nop