// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]SMLA/src/Main.cpp
// Function: main
int main(int argc, const char *argv[])
{
    if (argc < 2) {
        printf("Usage: %s <configs-file> --mode=cpu,dram [--stats <filename>] <trace-filename1> <trace-filename2>\n"
            "Example: %s ramulator-configs.cfg --mode=cpu cpu.trace cpu.trace\n", argv[0], argv[0]);
        return 0;
    }

    Config configs(argv[1]);

    const std::string& standard = configs["standard"];
    assert(standard != "" || "DRAM standard should be specified.");

    const char *trace_type = strstr(argv[2], "=");
    trace_type++;
    if (strcmp(trace_type, "cpu") == 0) {
      configs.add("trace_type", "CPU");
    } else if (strcmp(trace_type, "dram") == 0) {
      configs.add("trace_type", "DRAM");
    } else {
      printf("invalid trace type: %s\n", trace_type);
      assert(false);
    }

    int trace_start = 3;
    string stats_out;
    if (strcmp(argv[3], "--stats") == 0) {
      Stats::statlist.output(argv[4]);
      stats_out = argv[4];
      trace_start = 5;
    } else {
      Stats::statlist.output(standard+".stats");
      stats_out = standard + string(".stats");
    }
    std::vector<const char*> files(&argv[trace_start], &argv[argc]);
    configs.set_core_num(argc - trace_start);

		if (standard == "WideIO") {
      WideIO* wio = new WideIO(configs["org"], configs["speed"]);
      start_run(configs, wio, files);
    } 
		else if (standard == "SMLA_CIO") {
      SMLA_CIO* scio = new SMLA_CIO(configs["org"], configs["speed"]);
      start_run(configs, scio, files);
    }
		else if (standard == "SMLA_DIO") {
      SMLA_DIO* sdio = new SMLA_DIO(configs["org"], configs["speed"]);
      start_run(configs, sdio, files);
    }

    printf("Simulation done. Statistics written to %s\n", stats_out.c_str());

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %r14
cmpl $0x1, %edi
jg 0x5dda
movq (%r14), %rdx
leaq 0x2e2e5(%rip), %rdi     # 0x340b0
movq %rdx, %rsi
xorl %eax, %eax
callq 0x5050
jmp 0x634d
movl %edi, %ebx
movq 0x8(%r14), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x64b0
leaq 0xe8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x279b0
leaq 0x90(%rsp), %rdi
callq 0x5508
leaq 0x2e339(%rip), %rsi     # 0x34154
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x64b0
leaq 0x90(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x64ec
leaq 0x50(%rsp), %rdi
callq 0x5508
leaq 0x2e41f(%rip), %rsi     # 0x34274
leaq 0x90(%rsp), %rdi
callq 0x654c
movq 0x10(%r14), %rdi
pushq $0x3d
popq %rsi
callq 0x5120
movq %rax, %r15
incq %r15
leaq 0x2e30c(%rip), %rsi     # 0x34187
movq %r15, %rdi
callq 0x5370
testl %eax, %eax
je 0x5ee3
leaq 0x2e30c(%rip), %rsi     # 0x3419a
movq %r15, %rdi
callq 0x5370
testl %eax, %eax
jne 0x635d
leaq 0x2e2e6(%rip), %rsi     # 0x3418b
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x64b0
leaq 0x2f1ff(%rip), %rsi     # 0x350ba
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x64b0
leaq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x6556
jmp 0x5f26
leaq 0x2e2a1(%rip), %rsi     # 0x3418b
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x64b0
leaq 0x2e296(%rip), %rsi     # 0x34196
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x64b0
leaq 0xe8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x6556
leaq 0x10(%rsp), %rdi
callq 0x5508
leaq 0x50(%rsp), %rdi
callq 0x5508
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x18(%r14), %rdi
leaq 0x2e267(%rip), %rsi     # 0x341bd
callq 0x5370
testl %eax, %eax
je 0x5ff5
leaq 0x2e25b(%rip), %rdx     # 0x341c5
leaq 0x138(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x6619
leaq 0x4b442(%rip), %rdi     # 0x513c8
leaq 0x138(%rsp), %rsi
callq 0x65d8
leaq 0x138(%rsp), %rdi
callq 0x5508
leaq 0x2e21e(%rip), %rsi     # 0x341c5
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x64b0
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x6651
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x5320
movq %r15, %rdi
callq 0x5508
leaq 0x30(%rsp), %rdi
callq 0x5508
pushq $0x3
jmp 0x603c
movq 0x20(%r14), %rsi
leaq 0x158(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x64b0
leaq 0x4b3b6(%rip), %rdi     # 0x513c8
leaq 0x158(%rsp), %rsi
callq 0x65d8
leaq 0x158(%rsp), %rdi
callq 0x5508
movq 0x20(%r14), %rsi
leaq 0x50(%rsp), %rdi
callq 0x54e0
pushq $0x5
popq %rbp
movl %ebp, %eax
leaq (%r14,%rax,8), %rsi
movl %ebx, %eax
leaq (%r14,%rax,8), %rdx
leaq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rcx
callq 0x6676
subl %ebp, %ebx
movl %ebx, 0x12c(%rsp)
leaq 0x2e161(%rip), %rsi     # 0x341cc
leaq 0x90(%rsp), %rdi
callq 0x66a8
testb %al, %al
je 0x6147
movl $0x2780, %edi           # imm = 0x2780
callq 0x52b0
movq %rax, %r14
leaq 0x2e13f(%rip), %rsi     # 0x341d3
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x64b0
leaq 0x10(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x64ec
leaq 0x2e116(%rip), %rsi     # 0x341d7
leaq 0xb0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x64b0
leaq 0x70(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x64ec
leaq 0x10(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %r14, %rdi
callq 0x32626
leaq 0x70(%rsp), %rdi
callq 0x5508
leaq 0xb0(%rsp), %rdi
callq 0x5508
leaq 0x10(%rsp), %rdi
callq 0x5508
leaq 0x30(%rsp), %rdi
callq 0x5508
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq %r14, %rsi
callq 0x66b5
jmp 0x6308
leaq 0x2e08f(%rip), %rsi     # 0x341dd
leaq 0x90(%rsp), %rdi
callq 0x66a8
testb %al, %al
je 0x622a
movl $0x2780, %edi           # imm = 0x2780
callq 0x52b0
movq %rax, %r14
leaq 0x2e05c(%rip), %rsi     # 0x341d3
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x64b0
leaq 0x10(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x64ec
leaq 0x2e033(%rip), %rsi     # 0x341d7
leaq 0xb0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x64b0
leaq 0x70(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x64ec
leaq 0x10(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %r14, %rdi
callq 0x2c432
leaq 0x70(%rsp), %rdi
callq 0x5508
leaq 0xb0(%rsp), %rdi
callq 0x5508
leaq 0x10(%rsp), %rdi
callq 0x5508
leaq 0x30(%rsp), %rdi
callq 0x5508
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq %r14, %rsi
callq 0x6984
jmp 0x6308
leaq 0x2dfb5(%rip), %rsi     # 0x341e6
leaq 0x90(%rsp), %rdi
callq 0x66a8
testb %al, %al
je 0x6308
movl $0x2780, %edi           # imm = 0x2780
callq 0x52b0
movq %rax, %r14
leaq 0x2df79(%rip), %rsi     # 0x341d3
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x64b0
leaq 0x10(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x64ec
leaq 0x2df50(%rip), %rsi     # 0x341d7
leaq 0xb0(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x64b0
leaq 0x70(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x64ec
leaq 0x10(%rsp), %rsi
leaq 0x70(%rsp), %rdx
movq %r14, %rdi
callq 0x2f20e
leaq 0x70(%rsp), %rdi
callq 0x5508
leaq 0xb0(%rsp), %rdi
callq 0x5508
leaq 0x10(%rsp), %rdi
callq 0x5508
leaq 0x30(%rsp), %rdi
callq 0x5508
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
movq %r14, %rsi
callq 0x6c53
leaq 0x50(%rsp), %rbx
movq (%rbx), %rsi
leaq 0x2ded8(%rip), %rdi     # 0x341ef
xorl %eax, %eax
callq 0x5050
leaq 0xd0(%rsp), %rdi
callq 0x737c
movq %rbx, %rdi
callq 0x5508
leaq 0x90(%rsp), %rdi
callq 0x5508
leaq 0xe8(%rsp), %rdi
callq 0x7240
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2de3b(%rip), %rdi     # 0x3419f
movq %r15, %rsi
xorl %eax, %eax
callq 0x5050
leaq 0x2de42(%rip), %rdi     # 0x341b7
leaq 0x2dde1(%rip), %rsi     # 0x3415d
leaq 0x2dde7(%rip), %rcx     # 0x3416a
movl $0x8f, %edx
callq 0x5200
jmp 0x63c4
jmp 0x63d3
jmp 0x63e7
jmp 0x63f6
jmp 0x6405
jmp 0x63c4
jmp 0x63d3
jmp 0x6446
jmp 0x63e7
jmp 0x63f6
jmp 0x6405
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x6438
jmp 0x645a
jmp 0x6430
jmp 0x645a
jmp 0x6441
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5508
jmp 0x63d6
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x5508
jmp 0x63ea
jmp 0x6446
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5508
jmp 0x63f9
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5508
jmp 0x6408
movq %rax, %rbx
movl $0x2780, %esi           # imm = 0x2780
movq %r14, %rdi
callq 0x52c0
jmp 0x6449
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x6438
jmp 0x645a
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x6438
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5508
jmp 0x645d
jmp 0x645a
movq %rax, %rbx
jmp 0x6467
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x737c
jmp 0x645d
jmp 0x645a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x5508
leaq 0x90(%rsp), %rdi
callq 0x5508
leaq 0xe8(%rsp), %rdi
callq 0x7240
movq %rbx, %rdi
callq 0x54a0
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x646f
movq %rax, %rbx
jmp 0x6474
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x5508
jmp 0x6481
movq %rax, %rbx
jmp 0x6481
nop