// File: /workspace/github_cpp_makefile_star2_O2/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 0x2e8e
andl $0x0, (%rbx)
leaq 0x160(%rbx), %r14
leaq -0x48(%rbp), %r15
movq 0x49f8(%rip), %r13      # 0x7fd0
movq %rbx, %rdi
callq 0x2f70
testb %al, %al
je 0x37ae
movq %rbx, %rdi
callq 0x2d56
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2eaa
testb %al, %al
je 0x3733
movq %r15, %rdi
callq 0x2ad8
testb %al, %al
je 0x3673
movq %rbx, %rdi
movq %r15, %rsi
callq 0x31c0
movq %r15, %rdi
callq 0x2a16
testl %eax, %eax
jle 0x373a
movq %r15, %rdi
callq 0x29f6
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x29fa
movq %r15, %rdi
callq 0x29f6
cmpl $0x4, %eax
jl 0x3655
movq %r15, %rdi
pushq $0x3
popq %rsi
callq 0x29fa
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2d1e
jmp 0x35d8
movq %r15, %rdi
callq 0x2a06
movl %eax, %r12d
movq %r15, %rdi
callq 0x29f6
movq %r14, %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x2b82
cmpl $0x400, %eax            # imm = 0x400
jne 0x370c
movq %r13, %rdi
leaq 0x1b4b(%rip), %rsi      # 0x51ef
callq 0x2170
movq %rax, %r12
movq %r15, %rdi
callq 0x29ee
movq %r12, %rdi
movl %eax, %esi
callq 0x2230
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x29f6
leal 0x1(%rax), %esi
movq %r15, %rdi
callq 0x29fa
movq %r15, %rdi
callq 0x29f6
cmpl $0x4, %eax
jl 0x36f1
movq %r15, %rdi
pushq $0x3
popq %rsi
callq 0x29fa
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2d1e
jmp 0x3733
movq %r15, %rdi
jbe 0x37a2
xorl %esi, %esi
callq 0x2a1a
movq %r13, %rdi
leaq 0x1af4(%rip), %rsi      # 0x521a
callq 0x2170
movq %rax, %rdi
callq 0x20d0
incl (%rbx)
jmp 0x35d8
movq %r13, %rdi
leaq 0x1b01(%rip), %rsi      # 0x5245
callq 0x2170
movq %rax, %r12
movq %r15, %rdi
callq 0x29ee
movq %r12, %rdi
movl %eax, %esi
callq 0x2230
movq %rax, %rdi
leaq 0x1ae7(%rip), %rsi      # 0x524f
callq 0x2170
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x29fe
movl %eax, %r12d
movq %r15, %rdi
callq 0x2a06
movq %r14, %rdi
movl %r12d, %esi
movl %eax, %edx
callq 0x2c5a
movq %r15, %rdi
callq 0x2aa4
jmp 0x35d8
movl %eax, %esi
callq 0x2a02
jmp 0x360f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop