// File: CMU-SAFARI[P]MQSim/src/main.cpp
// Function: read_configuration_parameters(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Execution_Parameter_Set*)
void read_configuration_parameters(const string ssd_config_file_path, Execution_Parameter_Set* exec_params)
{
	ifstream ssd_config_file;
	ssd_config_file.open(ssd_config_file_path.c_str());

	if (!ssd_config_file) {
		PRINT_MESSAGE("The specified SSD configuration file does not exist.")
		PRINT_MESSAGE("Using MQSim's default configuration.")
		PRINT_MESSAGE("Writing the default configuration parameters to the expected configuration file.")

		Utils::XmlWriter xmlwriter;
		string tmp;
		xmlwriter.Open(ssd_config_file_path.c_str());
		exec_params->XML_serialize(xmlwriter);
		xmlwriter.Close();
		PRINT_MESSAGE("[====================] Done!\n")
	} else {
		//Read input workload parameters
		string line((std::istreambuf_iterator<char>(ssd_config_file)),
			std::istreambuf_iterator<char>());
		ssd_config_file >> line;
		if (line.compare("USE_INTERNAL_PARAMS") != 0) {
			rapidxml::xml_document<> doc;    // character type defaults to char
			char* temp_string = new char[line.length() + 1];
			strcpy(temp_string, line.c_str());
			doc.parse<0>(temp_string);
			rapidxml::xml_node<> *mqsim_config = doc.first_node("Execution_Parameter_Set");
			if (mqsim_config != NULL) {
				exec_params = new Execution_Parameter_Set;
				exec_params->XML_deserialize(mqsim_config);
			} else {
				PRINT_MESSAGE("Error in the SSD configuration file!")
				PRINT_MESSAGE("Using MQSim's default configuration.")
			}
		} else {
			PRINT_MESSAGE("Using MQSim's default configuration.");
			PRINT_MESSAGE("Writing the default configuration parameters to the expected configuration file.");

			Utils::XmlWriter xmlwriter;
			string tmp;
			xmlwriter.Open(ssd_config_file_path.c_str());
			exec_params->XML_serialize(xmlwriter);
			xmlwriter.Close();
			PRINT_MESSAGE("[====================] Done!\n")
		}
	}

	ssd_config_file.close();
}

// Assembly:
subq $0x108c8, %rsp          # imm = 0x108C8
movq %rdi, 0xa0(%rsp)
movq %rdi, 0x108c0(%rsp)
movq %rsi, 0x108b8(%rsp)
leaq 0x106b0(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x84d0
movq 0xa0(%rsp), %rdi
callq 0x8190
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x82c0
jmp 0x9ce8
movq 0x106b0(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x106b0(%rsp,%rax), %rdi
callq 0x81e0
movb %al, 0x9f(%rsp)
jmp 0x9d0a
movb 0x9f(%rsp), %al
testb $0x1, %al
jne 0x9d1a
jmp 0x9f44
movq 0xd0277(%rip), %rdi     # 0xd9f98
leaq 0x9f2ee(%rip), %rsi     # 0xa9016
callq 0x8440
movq %rax, 0x90(%rsp)
jmp 0x9d37
movq 0x90(%rsp), %rdi
movq 0xd0212(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x9d4d
movq 0xd0244(%rip), %rdi     # 0xd9f98
leaq 0x9f2f0(%rip), %rsi     # 0xa904b
callq 0x8440
movq %rax, 0x88(%rsp)
jmp 0x9d6a
movq 0x88(%rsp), %rdi
movq 0xd01df(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x9d80
movq 0xd0211(%rip), %rdi     # 0xd9f98
leaq 0x9f2e2(%rip), %rsi     # 0xa9070
callq 0x8440
movq %rax, 0x80(%rsp)
jmp 0x9d9d
movq 0x80(%rsp), %rdi
movq 0xd01ac(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x9db3
leaq 0x10460(%rsp), %rdi
callq 0xc640
jmp 0x9dc2
leaq 0x10440(%rsp), %rdi
callq 0x85e0
movq 0xa0(%rsp), %rdi
callq 0x8190
movq %rax, 0x70(%rsp)
leaq 0x1041f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x8780
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x10420(%rsp), %rdi
callq 0x85d0
jmp 0x9e0c
leaq 0x10460(%rsp), %rdi
leaq 0x10420(%rsp), %rsi
callq 0xa7cb0
jmp 0x9e23
leaq 0x10420(%rsp), %rdi
callq 0x8848
leaq 0x1041f(%rsp), %rdi
callq 0x84a0
movq 0x108b8(%rsp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
leaq 0x10460(%rsp), %rsi
callq *%rax
jmp 0x9e57
leaq 0x10460(%rsp), %rdi
callq 0xa7d30
jmp 0x9e66
movq 0xd012b(%rip), %rdi     # 0xd9f98
leaq 0x9f24d(%rip), %rsi     # 0xa90c1
callq 0x8440
movq %rax, 0x68(%rsp)
jmp 0x9e80
movq 0x68(%rsp), %rdi
movq 0xd00cc(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x9e93
leaq 0x10440(%rsp), %rdi
callq 0x8848
leaq 0x10460(%rsp), %rdi
callq 0xc680
jmp 0xa3aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
jmp 0xa3ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
jmp 0x9f02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0x10420(%rsp), %rdi
callq 0x8848
leaq 0x1041f(%rsp), %rdi
callq 0x84a0
jmp 0x9f25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0x10440(%rsp), %rdi
callq 0x8848
leaq 0x10460(%rsp), %rdi
callq 0xc680
jmp 0xa3ce
leaq 0x103e8(%rsp), %rdi
leaq 0x106b0(%rsp), %rsi
callq 0xc6c0
leaq 0x103d8(%rsp), %rdi
callq 0xc720
leaq 0x103d7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x8780
movq 0x60(%rsp), %r9
movq 0x103e8(%rsp), %rsi
movl 0x103f0(%rsp), %edx
movq 0x103d8(%rsp), %rcx
movl 0x103e0(%rsp), %r8d
leaq 0x103f8(%rsp), %rdi
callq 0xc750
jmp 0x9fab
leaq 0x103d7(%rsp), %rdi
callq 0x84a0
leaq 0x106b0(%rsp), %rdi
leaq 0x103f8(%rsp), %rsi
callq 0x8540
jmp 0x9fcf
leaq 0x103f8(%rsp), %rdi
leaq 0x9f101(%rip), %rsi     # 0xa90df
callq 0x8140
cmpl $0x0, %eax
je 0xa1c0
leaq 0x348(%rsp), %rdi
callq 0xc7f0
jmp 0x9ffb
leaq 0x103f8(%rsp), %rdi
callq 0x8660
movq %rax, %rdi
incq %rdi
callq 0x8030
movq %rax, 0x58(%rsp)
jmp 0xa01a
movq 0x58(%rsp), %rax
movq %rax, 0x340(%rsp)
movq 0x340(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x103f8(%rsp), %rdi
callq 0x8190
movq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x8400
movq 0x340(%rsp), %rsi
leaq 0x348(%rsp), %rdi
callq 0xc820
jmp 0xa065
leaq 0x9f087(%rip), %rsi     # 0xa90f3
xorl %eax, %eax
movl %eax, %edx
leaq 0x348(%rsp), %rdi
movl $0x1, %ecx
callq 0xc960
movq %rax, 0x48(%rsp)
jmp 0xa089
movq 0x48(%rsp), %rax
movq %rax, 0x338(%rsp)
cmpq $0x0, 0x338(%rsp)
je 0xa152
movl $0x8, %edi
callq 0x8450
movq %rax, 0x40(%rsp)
jmp 0xa0b6
movq 0x40(%rsp), %rdi
callq 0xca50
movq 0x40(%rsp), %rax
movq %rax, 0x108b8(%rsp)
movq 0x108b8(%rsp), %rdi
movq 0x338(%rsp), %rsi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0xa0e8
jmp 0xa1ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0x103d7(%rsp), %rdi
callq 0x84a0
jmp 0xa3ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
jmp 0xa39b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0x348(%rsp), %rdi
callq 0xca80
jmp 0xa39b
movq 0xcfe3f(%rip), %rdi     # 0xd9f98
leaq 0x9efab(%rip), %rsi     # 0xa910b
callq 0x8440
movq %rax, 0x38(%rsp)
jmp 0xa16c
movq 0x38(%rsp), %rdi
movq 0xcfde0(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0xa17f
movq 0xcfe12(%rip), %rdi     # 0xd9f98
leaq 0x9eebe(%rip), %rsi     # 0xa904b
callq 0x8440
movq %rax, 0x30(%rsp)
jmp 0xa199
movq 0x30(%rsp), %rdi
movq 0xcfdb3(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0xa1ac
jmp 0xa1ae
leaq 0x348(%rsp), %rdi
callq 0xca80
jmp 0xa38c
movq 0xcfdd1(%rip), %rdi     # 0xd9f98
leaq 0x9ee7d(%rip), %rsi     # 0xa904b
callq 0x8440
movq %rax, 0x28(%rsp)
jmp 0xa1da
movq 0x28(%rsp), %rdi
movq 0xcfd72(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0xa1ed
movq 0xcfda4(%rip), %rdi     # 0xd9f98
leaq 0x9ee75(%rip), %rsi     # 0xa9070
callq 0x8440
movq %rax, 0x20(%rsp)
jmp 0xa207
movq 0x20(%rsp), %rdi
movq 0xcfd45(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0xa21a
leaq 0xf8(%rsp), %rdi
callq 0xc640
jmp 0xa229
leaq 0xd8(%rsp), %rdi
callq 0x85e0
movq 0xa0(%rsp), %rdi
callq 0x8190
movq %rax, 0x10(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x8780
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x85d0
jmp 0xa273
leaq 0xf8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xa7cb0
jmp 0xa28a
leaq 0xb8(%rsp), %rdi
callq 0x8848
leaq 0xb7(%rsp), %rdi
callq 0x84a0
movq 0x108b8(%rsp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
leaq 0xf8(%rsp), %rsi
callq *%rax
jmp 0xa2be
leaq 0xf8(%rsp), %rdi
callq 0xa7d30
jmp 0xa2cd
movq 0xcfcc4(%rip), %rdi     # 0xd9f98
leaq 0x9ede6(%rip), %rsi     # 0xa90c1
callq 0x8440
movq %rax, 0x8(%rsp)
jmp 0xa2e7
movq 0x8(%rsp), %rdi
movq 0xcfc65(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0xa2fa
leaq 0xd8(%rsp), %rdi
callq 0x8848
leaq 0xf8(%rsp), %rdi
callq 0xc680
jmp 0xa38c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
jmp 0xa34d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x8848
leaq 0xb7(%rsp), %rdi
callq 0x84a0
jmp 0xa370
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x106a8(%rsp)
movl %eax, 0x106a4(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x8848
leaq 0xf8(%rsp), %rdi
callq 0xc680
jmp 0xa39b
leaq 0x103f8(%rsp), %rdi
callq 0x8848
jmp 0xa3aa
leaq 0x103f8(%rsp), %rdi
callq 0x8848
jmp 0xa3ce
leaq 0x106b0(%rsp), %rdi
callq 0x80d0
jmp 0xa3b9
leaq 0x106b0(%rsp), %rdi
callq 0x8120
addq $0x108c8, %rsp          # imm = 0x108C8
retq
leaq 0x106b0(%rsp), %rdi
callq 0x8120
movq 0x106a8(%rsp), %rdi
callq 0x8770
nopl (%rax,%rax)