// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]ramulator/src/Processor.cpp
// Function: ramulator::Core::tick()
void Core::tick()
{
    clk++;

    if(first_level_cache != nullptr)
        first_level_cache->tick();

    retired += window.retire();

    if (expected_limit_insts == 0 && !more_reqs) return;

    // bubbles (non-memory operations)
    int inserted = 0;
    while (bubble_cnt > 0) {
        if (inserted == window.ipc) return;
        if (window.is_full()) return;

        window.insert(true, -1);
        inserted++;
        bubble_cnt--;
        cpu_inst++;
        if (long(cpu_inst.value()) == expected_limit_insts && !reached_limit) {
          record_cycs = clk;
          record_insts = long(cpu_inst.value());
          memory.record_core(id);
          reached_limit = true;
        }
    }

    if (req_type == Request::Type::READ) {
        // read request
        if (inserted == window.ipc) return;
        if (window.is_full()) return;

        Request req(req_addr, req_type, callback, id);
        if (!send(req)) return;

        window.insert(false, req_addr);
        cpu_inst++;
    }
    else {
        // write request
        assert(req_type == Request::Type::WRITE);
        Request req(req_addr, req_type, callback, id);
        if (!send(req)) return;
        cpu_inst++;
    }
    if (long(cpu_inst.value()) == expected_limit_insts && !reached_limit) {
      record_cycs = clk;
      record_insts = long(cpu_inst.value());
      memory.record_core(id);
      reached_limit = true;
    }

    if (no_core_caches) {
      more_reqs = trace.get_filtered_request(
          bubble_cnt, req_addr, req_type);
      if (req_addr != -1) {
        req_addr = memory.page_allocator(req_addr, id);
      }
    } else {
      more_reqs = trace.get_unfiltered_request(
          bubble_cnt, req_addr, req_type);
      if (req_addr != -1) {
        req_addr = memory.page_allocator(req_addr, id);
      }
    }
    if (!more_reqs) {
      if (!reached_limit) { // if the length of this trace is shorter than expected length, then record it when the whole trace finishes, and set reached_limit to true.
        // Hasan: overriding this behavior. We start the trace from the
        // beginning until the requested amount of instructions are
        // simulated. This should never be reached now.
        assert((expected_limit_insts == 0) && "Shouldn't be reached when expected_limit_insts > 0 since we start over the trace");
        record_cycs = clk;
        record_insts = long(cpu_inst.value());
        memory.record_core(id);
        reached_limit = true;
      }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdi, %rbx
incq (%rdi)
movq 0x488(%rdi), %rdi
testq %rdi, %rdi
je 0xba12a
callq 0x9b6d0
leaq 0x410(%rbx), %r15
movq %r15, %rdi
callq 0xbb2ee
addq %rax, 0x8(%rbx)
cmpq $0x0, 0x1d0(%rbx)
jne 0xba154
cmpb $0x1, 0x47c(%rbx)
jne 0xba469
leaq 0x468(%rbx), %r14
xorl %r13d, %r13d
pushq $0x1
popq %rbp
pushq $-0x1
popq %r12
cmpq $0x0, (%r14)
jle 0xba206
cmpl (%r15), %r13d
je 0xba469
movl 0x418(%rbx), %eax
cmpl 0x414(%rbx), %eax
je 0xba469
movq %r15, %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0xbb374
decq 0x468(%rbx)
movsd 0x598(%rbx), %xmm0
addsd 0x16eca(%rip), %xmm0    # 0xd1078
movsd %xmm0, 0x598(%rbx)
cvttsd2si %xmm0, %rax
cmpq %rax, 0x1d0(%rbx)
jne 0xba1fe
cmpb $0x0, 0x1d8(%rbx)
jne 0xba1fe
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x1a8(%rbx)
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %esi
movq (%rdi), %rax
callq *0x40(%rax)
movb $0x1, 0x1d8(%rbx)
incl %r13d
jmp 0xba165
movl 0x478(%rbx), %eax
cmpl $0x1, %eax
je 0xba2c4
testl %eax, %eax
jne 0xba47b
cmpl %r13d, (%r15)
je 0xba469
movl 0x418(%rbx), %eax
cmpl 0x414(%rbx), %eax
je 0xba469
movq 0x470(%rbx), %r12
leaq 0x38(%rbx), %rsi
leaq 0x88(%rsp), %r13
movq %r13, %rdi
callq 0x1ff42
movl 0x10(%rbx), %r8d
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x22732
leaq 0x88(%rsp), %rdi
callq 0x96b6a
leaq 0x108(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2000a
leaq 0x18(%rbx), %rdi
leaq 0x108(%rsp), %rsi
callq 0x9b9e4
movl %eax, %ebp
leaq 0x108(%rsp), %rdi
callq 0x1cc14
testb %bpl, %bpl
je 0xba3d1
movq 0x470(%rbx), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xbb374
jmp 0xba338
movq 0x470(%rbx), %r15
leaq 0x38(%rbx), %rsi
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x1ff42
movl 0x10(%rbx), %r8d
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rdx
movq %r15, %rsi
movq %r12, %rcx
callq 0x22732
leaq 0x68(%rsp), %rdi
callq 0x96b6a
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2000a
leaq 0x18(%rbx), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x9b9e4
movl %eax, %ebp
leaq 0xa8(%rsp), %rdi
callq 0x1cc14
testb %bpl, %bpl
je 0xba3d1
movsd 0x598(%rbx), %xmm0
addsd 0x16d30(%rip), %xmm0    # 0xd1078
movsd %xmm0, 0x598(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x1cc14
cvttsd2si 0x598(%rbx), %rax
cmpq %rax, 0x1d0(%rbx)
jne 0xba3a6
cmpb $0x0, 0x1d8(%rbx)
jne 0xba3a6
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x1a8(%rbx)
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %esi
movq (%rdi), %rax
callq *0x40(%rax)
movb $0x1, 0x1d8(%rbx)
leaq 0x478(%rbx), %rcx
leaq 0x1e0(%rbx), %rdi
leaq 0x470(%rbx), %rdx
cmpb $0x1, 0x58(%rbx)
jne 0xba3e0
movq %r14, %rsi
callq 0xbaf70
movb %al, 0x47c(%rbx)
jmp 0xba3ef
leaq 0x8(%rsp), %rdi
callq 0x1cc14
jmp 0xba469
movq %r14, %rsi
callq 0xbb140
movb $0x1, 0x47c(%rbx)
movq 0x470(%rbx), %rsi
cmpq $-0x1, %rsi
je 0xba413
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, 0x470(%rbx)
cmpb $0x0, 0x47c(%rbx)
jne 0xba469
cmpb $0x0, 0x1d8(%rbx)
jne 0xba469
cmpq $0x0, 0x1d0(%rbx)
jne 0xba49a
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
cvttsd2si 0x598(%rbx), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x1a8(%rbx)
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %esi
movq (%rdi), %rax
callq *0x40(%rax)
movb $0x1, 0x1d8(%rbx)
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x278f9(%rip), %rdi     # 0xe1d7b
leaq 0x2764b(%rip), %rsi     # 0xe1ad4
leaq 0x2790c(%rip), %rcx     # 0xe1d9c
movl $0xfd, %edx
callq 0xb210
leaq 0x27918(%rip), %rdi     # 0xe1db9
leaq 0x2762c(%rip), %rsi     # 0xe1ad4
leaq 0x278ed(%rip), %rcx     # 0xe1d9c
movl $0x11b, %edx            # imm = 0x11B
callq 0xb210
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
jmp 0xba4e0
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0xba4fe
jmp 0xba4e7
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x1cc14
jmp 0xba4ea
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1cc14
jmp 0xba503
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x96b6a
movq %rbx, %rdi
callq 0xb4d0
nop