// File: 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
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x2820
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
callq 0x4900
xorb $-0x1, %al
testb $0x1, %al
jne 0x3f0e
jmp 0x417a
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0x98(%rbp)
callq 0x4820
movq -0x98(%rbp), %rdi
movq %rax, -0x30(%rbp)
callq 0x4850
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4940
jmp 0x3f48
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
callq 0x49b0
movq -0x90(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x18(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0x10(%rbp)
addq $0x28, %rdi
callq 0x49f0
movq -0x90(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
cmpl $-0x1, -0x10(%rbp)
jne 0x3fc6
movq -0x90(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x41a0
jmp 0x3fb0
jmp 0x4175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x418c
movq -0x90(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4340
movl %eax, -0x9c(%rbp)
jmp 0x3fde
movq -0x90(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl %ecx, -0x50(%rbp)
movq 0x20(%rax), %rax
movslq -0x10(%rbp), %rcx
imulq $0x70, %rcx, %rcx
leaq 0x10(%rax,%rcx), %rdi
callq 0x4a20
movb %al, -0x9d(%rbp)
jmp 0x400c
movb -0x9d(%rbp), %al
testb $0x1, %al
jne 0x413c
jmp 0x401c
movq -0x90(%rbp), %rax
movq 0x20(%rax), %rcx
movslq -0x10(%rbp), %rdx
imulq $0x70, %rdx, %rdx
movl 0x64(%rcx,%rdx), %esi
incl %esi
movl %esi, 0x64(%rcx,%rdx)
movq 0x20(%rax), %rax
movslq -0x10(%rbp), %rcx
imulq $0x70, %rcx, %rcx
leaq 0x10(%rax,%rcx), %rdi
callq 0x4a40
movq %rax, -0xa8(%rbp)
jmp 0x4058
movq -0x90(%rbp), %rax
movq -0xa8(%rbp), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movq 0x20(%rax), %rax
movslq -0x10(%rbp), %rcx
imulq $0x70, %rcx, %rcx
leaq 0x10(%rax,%rcx), %rdi
callq 0x4a60
jmp 0x408d
movq -0x90(%rbp), %rdi
movsd 0x8(%rdi), %xmm0
movq 0x20(%rdi), %rax
movslq -0x10(%rbp), %rcx
imulq $0x70, %rcx, %rcx
movsd 0x8(%rax,%rcx), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq 0x18(%rdi), %rax
movslq -0x70(%rbp), %rcx
shlq $0x5, %rcx
movups -0x64(%rbp), %xmm0
movups %xmm0, 0xc(%rax,%rcx)
movaps -0x70(%rbp), %xmm0
movups %xmm0, (%rax,%rcx)
addq $0x28, %rdi
leaq -0x70(%rbp), %rsi
callq 0x4770
jmp 0x40e0
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0xb0(%rbp)
callq 0x4820
movq -0xb0(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x4850
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x4a80
jmp 0x411a
leaq -0x70(%rbp), %rdi
callq 0x2850
jmp 0x4156
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2850
jmp 0x418c
movq -0x90(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x10(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x6c(%rax)
cmpl $-0x1, -0x50(%rbp)
je 0x4173
movq -0x90(%rbp), %rdi
movl -0x50(%rbp), %edx
leaq -0x28(%rbp), %rsi
callq 0x41a0
jmp 0x4171
jmp 0x4173
jmp 0x4175
jmp 0x3ef3
leaq -0x28(%rbp), %rdi
callq 0x2850
addq $0xb0, %rsp
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x2850
movq -0x48(%rbp), %rdi
callq 0x2280
nop