// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rdi, %rbx
incq (%rdi)
movq 0x488(%rdi), %rdi
testq %rdi, %rdi
je 0x12c4f4
callq 0x105278
leaq 0x410(%rbx), %r14
movq %r14, %rdi
callq 0x12e164
addq %rax, 0x8(%rbx)
cmpq $0x0, 0x1d0(%rbx)
jne 0x12c51e
cmpb $0x1, 0x47c(%rbx)
jne 0x12c9c4
cmpq $0x0, 0x468(%rbx)
jle 0x12c5e8
xorl %ebp, %ebp
cmpl (%r14), %ebp
je 0x12c9c4
movl 0x418(%rbx), %eax
cmpl 0x414(%rbx), %eax
je 0x12c9c4
movq %r14, %rdi
movl $0x1, %esi
movq $-0x1, %rdx
callq 0x12e1ee
movq 0x468(%rbx), %rax
decq %rax
movq %rax, 0x468(%rbx)
movsd 0x598(%rbx), %xmm0
addsd 0x1db3a(%rip), %xmm0    # 0x14a0b8
movsd %xmm0, 0x598(%rbx)
cvttsd2si %xmm0, %rcx
cmpq %rcx, 0x1d0(%rbx)
jne 0x12c5db
cmpb $0x0, 0x1d8(%rbx)
jne 0x12c5db
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x1a8(%rbx)
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %esi
movq (%rdi), %rax
callq *0x40(%rax)
movb $0x1, 0x1d8(%rbx)
movq 0x468(%rbx), %rax
incl %ebp
testq %rax, %rax
jg 0x12c52e
jmp 0x12c5ea
xorl %ebp, %ebp
movl 0x478(%rbx), %eax
cmpl $0x1, %eax
je 0x12c740
testl %eax, %eax
jne 0x12c9d4
cmpl (%r14), %ebp
je 0x12c9c4
movl 0x418(%rbx), %eax
cmpl 0x414(%rbx), %eax
je 0x12c9c4
movq 0x470(%rbx), %r15
leaq 0x38(%rbx), %rsi
leaq 0x80(%rsp), %r12
movq %r12, %rdi
callq 0x29968
movl 0x10(%rbx), %r8d
movq %rsp, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x2ca64
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x12c66a
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x10(%rsp), %rsi
movupd -0x10(%rsi), %xmm0
leaq 0x110(%rsp), %rdi
movapd %xmm0, -0x10(%rdi)
callq 0x24b42
leaq 0x40(%rsp), %rsi
movq -0x8(%rsi), %rax
leaq 0x140(%rsp), %r15
movq %rax, -0x8(%r15)
movupd -0x18(%rsi), %xmm0
movupd %xmm0, -0x18(%r15)
movq %r15, %rdi
callq 0x29968
cmpq $0x0, 0x28(%rbx)
je 0x12c9f8
leaq 0x18(%rbx), %rdi
leaq 0x100(%rsp), %rsi
callq *0x30(%rbx)
movl %eax, %ebp
movq 0x150(%rsp), %rax
testq %rax, %rax
je 0x12c6e4
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x12c701
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0xb2f0
testb %bpl, %bpl
je 0x12c9bc
movq 0x470(%rbx), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x12e1ee
movsd 0x598(%rbx), %xmm0
addsd 0x1d98d(%rip), %xmm0    # 0x14a0b8
movsd %xmm0, 0x598(%rbx)
movq %rsp, %rdi
callq 0x25c78
jmp 0x12c872
movq 0x470(%rbx), %r14
leaq 0x38(%rbx), %rsi
leaq 0x60(%rsp), %r15
movq %r15, %rdi
callq 0x29968
movl 0x10(%rbx), %r8d
movq %rsp, %rdi
movq %r14, %rsi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2ca64
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x12c788
leaq 0x60(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x10(%rsp), %rsi
movupd -0x10(%rsi), %xmm0
leaq 0xb0(%rsp), %rdi
movapd %xmm0, -0x10(%rdi)
callq 0x24b42
leaq 0x40(%rsp), %r14
movq -0x8(%r14), %rax
leaq 0xe0(%rsp), %r15
movq %rax, -0x8(%r15)
movupd -0x18(%r14), %xmm0
movupd %xmm0, -0x18(%r15)
movq %r15, %rdi
movq %r14, %rsi
callq 0x29968
cmpq $0x0, 0x28(%rbx)
je 0x12c9f3
leaq 0x18(%rbx), %rdi
leaq 0xa0(%rsp), %rsi
callq *0x30(%rbx)
movl %eax, %ebp
movq 0xf0(%rsp), %rax
testq %rax, %rax
je 0x12c806
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x12c823
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0xb2f0
testb %bpl, %bpl
je 0x12c8f3
movsd 0x598(%rbx), %xmm0
addsd 0x1d87c(%rip), %xmm0    # 0x14a0b8
movsd %xmm0, 0x598(%rbx)
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x12c85b
movq %r14, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq *%rax
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x12c872
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0xb2f0
cvttsd2si 0x598(%rbx), %rax
cmpq %rax, 0x1d0(%rbx)
jne 0x12c8c4
cmpb $0x0, 0x1d8(%rbx)
jne 0x12c8c4
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
xorps %xmm0, %xmm0
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 0x468(%rbx), %rsi
leaq 0x478(%rbx), %rcx
leaq 0x1e0(%rbx), %rdi
leaq 0x470(%rbx), %rdx
cmpb $0x1, 0x58(%rbx)
jne 0x12c92a
callq 0x12dae0
movb %al, 0x47c(%rbx)
jmp 0x12c936
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x12c90a
movq %r14, %rdi
movq %r14, %rsi
movl $0x3, %edx
callq *%rax
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x12c9c4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0xb2f0
jmp 0x12c9c4
callq 0x12de64
movb $0x1, 0x47c(%rbx)
movq 0x470(%rbx), %rsi
cmpq $-0x1, %rsi
je 0x12c95a
movq 0x5c0(%rbx), %rdi
movl 0x10(%rbx), %edx
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, 0x470(%rbx)
cmpb $0x0, 0x47c(%rbx)
jne 0x12c9c4
cmpb $0x0, 0x1d8(%rbx)
jne 0x12c9c4
cmpq $0x0, 0x1d0(%rbx)
jne 0x12c9fd
xorps %xmm0, %xmm0
cvtsi2sdq (%rbx), %xmm0
movsd %xmm0, 0x110(%rbx)
cvttsd2si 0x598(%rbx), %rax
xorps %xmm0, %xmm0
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)
jmp 0x12c9c4
movq %rsp, %rdi
callq 0x25c78
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e3e0(%rip), %rdi     # 0x15adbb
leaq 0x2e132(%rip), %rsi     # 0x15ab14
leaq 0x2e3f3(%rip), %rcx     # 0x15addc
movl $0xfd, %edx
callq 0xb200
callq 0xb160
callq 0xb160
leaq 0x2e3f5(%rip), %rdi     # 0x15adf9
leaq 0x2e109(%rip), %rsi     # 0x15ab14
leaq 0x2e3ca(%rip), %rcx     # 0x15addc
movl $0x11b, %edx            # imm = 0x11B
callq 0xb200
jmp 0x12caca
jmp 0x12caca
movq %rax, %rbx
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x12cae2
movq 0x120(%rsp), %rsi
jmp 0x12ca9d
movq %rax, %rbx
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x12caea
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x12caea
jmp 0x12caca
jmp 0x12caca
jmp 0x12caca
jmp 0x12caa7
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
jmp 0x12cadd
jmp 0x12caca
jmp 0x12caca
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x12cae2
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0xb2f0
jmp 0x12cae2
movq %rax, %rbx
jmp 0x12cae2
movq %rax, %rbx
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0x12caea
leaq 0x60(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x12caea
movq %rax, %rdi
callq 0x171a3
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x25c78
movq %rsp, %rdi
callq 0x25c78
movq %rbx, %rdi
callq 0xb510