// File: /workspace/github_cpp_makefile_star2_O3/dsesami[P]superscalar-processor-model/main.cc
// Function: main
int main(int argc, char ** argv) {
    if(argc != 7) {
        cout << "Invalid amount of arguments for 'sim_ds'. Please include 6 " <<
                "parameters of the format <ROB_SIZE> <IQ_SIZE> <WIDTH> " <<
                "<CACHE_SIZE> <P> <TRACE_FILE>." << endl;
        return 1;
    }

    ROBSIZE    = atoi(argv[1]), // Max # of entries within Reorder Buffer
    IQ_SIZE    = atoi(argv[2]), // Max # of entries within Issue Queue
    WIDTH      = atoi(argv[3]), // Superscalar width of all pipeline stages (minus WB)
    CACHE_SIZE = atoi(argv[4]), // Size of instruction cache in bytes
    P          = atoi(argv[5]); // Prefetching flag
    TRACE_FILE =      argv[6] ; // Name of trace file

    dyn_instr_count   = 0,   // Dynamic instruction count
    cycles            = 0;   // Total number of cycles. Always at least 1.
    double ipc        = 0;   // Average instructions per cycle

    infile.open(TRACE_FILE);

    ROB.resize(ROBSIZE);
    IQ.resize(IQ_SIZE);

    // Pipeline routine
    do {
        retire();
        //cout << "1" << endl;
        writeback();
        //cout << "2" << endl;
        execute();
        //cout << "3" << endl;
        issue();
        //cout << "4" << endl;
        dispatch();
        //cout << "5" << endl;
        regRead();
        //cout << "6" << endl;
        rename();
        //cout << "7" << endl;
        decode();
        //cout << "8" << endl;
        FE_continue = fetch();
        //cout << "9" << endl;
    }
    while (advance_cycle());

    ipc = (double) dyn_instr_count / (double) cycles;

    cout << "# === Simulator Command =========" << endl
         << "# ./sim_ds "  << argv[1] << " " <<
            argv[2] << " " << argv[3] << " " <<
            argv[4] << " " << argv[5] << " " <<
            argv[6] << endl;
    cout << "# === Processor Configuration ===" << endl;
    cout << "# ROB_SIZE  = "        << argv[1]  << endl;
    cout << "# IQ_SIZE   = "        << argv[2]  << endl;
    cout << "# WIDTH     = "        << argv[3]  << endl;
    cout << "# CACHE_SIZE    = "    << argv[4]  << endl;
    cout << "# PREFETCHING   = "    << argv[5]  << endl;
    cout << "# === Simulation Results ========" << endl;
    cout << "# Dynamic Instruction Count      = " << dyn_instr_count << endl;
    cout << "# Cycles                         = " << cycles          << endl;
    cout << "# Instructions Per Cycle (IPC)   = " << fixed << setprecision(2) << ipc             << endl;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x7, %edi
jne 0x2992
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x21f0
movl %eax, 0x8937(%rip)      # 0xb17c
movq 0x10(%r14), %rdi
callq 0x21f0
movl %eax, 0x892c(%rip)      # 0xb180
movq 0x18(%r14), %rdi
callq 0x21f0
movl %eax, 0x8921(%rip)      # 0xb184
movq 0x20(%r14), %rdi
callq 0x21f0
movl %eax, 0x8916(%rip)      # 0xb188
movq 0x28(%r14), %rdi
callq 0x21f0
movl %eax, 0x890b(%rip)      # 0xb18c
movq 0x30(%r14), %rsi
movq %rsi, 0x890c(%rip)      # 0xb198
xorl %eax, %eax
movl %eax, 0x88fc(%rip)      # 0xb190
movl %eax, 0x88fa(%rip)      # 0xb194
leaq 0x88ff(%rip), %rdi      # 0xb1a0
movl $0x8, %edx
callq 0x20d0
movl 0x88cb(%rip), %esi      # 0xb17c
leaq 0x8af0(%rip), %rdi      # 0xb3a8
callq 0x38ee
movl 0x88bd(%rip), %esi      # 0xb180
leaq 0x8b0e(%rip), %rdi      # 0xb3d8
callq 0x3934
callq 0x67ac
callq 0x6538
callq 0x5fc0
callq 0x5bc0
callq 0x5858
callq 0x55a4
callq 0x519c
callq 0x4f78
callq 0x4934
movl %eax, 0x8b06(%rip)      # 0xb408
callq 0x2fb0
testb %al, %al
jne 0x28cf
movl 0x887e(%rip), %r13d     # 0xb190
movl 0x887c(%rip), %ebp      # 0xb194
movq 0x86b9(%rip), %rbx      # 0xafd8
leaq 0x581c(%rip), %rsi      # 0x8142
movl $0x21, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movq %rax, %r15
leaq 0x5800(%rip), %rsi      # 0x8164
movl $0xb, %edx
movq %rax, %rdi
callq 0x2180
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x29df
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x29f7
movq 0x863f(%rip), %rbx      # 0xafd8
leaq 0x5710(%rip), %rsi      # 0x80b0
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x5738(%rip), %rsi      # 0x80ec
movl $0x36, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x575b(%rip), %rsi      # 0x8123
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x2180
movl $0x1, %ebp
jmp 0x2f78
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x5a57(%rip), %rsi      # 0x8455
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x10(%r14), %r12
testq %r12, %r12
je 0x2a2c
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2a44
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x5a0a(%rip), %rsi      # 0x8455
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x18(%r14), %r12
testq %r12, %r12
je 0x2a79
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2a91
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x59bd(%rip), %rsi      # 0x8455
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x20(%r14), %r12
testq %r12, %r12
je 0x2ac6
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2ade
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x5970(%rip), %rsi      # 0x8455
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x28(%r14), %r12
testq %r12, %r12
je 0x2b13
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2b2b
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x5923(%rip), %rsi      # 0x8455
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x30(%r14), %r12
testq %r12, %r12
je 0x2b60
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2b7a
movq (%r15), %rax
movq -0x18(%rax), %rax
movq %r15, %rdi
addq %rax, %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x55c8(%rip), %rsi      # 0x8170
movl $0x21, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x55af(%rip), %rsi      # 0x8192
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x2c15
movq %r15, %rdi
callq 0x20a0
movq 0x83d0(%rip), %rdi      # 0xafd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2c2c
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2260
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x5547(%rip), %rsi      # 0x81a1
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x2c8c
movq %r15, %rdi
callq 0x20a0
movq 0x8359(%rip), %rdi      # 0xafd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2ca3
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2260
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x54df(%rip), %rsi      # 0x81b0
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x18(%r14), %r15
testq %r15, %r15
je 0x2d03
movq %r15, %rdi
callq 0x20a0
movq 0x82e2(%rip), %rdi      # 0xafd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2d1a
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2260
cvtsi2sd %r13, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
movsd %xmm0, 0x10(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x545e(%rip), %rsi      # 0x81bf
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x20(%r14), %r15
testq %r15, %r15
je 0x2d93
movq %r15, %rdi
callq 0x20a0
movq 0x8252(%rip), %rdi      # 0xafd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2daa
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2260
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x53e8(%rip), %rsi      # 0x81d2
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x28(%r14), %r14
testq %r14, %r14
je 0x2e1c
movq %r14, %rdi
callq 0x20a0
movq 0x81c9(%rip), %rdi      # 0xafd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2e33
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2260
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x5384(%rip), %rsi      # 0x81e5
movl $0x21, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x536b(%rip), %rsi      # 0x8207
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2180
movl 0x82e1(%rip), %esi      # 0xb190
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x5343(%rip), %rsi      # 0x822b
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2180
movl 0x8299(%rip), %esi      # 0xb194
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
leaq 0x531b(%rip), %rsi      # 0x824f
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x18(%rbx,%rcx), %edx
orl $0x4, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq $0x2, 0x8(%rbx,%rax)
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x2210
movq %rax, %rbx
xorl %ebp, %ebp
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20f0
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq