// File: 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
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5700
movq -0x78(%rbp), %rdi
callq 0x4680
movq -0x78(%rbp), %rdi
callq 0x4310
movq -0x78(%rbp), %rdi
callq 0x48e0
testb $0x1, %al
jne 0x53d4
jmp 0x56c0
movq -0x78(%rbp), %rdi
callq 0x43d0
movq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x46d0
testb $0x1, %al
jne 0x53f3
jmp 0x56b0
leaq -0x28(%rbp), %rdi
callq 0x3ba0
testb $0x1, %al
jne 0x5573
movq -0x78(%rbp), %rax
addq $0x160, %rax            # imm = 0x160
movq %rax, -0x88(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3790
movl %eax, -0x7c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3710
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %esi
movl %eax, %edx
callq 0x3d10
movl %eax, -0x2c(%rbp)
cmpl $0x400, -0x2c(%rbp)     # imm = 0x400
jne 0x551d
movq 0x9b7e(%rip), %rdi      # 0xefd0
leaq 0x4ddb(%rip), %rsi      # 0xa234
callq 0x2170
movq %rax, -0x90(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x36e0
movq -0x90(%rbp), %rdi
movl %eax, %esi
callq 0x2270
movq %rax, %rdi
movq 0x9b3a(%rip), %rsi      # 0xefc0
callq 0x2190
leaq -0x28(%rbp), %rdi
callq 0x3710
movl %eax, %esi
addl $0x1, %esi
leaq -0x28(%rbp), %rdi
callq 0x3730
leaq -0x28(%rbp), %rdi
callq 0x3710
cmpl $0x3, %eax
jle 0x54be
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x3730
movq -0x78(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x4330
movq -0x78(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x53c2
cmpl $0x400, -0x2c(%rbp)     # imm = 0x400
jbe 0x5563
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x3830
movq 0x9a98(%rip), %rdi      # 0xefd0
leaq 0x4d20(%rip), %rsi      # 0xa25f
callq 0x2170
movq %rax, %rdi
movq 0x9a72(%rip), %rsi      # 0xefc0
callq 0x2190
movq -0x78(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x53c2
movl -0x2c(%rbp), %esi
leaq -0x28(%rbp), %rdi
callq 0x3770
jmp 0x5571
jmp 0x5573
movq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x4cc0
leaq -0x28(%rbp), %rdi
callq 0x3810
cmpl $0x0, %eax
jle 0x5619
leaq -0x28(%rbp), %rdi
callq 0x3710
movl %eax, %esi
addl $0x1, %esi
leaq -0x28(%rbp), %rdi
callq 0x3730
leaq -0x28(%rbp), %rdi
callq 0x3710
cmpl $0x3, %eax
jle 0x55c5
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x3730
movq -0x78(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x70(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x4330
jmp 0x56ae
movq 0x99b0(%rip), %rdi      # 0xefd0
leaq 0x4c63(%rip), %rsi      # 0xa28a
callq 0x2170
movq %rax, -0xa8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x36e0
movq -0xa8(%rbp), %rdi
movl %eax, %esi
callq 0x2270
movq %rax, %rdi
leaq 0x4c40(%rip), %rsi      # 0xa294
callq 0x2170
movq %rax, %rdi
movq 0x995d(%rip), %rsi      # 0xefc0
callq 0x2190
movq -0x78(%rbp), %rax
addq $0x160, %rax            # imm = 0x160
movq %rax, -0xa0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3750
movl %eax, -0x94(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3790
movq -0xa0(%rbp), %rdi
movl -0x94(%rbp), %esi
movl %eax, %edx
callq 0x3ed0
leaq -0x28(%rbp), %rdi
callq 0x3b00
jmp 0x56bb
movq -0x78(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x53c2
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)