// File: /workspace/github_cpp_makefile_star2_O1/marcellapantarotto[P]pseudoSO/scheduler.cpp
// Function: Scheduler::simulation()
void Scheduler::simulation() {
	Process p;
	unsigned int offset;
	processOrder();
	startTime();

	while(stillExistsProcess()) {
		fillQueue();
		if(nextProcess(&p)){
			if(!p.inMemory()) {
				offset = m.allocation(p.getAmoutBlocks(),p.getPriority());
				if(offset==MAX_MEM)	{
					cout << "\a\tERROR : MEMORY NOT ALLOCATED TO PROCESS " << p.getPID() << endl;
					p.setPriority(p.getPriority()+1);
					if(p.getPriority() > 3) {
						p.setPriority(3);
					}
					addEndQueue(p);
					clock++;
					continue;
				}
				else if(offset > MAX_MEM){
					p.setExecutionTime(0);
					cout << "\a\tERROR : MEMORY IS BIGGER THEN THE TOTAL " << endl;
					clock++;
					continue;
				}
				else
					p.setMemoryOffset(offset);
			}

			dispatcher(p);
			if(p.getExecutionTime() > 0) {
				p.setPriority(p.getPriority()+1);
				if(p.getPriority() > 3)
					p.setPriority(3);
				addEndQueue(p);
			}
			else {
				cout << "\tProcess " << p.getPID() << " received SIGINT" << endl;
				m.deallocation(p.getMemoryOffset(),p.getAmoutBlocks());
				p.freeResources();
			}
		}
		else{
			clock++;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
callq 0x31a4
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x32d0
testb %al, %al
je 0x4032
leaq 0x160(%rbx), %r14
leaq -0x48(%rbp), %r15
movq 0x41ef(%rip), %r12      # 0x7fd0
movq %rbx, %rdi
callq 0x3026
movq %rbx, %rdi
movq %r15, %rsi
callq 0x320a
testb %al, %al
je 0x3f7d
movq %r15, %rdi
callq 0x2c46
testb %al, %al
je 0x3e6e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x37f4
movq %r15, %rdi
callq 0x2b72
testl %eax, %eax
jle 0x3f94
movq %r15, %rdi
callq 0x2b52
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x2b56
movq %r15, %rdi
callq 0x2b52
cmpl $0x4, %eax
jl 0x3e50
movq %r15, %rdi
movl $0x3, %esi
callq 0x2b56
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2f04
jmp 0x3f7f
movq %r15, %rdi
callq 0x2b62
movl %eax, %r13d
movq %r15, %rdi
callq 0x2b52
movq %r14, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x2d0a
cmpl $0x400, %eax            # imm = 0x400
jne 0x3f31
movl $0x2a, %edx
movq %r12, %rdi
leaq 0x136c(%rip), %rsi      # 0x5214
callq 0x2180
movq %r15, %rdi
callq 0x2b4a
movq %r12, %rdi
movl %eax, %esi
callq 0x2220
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x2b52
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x2b56
movq %r15, %rdi
callq 0x2b52
cmpl $0x4, %eax
jl 0x3f16
movq %r15, %rdi
movl $0x3, %esi
callq 0x2b56
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2f04
jmp 0x3f7d
movq %r15, %rdi
jbe 0x4026
xorl %esi, %esi
callq 0x2b76
movl $0x2a, %edx
movq %r12, %rdi
leaq 0x12ef(%rip), %rsi      # 0x523f
callq 0x2180
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
incl (%rbx)
movq %rbx, %rdi
callq 0x32d0
testb %al, %al
jne 0x3de1
jmp 0x4032
movl $0x9, %edx
movq %r12, %rdi
leaq 0x12c7(%rip), %rsi      # 0x526a
callq 0x2180
movq %r15, %rdi
callq 0x2b4a
movq %r12, %rdi
movl %eax, %esi
callq 0x2220
movq %rax, %r13
movl $0x10, %edx
movq %rax, %rdi
leaq 0x12a8(%rip), %rsi      # 0x5274
callq 0x2180
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x2b5a
movl %eax, %r13d
movq %r15, %rdi
callq 0x2b62
movq %r14, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x2e3e
movq %r15, %rdi
callq 0x2c0c
jmp 0x3f7f
movl %eax, %esi
callq 0x2b5e
jmp 0x3e08
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop