// File: /workspace/github_cpp_makefile_star2_O3/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 0x31b2
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x32de
testb %al, %al
je 0x4040
leaq 0x160(%rbx), %r14
leaq -0x48(%rbp), %r15
movq 0x41e1(%rip), %r12      # 0x7fd0
movq %rbx, %rdi
callq 0x302a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3218
testb %al, %al
je 0x3f8b
movq %r15, %rdi
callq 0x2c52
testb %al, %al
je 0x3e7c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3802
movq %r15, %rdi
callq 0x2b7e
testl %eax, %eax
jle 0x3fa2
movq %r15, %rdi
callq 0x2b5e
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x2b62
movq %r15, %rdi
callq 0x2b5e
cmpl $0x4, %eax
jl 0x3e5e
movq %r15, %rdi
movl $0x3, %esi
callq 0x2b62
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2f08
jmp 0x3f8d
movq %r15, %rdi
callq 0x2b6e
movl %eax, %r13d
movq %r15, %rdi
callq 0x2b5e
movq %r14, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x2d16
cmpl $0x400, %eax            # imm = 0x400
jne 0x3f3f
movl $0x2a, %edx
movq %r12, %rdi
leaq 0x135e(%rip), %rsi      # 0x5214
callq 0x2180
movq %r15, %rdi
callq 0x2b56
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 0x2b5e
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x2b62
movq %r15, %rdi
callq 0x2b5e
cmpl $0x4, %eax
jl 0x3f24
movq %r15, %rdi
movl $0x3, %esi
callq 0x2b62
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2f08
jmp 0x3f8b
movq %r15, %rdi
jbe 0x4034
xorl %esi, %esi
callq 0x2b82
movl $0x2a, %edx
movq %r12, %rdi
leaq 0x12e1(%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 0x32de
testb %al, %al
jne 0x3def
jmp 0x4040
movl $0x9, %edx
movq %r12, %rdi
leaq 0x12b9(%rip), %rsi      # 0x526a
callq 0x2180
movq %r15, %rdi
callq 0x2b56
movq %r12, %rdi
movl %eax, %esi
callq 0x2220
movq %rax, %r13
movl $0x10, %edx
movq %rax, %rdi
leaq 0x129a(%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 0x2b66
movl %eax, %r13d
movq %r15, %rdi
callq 0x2b6e
movq %r14, %rdi
movl %r13d, %esi
movl %eax, %edx
callq 0x2e40
movq %r15, %rdi
callq 0x2c18
jmp 0x3f8d
movl %eax, %esi
callq 0x2b6a
jmp 0x3e16
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop