// File: /workspace/github_cpp_makefile_star2_O1/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 0x2962
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x21f0
movl %eax, 0x7967(%rip)      # 0xa17c
movq 0x10(%r14), %rdi
callq 0x21f0
movl %eax, 0x795c(%rip)      # 0xa180
movq 0x18(%r14), %rdi
callq 0x21f0
movl %eax, 0x7951(%rip)      # 0xa184
movq 0x20(%r14), %rdi
callq 0x21f0
movl %eax, 0x7946(%rip)      # 0xa188
movq 0x28(%r14), %rdi
callq 0x21f0
movl %eax, 0x793b(%rip)      # 0xa18c
movq 0x30(%r14), %rsi
movq %rsi, 0x793c(%rip)      # 0xa198
xorl %eax, %eax
movl %eax, 0x792c(%rip)      # 0xa190
movl %eax, 0x792a(%rip)      # 0xa194
leaq 0x792f(%rip), %rdi      # 0xa1a0
movl $0x8, %edx
callq 0x20d0
movl 0x78fb(%rip), %esi      # 0xa17c
leaq 0x7b20(%rip), %rdi      # 0xa3a8
callq 0x392a
movl 0x78ed(%rip), %esi      # 0xa180
leaq 0x7b3e(%rip), %rdi      # 0xa3d8
callq 0x3970
callq 0x5d04
callq 0x5aa0
callq 0x5510
callq 0x511c
callq 0x4dd8
callq 0x4b2c
callq 0x473c
callq 0x4540
callq 0x3edc
movl %eax, 0x7b36(%rip)      # 0xa408
callq 0x2f80
testb %al, %al
jne 0x289f
movl 0x78ae(%rip), %r13d     # 0xa190
movl 0x78ac(%rip), %ebp      # 0xa194
movq 0x76e9(%rip), %rbx      # 0x9fd8
leaq 0x47bc(%rip), %rsi      # 0x70b2
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 0x47a0(%rip), %rsi      # 0x70d4
movl $0xb, %edx
movq %rax, %rdi
callq 0x2180
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x29af
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x29c7
movq 0x766f(%rip), %rbx      # 0x9fd8
leaq 0x46b0(%rip), %rsi      # 0x7020
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x46d8(%rip), %rsi      # 0x705c
movl $0x36, %edx
movq %rbx, %rdi
callq 0x2180
leaq 0x46fb(%rip), %rsi      # 0x7093
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x2180
movl $0x1, %ebp
jmp 0x2f48
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x4a28(%rip), %rsi      # 0x73f6
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x10(%r14), %r12
testq %r12, %r12
je 0x29fc
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2a14
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x49db(%rip), %rsi      # 0x73f6
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x18(%r14), %r12
testq %r12, %r12
je 0x2a49
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2a61
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x498e(%rip), %rsi      # 0x73f6
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x20(%r14), %r12
testq %r12, %r12
je 0x2a96
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2aae
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x4941(%rip), %rsi      # 0x73f6
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x28(%r14), %r12
testq %r12, %r12
je 0x2ae3
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2afb
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2260
leaq 0x48f4(%rip), %rsi      # 0x73f6
movl $0x1, %edx
movq %r15, %rdi
callq 0x2180
movq 0x30(%r14), %r12
testq %r12, %r12
je 0x2b30
movq %r12, %rdi
callq 0x20a0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2b4a
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 0x4568(%rip), %rsi      # 0x70e0
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 0x454f(%rip), %rsi      # 0x7102
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x8(%r14), %r15
testq %r15, %r15
je 0x2be5
movq %r15, %rdi
callq 0x20a0
movq 0x7400(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2bfc
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 0x44e7(%rip), %rsi      # 0x7111
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x2c5c
movq %r15, %rdi
callq 0x20a0
movq 0x7389(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2c73
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 0x447f(%rip), %rsi      # 0x7120
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x18(%r14), %r15
testq %r15, %r15
je 0x2cd3
movq %r15, %rdi
callq 0x20a0
movq 0x7312(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2cea
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 0x43fe(%rip), %rsi      # 0x712f
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x20(%r14), %r15
testq %r15, %r15
je 0x2d63
movq %r15, %rdi
callq 0x20a0
movq 0x7282(%rip), %rdi      # 0x9fd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2d7a
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 0x4388(%rip), %rsi      # 0x7142
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2180
movq 0x28(%r14), %r14
testq %r14, %r14
je 0x2dec
movq %r14, %rdi
callq 0x20a0
movq 0x71f9(%rip), %rdi      # 0x9fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2180
jmp 0x2e03
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 0x4324(%rip), %rsi      # 0x7155
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 0x430b(%rip), %rsi      # 0x7177
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2180
movl 0x7311(%rip), %esi      # 0xa190
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 0x42e3(%rip), %rsi      # 0x719b
movl $0x23, %edx
movq %rbx, %rdi
callq 0x2180
movl 0x72c9(%rip), %esi      # 0xa194
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 0x42bb(%rip), %rsi      # 0x71bf
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