// File: /workspace/github_cpp_makefile_star2_O1/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 0xa9c3
leaq 0xc0(%rsp), %rax
leaq 0xa0(%rsp), %rdx
movq %rsi, %rdi
movq %rax, %rsi
callq 0x87ec
movl $0x8, %edi
callq 0x73a0
movq %rax, %rbx
leaq 0x637a5(%rip), %rax     # 0x6d8e8
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 0xb036
leaq 0x120(%rsp), %rdi
movq %rbx, %rsi
callq 0x8932
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0xa198
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 0xb036
leaq 0x100(%rsp), %rdi
callq 0x9011
movq %rax, 0x8(%rsp)
movq 0x100(%rsp), %rdi
cmpq %r14, %rdi
je 0xa1e8
callq 0x7370
movq 0x8(%rsp), %rax
movq (%rax), %rbp
cmpq 0x8(%rax), %rbp
je 0xa96d
movl $0x1, 0x4(%rsp)
movq 0x64d87(%rip), %r15     # 0x6ef90
leaq 0x65388(%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 0x4b206(%rip), %rsi     # 0x5543e
callq 0x7400
testq %rbx, %rbx
je 0xa25a
movq %rbx, %rdi
callq 0x71a0
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7400
jmp 0xa272
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 0x4b1a8(%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 0x4b18c(%rip), %rsi     # 0x5546f
callq 0x7400
movq %r15, %rdi
movl 0x4(%rsp), %esi
callq 0x75f0
movq %rax, %rbx
movl $0x8, %edx
movq %rax, %rdi
leaq 0x4b17d(%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 0x4b1a0(%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 0x281b4
movq %rax, %rdi
callq 0x28200
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0xa37c
movq %rax, 0x8(%r14)
movq (%rbp), %rax
movq (%rax), %r12
cmpq 0x8(%rax), %r12
je 0xa3b6
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xa3a1
movq (%r12), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r14)
jmp 0xa3ac
movq %r14, %rdi
movq %r12, %rdx
callq 0xc754
addq $0x8, %r12
movq (%rbp), %rax
jmp 0xa383
leaq 0x168(%rsp), %rdi
leaq 0x6505b(%rip), %rsi     # 0x6f420
movq %r14, %rdx
callq 0x1ad58
movl $0x1, %ecx
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4b0f8(%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 0x65169(%rip), %rdi     # 0x6f578
movq %r12, %rsi
callq 0x7450
movq 0x1e8(%rsp), %rdi
leaq 0x1f8(%rsp), %rax
cmpq %rax, %rdi
je 0xa431
callq 0x7370
leaq 0x64f44(%rip), %rax     # 0x6f37c
movzbl (%rax), %edx
movq 0x1a8(%rsp), %rcx
movq %r12, %rdi
leaq 0x64fcb(%rip), %rsi     # 0x6f418
callq 0x14ac0
movq %r12, %rdi
leaq 0x168(%rsp), %rsi
callq 0x15faa
callq 0x281b4
movq %rax, %rdi
callq 0x284de
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 0x4aff5(%rip), %rsi     # 0x5548c
callq 0x7400
testq %rbx, %rbx
je 0xa4b9
movq %rbx, %rdi
callq 0x71a0
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x7400
jmp 0xa4d1
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 0x4ab38(%rip), %xmm0    # 0x55050
movapd %xmm0, 0x150(%rsp)
movl $0x17, %edx
movq %r15, %rdi
leaq 0x4af6f(%rip), %rsi     # 0x5549f
callq 0x7400
cvttsd2si 0x140(%rsp), %rax
movq %rax, %rcx
sarq $0x3f, %rcx
cvttsd2si 0x150(%rsp), %r12
andq %rcx, %r12
orq %rax, %r12
movq %r12, %rax
shrq $0x4, %rax
movabsq $0x91a2b3c4d5e6f81, %rcx # imm = 0x91A2B3C4D5E6F81
mulq %rcx
movq %rdx, %r13
shrq $0x3, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x7280
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c01f(%rip), %rsi     # 0x565ad
callq 0x7400
imulq $0xe10, %r13, %rax      # imm = 0xE10
subq %rax, %r12
movq %r12, %rax
movabsq $-0x7777777777777777, %rcx # imm = 0x8888888888888889
mulq %rcx
movq %rdx, %r13
shrq $0x5, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x7280
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4bfdc(%rip), %rsi     # 0x565ad
callq 0x7400
imulq $0x3c, %r13, %rax
subq %rax, %r12
movq %rbx, %rdi
movq %r12, %rsi
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 0x4d3bf(%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 0x4ae5e(%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 0x4ae40(%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 0x4ae14(%rip), %rsi     # 0x554de
callq 0x7690
leaq 0x1e8(%rsp), %rbx
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa6ff
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0xa707
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x1, %r12d
cmpl $0xa, 0x4(%rsp)
jb 0xa774
movl $0x4, %r12d
movl 0x4(%rsp), %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0xa76b
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0xa771
cmpl $0x2710, %eax           # imm = 0x2710
jb 0xa774
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %r12d
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0xa73b
addl $-0x3, %r12d
jmp 0xa774
addl $-0x2, %r12d
jmp 0xa774
decl %r12d
movl %r12d, %esi
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
movl $0x2d, %edx
callq 0x7420
movq 0x30(%rsp), %rdi
movl %r12d, %esi
movl 0x4(%rsp), %edx
callq 0xafc9
movq 0x50(%rsp), %rcx
movl $0xf, %esi
leaq 0x60(%rsp), %rax
cmpq %rax, %rcx
je 0xa7ba
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %r8
movq 0x38(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0xa7e8
movl $0xf, %esi
leaq 0x40(%rsp), %rdi
cmpq %rdi, 0x30(%rsp)
je 0xa7e3
movq 0x40(%rsp), %rsi
cmpq %rsi, %rax
jbe 0xa7f9
movq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x7130
jmp 0xa807
leaq 0x30(%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 0xa82c
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0xa834
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 0x4ac8c(%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 0xa896
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0xa89e
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 0x9b92
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xa8eb
callq 0x7370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa8ff
callq 0x7370
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa913
callq 0x7370
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa927
callq 0x7370
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xa941
callq 0x7370
movq %rbx, %rdi
callq 0x15e84
leaq 0x168(%rsp), %rdi
callq 0x1d608
addq $0x8, %rbp
incl 0x4(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %rbp
jne 0xa210
movq 0x6461c(%rip), %rbx     # 0x6ef90
leaq 0x4ab73(%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 0x645ea(%rip), %rdi     # 0x6ef90
callq 0x7040
movq %rax, %rdi
callq 0x7290
xorl %ebx, %ebx
movq 0x64614(%rip), %rdi     # 0x6efd0
callq 0x7430
jmp 0xa9cd
movl $0x1, %ebx
callq 0xa014
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xa9e7
callq 0x7370
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xaa01
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 0xaa32
jmp 0xab10
movq %rax, %rbx
movq 0x120(%rsp), %rdi
cmpq %r14, %rdi
je 0xab13
callq 0x7370
jmp 0xab13
jmp 0xab10
jmp 0xab10
jmp 0xab10
jmp 0xaaf1
movq %rax, %rbx
jmp 0xaac6
movq %rax, %rbx
jmp 0xaab2
movq %rax, %rbx
jmp 0xaa9e
movq %rax, %rbx
jmp 0xaa8a
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xaa8a
callq 0x7370
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xaa9e
callq 0x7370
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xaab2
callq 0x7370
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xaac6
callq 0x7370
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0xaaf4
callq 0x7370
jmp 0xaaf4
jmp 0xab10
jmp 0xaae6
movq %rax, %rbx
jmp 0xab01
jmp 0xaaf1
jmp 0xaaf1
jmp 0xab10
movq %rax, %rbx
leaq 0x1e8(%rsp), %rdi
callq 0x15e84
leaq 0x168(%rsp), %rdi
callq 0x1d608
jmp 0xab13
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0xab2d
callq 0x7370
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0xab47
callq 0x7370
movq %rbx, %rdi
callq 0x7620
nop