// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/main.cpp
// Function: main
int main(int argc, char* argv[])
{
	string ssd_config_file_path, workload_defs_file_path;
	if (argc != 5) {
		// MQSim expects 2 arguments: 1) the path to the SSD configuration definition file, and 2) the path to the workload definition file
		print_help();
		return 1;
	}

	command_line_args(argv, ssd_config_file_path, workload_defs_file_path);

	Execution_Parameter_Set* exec_params = new Execution_Parameter_Set;
	read_configuration_parameters(ssd_config_file_path, exec_params);
	std::vector<std::vector<IO_Flow_Parameter_Set*>*>* io_scenarios = read_workload_definitions(workload_defs_file_path);

	int cntr = 1;
	for (auto io_scen = io_scenarios->begin(); io_scen != io_scenarios->end(); io_scen++, cntr++) {
		time_t start_time = time(0);
		char* dt = ctime(&start_time);
		PRINT_MESSAGE("MQSim started at " << dt)
		PRINT_MESSAGE("******************************")
		PRINT_MESSAGE("Executing scenario " << cntr << " out of " << io_scenarios->size() << " .......")

		//The simulator should always be reset, before starting the actual simulation
		Simulator->Reset();

		exec_params->Host_Configuration.IO_Flow_Definitions.clear();
		for (auto io_flow_def = (*io_scen)->begin(); io_flow_def != (*io_scen)->end(); io_flow_def++) {
			exec_params->Host_Configuration.IO_Flow_Definitions.push_back(*io_flow_def);
		}

		SSD_Device ssd(&exec_params->SSD_Device_Configuration, &exec_params->Host_Configuration.IO_Flow_Definitions);//Create SSD_Device based on the specified parameters
		exec_params->Host_Configuration.Input_file_path = workload_defs_file_path.substr(0, workload_defs_file_path.find_last_of("."));//Create Host_System based on the specified parameters
		Host_System host(&exec_params->Host_Configuration, exec_params->SSD_Device_Configuration.Enabled_Preconditioning, ssd.Host_interface);
		host.Attach_ssd_device(&ssd);

		Simulator->Start_simulation();

		time_t end_time = time(0);
		dt = ctime(&end_time);
		PRINT_MESSAGE("MQSim finished at " << dt)
		uint64_t duration = (uint64_t)difftime(end_time, start_time);
		PRINT_MESSAGE("Total simulation time: " << duration / 3600 << ":" << (duration % 3600) / 60 << ":" << ((duration % 3600) % 60))
		PRINT_MESSAGE("");

		PRINT_MESSAGE("Writing results to output file .......");
		collect_results(ssd, host, (workload_defs_file_path.substr(0, workload_defs_file_path.find_last_of(".")) + "_scenario_" + std::to_string(cntr) + ".xml").c_str());
	}
    cout << "Simulation complete; Press any key to exit." << endl;

	cin.get(); // Disable if you prefer batch runs

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
leaq 0xd0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xb0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
cmpl $0x5, %edi
jne 0xa945
leaq 0xc0(%rsp), %rax
leaq 0xa0(%rsp), %rdx
movq %rsi, %rdi
movq %rax, %rsi
callq 0x879c
movl $0x8, %edi
callq 0x73a0
movq %rax, %rbx
leaq 0x63824(%rip), %rax     # 0x6d8f8
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x130(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %rdi
callq 0xaf32
leaq 0x120(%rsp), %rdi
movq %rbx, %rsi
callq 0x88e2
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0xa129
callq 0x7370
leaq 0x110(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %rdi
callq 0xaf32
leaq 0x100(%rsp), %rdi
callq 0x8fbd
movq %rax, 0x8(%rsp)
movq 0x100(%rsp), %rdi
cmpq %r14, %rdi
je 0xa179
callq 0x7370
movq 0x8(%rsp), %rax
movq (%rax), %r13
cmpq 0x8(%rax), %r13
je 0xa8ef
movl $0x1, 0x4(%rsp)
movq 0x64dee(%rip), %r15     # 0x6ef88
leaq 0x653f7(%rip), %r14     # 0x6f598
xorl %edi, %edi
callq 0x7350
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x7170
movq %rax, %rbx
movl $0x11, %edx
movq %r15, %rdi
leaq 0x4b275(%rip), %rsi     # 0x5543e
callq 0x7400
testq %rbx, %rbx
je 0xa1eb
movq %rbx, %rdi
callq 0x71a0
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7400
jmp 0xa203
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x75c0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movl $0x1e, %edx
movq %r15, %rdi
leaq 0x4b217(%rip), %rsi     # 0x55450
callq 0x7400
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movl $0x13, %edx
movq %r15, %rdi
leaq 0x4b1fb(%rip), %rsi     # 0x5546f
callq 0x7400
movq %r15, %rdi
movl 0x4(%rsp), %esi
callq 0x75f0
movq %rax, %rbx
movl $0x8, %edx
movq %rax, %rdi
leaq 0x4b1ec(%rip), %rsi     # 0x55483
callq 0x7400
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
movq %rbx, %rdi
callq 0x7280
movq %rax, %r12
movl $0x8, %edx
movq %rax, %rdi
leaq 0x4b20f(%rip), %rsi     # 0x554d5
callq 0x7400
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r12, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
callq 0x28018
movq %rax, %rdi
callq 0x28062
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0xa30d
movq %rax, 0x8(%r14)
movq (%r13), %rax
movq (%rax), %r12
cmpq 0x8(%rax), %r12
je 0xa347
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xa332
movq (%r12), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0xa33d
movq %r14, %rdi
movq %r12, %rdx
callq 0xc61a
addq $0x8, %r12
movq (%r13), %rax
jmp 0xa314
leaq 0x168(%rsp), %rdi
leaq 0x650ca(%rip), %rsi     # 0x6f420
movq %r14, %rdx
callq 0x1acc4
movl $0x1, %ecx
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4b167(%rip), %rsi     # 0x554dc
movq $-0x1, %rdx
callq 0x76a0
leaq 0x1e8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x73c0
leaq 0x651d8(%rip), %rdi     # 0x6f578
movq %r12, %rsi
callq 0x7450
movq 0x1e8(%rsp), %rdi
leaq 0x1f8(%rsp), %rax
cmpq %rax, %rdi
je 0xa3c2
callq 0x7370
leaq 0x64fb3(%rip), %rax     # 0x6f37c
movzbl (%rax), %edx
movq 0x1a8(%rsp), %rcx
movq %r12, %rdi
leaq 0x6503a(%rip), %rsi     # 0x6f418
callq 0x149cc
movq %r12, %rdi
leaq 0x168(%rsp), %rsi
callq 0x15ea0
callq 0x28018
movq %rax, %rdi
callq 0x28348
xorl %edi, %edi
callq 0x7350
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x7170
movq %rax, %rbx
movl $0x12, %edx
movq %r15, %rdi
leaq 0x4b064(%rip), %rsi     # 0x5548c
callq 0x7400
testq %rbx, %rbx
je 0xa44a
movq %rbx, %rdi
callq 0x71a0
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7400
jmp 0xa462
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x75c0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x71e0
movapd %xmm0, 0x140(%rsp)
subsd 0x4aba7(%rip), %xmm0    # 0x55050
movapd %xmm0, 0x150(%rsp)
movl $0x17, %edx
movq %r15, %rdi
leaq 0x4afde(%rip), %rsi     # 0x5549f
callq 0x7400
cvttsd2si 0x140(%rsp), %rax
movq %rax, %rcx
sarq $0x3f, %rcx
cvttsd2si 0x150(%rsp), %rbp
andq %rcx, %rbp
orq %rax, %rbp
movq %rbp, %rax
shrq $0x4, %rax
movabsq $0x91a2b3c4d5e6f81, %rcx # imm = 0x91A2B3C4D5E6F81
mulq %rcx
movq %rdx, %rbx
shrq $0x3, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c08e(%rip), %rsi     # 0x565ad
callq 0x7400
imulq $0xe10, %rbx, %rax      # imm = 0xE10
subq %rax, %rbp
movzwl %bp, %eax
imull $0x8889, %eax, %ebx     # imm = 0x8889
shrl $0x15, %ebx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x7280
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c056(%rip), %rsi     # 0x565ad
callq 0x7400
imull $0x3c, %ebx, %eax
subl %eax, %ebp
movzwl %bp, %esi
movq %r12, %rdi
callq 0x7280
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movq %r15, %rdi
leaq 0x4d43b(%rip), %rsi     # 0x579db
xorl %edx, %edx
callq 0x7400
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movl $0x26, %edx
movq %r15, %rdi
leaq 0x4aeda(%rip), %rsi     # 0x554b7
callq 0x7400
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq %r15, %rdi
callq 0x7040
movq %rax, %rdi
callq 0x7290
movl $0x1, %ecx
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4aebc(%rip), %rsi     # 0x554dc
movq $-0x1, %rdx
callq 0x76a0
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x73c0
movq %r12, %rdi
leaq 0x4ae90(%rip), %rsi     # 0x554de
callq 0x7690
leaq 0x1e8(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa683
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0xa68b
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x1, %r12d
cmpl $0xa, 0x4(%rsp)
jb 0xa6f8
movl $0x4, %r12d
movl 0x4(%rsp), %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0xa6ef
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0xa6f5
cmpl $0x2710, %eax           # imm = 0x2710
jb 0xa6f8
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r12d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0xa6bf
addl $-0x3, %r12d
jmp 0xa6f8
addl $-0x2, %r12d
jmp 0xa6f8
decl %r12d
movl %r12d, %esi
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x2d, %edx
callq 0x7420
movq 0x50(%rsp), %rdi
movl %r12d, %esi
movl 0x4(%rsp), %edx
callq 0xaec5
movq 0x30(%rsp), %rcx
movl $0xf, %edi
leaq 0x40(%rsp), %rax
cmpq %rax, %rcx
je 0xa73e
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0xa76f
movl $0xf, %edi
leaq 0x60(%rsp), %r9
cmpq %r9, %rsi
je 0xa76a
movq 0x60(%rsp), %rdi
cmpq %rdi, %rax
jbe 0xa77b
leaq 0x30(%rsp), %rdi
callq 0x7130
jmp 0xa789
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x73e0
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0xa7ae
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0xa7b6
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x10(%rsp), %rdi
leaq 0x4ad0a(%rip), %rsi     # 0x554e9
callq 0x7690
leaq 0x90(%rsp), %rsi
movq %rsi, 0x80(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa818
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0xa820
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x80(%rsp), %rdx
leaq 0x168(%rsp), %rdi
movq %rbx, %rsi
callq 0x9b23
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xa86d
callq 0x7370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa881
callq 0x7370
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa895
callq 0x7370
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa8a9
callq 0x7370
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xa8c3
callq 0x7370
movq %rbx, %rdi
callq 0x15d84
leaq 0x168(%rsp), %rdi
callq 0x1d550
addq $0x8, %r13
incl 0x4(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %r13
jne 0xa1a1
movq 0x64692(%rip), %rbx     # 0x6ef88
leaq 0x4abf1(%rip), %rsi     # 0x554ee
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x7400
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %esi
movq 0x64660(%rip), %rdi     # 0x6ef88
callq 0x7040
movq %rax, %rdi
callq 0x7290
xorl %ebx, %ebx
movq 0x64692(%rip), %rdi     # 0x6efd0
callq 0x7430
jmp 0xa94f
movl $0x1, %ebx
callq 0x9fa5
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xa969
callq 0x7370
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xa983
callq 0x7370
movl %ebx, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x100(%rsp), %rdi
jmp 0xa9b4
jmp 0xaa92
movq %rax, %rbx
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0xaa95
callq 0x7370
jmp 0xaa95
jmp 0xaa92
jmp 0xaa92
jmp 0xaa92
jmp 0xaa73
movq %rax, %rbx
jmp 0xaa48
movq %rax, %rbx
jmp 0xaa34
movq %rax, %rbx
jmp 0xaa20
movq %rax, %rbx
jmp 0xaa0c
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xaa0c
callq 0x7370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xaa20
callq 0x7370
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xaa34
callq 0x7370
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xaa48
callq 0x7370
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xaa76
callq 0x7370
jmp 0xaa76
jmp 0xaa92
jmp 0xaa68
movq %rax, %rbx
jmp 0xaa83
jmp 0xaa73
jmp 0xaa73
jmp 0xaa92
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x15d84
leaq 0x168(%rsp), %rdi
callq 0x1d550
jmp 0xaa95
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xaaaf
callq 0x7370
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xaac9
callq 0x7370
movq %rbx, %rdi
callq 0x7620
nop