// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::RequestMemoryOperation(int const&)
void RequestMemoryOperation(const int & address) {
            int page = address / page_size;
            
            int oldest_timestamp = timestamp;
            int index_of_oldest = -1;

            // Adds frames to the vector as needed until the vector is full (size is number_of_frames). Then replaces the least recently used frame
            // If the same process wants to access the same page, just update time stamp
            for (unsigned int i = 0; i < frames.size(); i++) {
                if ((frames[i]->page_ == page) && (frames[i]->pid_ == CPU)) {
                    frames[i]->timestamp_ = timestamp;
                    timestamp++;
                    return;
                }
            }

            // If there are empty frames, create a new frame in the vector
            if (frames.size() < number_of_frames) {
                Frame* new_frame = new Frame{};
                new_frame->timestamp_ = timestamp;
                new_frame->pid_ = CPU;
                new_frame->page_ = page;
                frames.push_back(new_frame);
            }

            // Replace the least recently used frame's data
            else {
                // Find the frame with the oldest(lowest) timestamp
                for (unsigned int i = 0; i < frames.size(); i++) {
                    if (frames[i]->timestamp_ <= oldest_timestamp) {
                        index_of_oldest = i;
                        oldest_timestamp = frames[i]->timestamp_;
                    }
                }
                frames[index_of_oldest]->page_ = page;
                frames[index_of_oldest]->pid_ = CPU;
                frames[index_of_oldest]->timestamp_ = timestamp;
            }
            timestamp++;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
xorl %edx, %edx
divl 0x10(%rcx)
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, -0x14(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movq -0x40(%rbp), %rdi
movl -0x20(%rbp), %eax
movq %rax, -0x48(%rbp)
addq $0x80, %rdi
callq 0x84d0
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x39a2
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq (%rax), %rax
movl 0x4(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x3992
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq -0x40(%rbp), %rcx
movq (%rax), %rax
movl 0x8(%rax), %eax
cmpl (%rcx), %eax
jne 0x3992
movq -0x40(%rbp), %rdi
movl 0x8(%rdi), %eax
movl %eax, -0x4c(%rbp)
addq $0x80, %rdi
movl -0x20(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movl -0x4c(%rbp), %edx
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq (%rcx), %rcx
movl %edx, (%rcx)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
jmp 0x3b22
jmp 0x3994
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x38f0
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
callq 0x84d0
movq -0x40(%rbp), %rcx
movl 0x18(%rcx), %ecx
cmpq %rcx, %rax
jae 0x3a35
movl $0xc, %edi
callq 0x21e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
callq 0xb3d0
jmp 0x39d9
movq -0x40(%rbp), %rdi
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movl 0x8(%rdi), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl (%rdi), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
addq $0x80, %rdi
leaq -0x28(%rbp), %rsi
callq 0xb400
jmp 0x3b15
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0xc, %esi
callq 0x21f0
jmp 0x3b28
movl $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movl -0x38(%rbp), %eax
movq %rax, -0x60(%rbp)
addq $0x80, %rdi
callq 0x84d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x3aae
movq -0x40(%rbp), %rdi
addq $0x80, %rdi
movl -0x38(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq (%rax), %rax
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jg 0x3aa1
movq -0x40(%rbp), %rdi
movl -0x38(%rbp), %eax
movl %eax, -0x1c(%rbp)
addq $0x80, %rdi
movl -0x38(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
jmp 0x3aa3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3a3c
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
addq $0x80, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x84f0
movl -0x6c(%rbp), %ecx
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movl (%rdi), %eax
movl %eax, -0x68(%rbp)
addq $0x80, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x84f0
movl -0x68(%rbp), %ecx
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movl 0x8(%rdi), %eax
movl %eax, -0x64(%rbp)
addq $0x80, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x84f0
movl -0x64(%rbp), %ecx
movq (%rax), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
addq $0x70, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)