// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]MQSim/src/host/IO_Flow_Trace_Based.cpp
// Function: Host_Components::IO_Flow_Trace_Based::Start_simulation()
void IO_Flow_Trace_Based::Start_simulation()
{
	IO_Flow_Base::Start_simulation();
	std::string trace_line;
	char *pEnd;

	trace_file.open(trace_file_path, std::ios::in);
	if (!trace_file.is_open())
	{
		PRINT_ERROR("Error while opening input trace file: " << trace_file_path)
	}
	PRINT_MESSAGE("Investigating input trace file: " << trace_file_path);

	sim_time_type last_request_arrival_time = 0;
	while (std::getline(trace_file, trace_line))
	{
		Utils::Helper_Functions::Remove_cr(trace_line);
		current_trace_line.clear();
		Utils::Helper_Functions::Tokenize(trace_line, ASCIILineDelimiter, current_trace_line);
		if (current_trace_line.size() != ASCIIItemsPerLine)
		{
			break;
		}
		total_requests_in_file++;
		sim_time_type prev_time = last_request_arrival_time;
		last_request_arrival_time = std::strtoll(current_trace_line[ASCIITraceTimeColumn].c_str(), &pEnd, 10);
		if (last_request_arrival_time < prev_time)
		{
			PRINT_ERROR("Unexpected request arrival time: " << last_request_arrival_time << "\nMQSim expects request arrival times to be monotonically increasing in the input trace!")
		}
	}

	trace_file.close();
	PRINT_MESSAGE("Trace file: " << trace_file_path << " seems healthy");

	if (total_replay_no == 1)
	{
		total_requests_to_be_generated = (int)(((double)percentage_to_be_simulated / 100) * total_requests_in_file);
	}
	else
	{
		total_requests_to_be_generated = total_requests_in_file * total_replay_no;
	}

	trace_file.open(trace_file_path);
	current_trace_line.clear();
	std::getline(trace_file, trace_line);
	Utils::Helper_Functions::Remove_cr(trace_line);
	Utils::Helper_Functions::Tokenize(trace_line, ASCIILineDelimiter, current_trace_line);
	Simulator->Register_sim_event(std::strtoll(current_trace_line[ASCIITraceTimeColumn].c_str(), &pEnd, 10), this);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
callq 0x1e98c
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x498(%rbx), %r14
leaq 0x478(%rbx), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x7330
leaq 0x510(%rbx), %rdi
callq 0x70e0
testb %al, %al
je 0x2312c
movq 0x4c175(%rip), %rdi     # 0x6ef90
leaq 0x34ff5(%rip), %rsi     # 0x57e17
movl $0x20, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4c14f(%rip), %rdi     # 0x6ef90
callq 0x7400
movq %rax, %r15
movq (%rax), %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 %r12, 0x28(%rsp)
leaq 0x6b0(%rbx), %r12
xorl %ebp, %ebp
leaq 0x8(%rsp), %r13
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x7660
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x22fa9
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rsi
cmpb $0xd, -0x1(%rax,%rsi)
jne 0x22ed8
decq %rsi
movl $0x1, %edx
movq %r13, %rdi
callq 0x70d0
movq %r12, %rdi
callq 0x23d70
movq %r13, %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0x23db6
movq 0x6b0(%rbx), %rax
movq 0x6b8(%rbx), %rcx
subq %rax, %rcx
cmpq $0xa0, %rcx
jne 0x22fa9
incl 0x6a8(%rbx)
movq (%rax), %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x7070
cmpq %rbp, %rax
movq %rax, %rbp
jae 0x22e83
movq %rax, %r15
movq 0x4c0b4(%rip), %rdi     # 0x6eff0
leaq 0x33665(%rip), %rsi     # 0x565a8
movl $0x6, %edx
callq 0x7400
movq 0x4c09c(%rip), %rdi     # 0x6eff0
leaq 0x34edd(%rip), %rsi     # 0x57e38
movl $0x21, %edx
callq 0x7400
movq 0x4c084(%rip), %rdi     # 0x6eff0
movq %r15, %rsi
callq 0x7280
movq %rax, %rbx
leaq 0x34edc(%rip), %rsi     # 0x57e5a
movl $0x57, %edx
movq %rax, %rdi
callq 0x7400
movq %rbx, %rdi
callq 0x71c0
movq 0x4c036(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
movq %r14, %rdi
callq 0x70b0
movq 0x4bfd8(%rip), %rdi     # 0x6ef90
leaq 0x34ef3(%rip), %rsi     # 0x57eb2
movl $0xc, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4bfb2(%rip), %rdi     # 0x6ef90
callq 0x7400
movq %rax, %r15
leaq 0x34ed2(%rip), %rsi     # 0x57ebf
movl $0xe, %edx
movq %rax, %rdi
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 0x6a0(%rbx), %eax
cmpl $0x1, %eax
jne 0x23054
movl 0x470(%rbx), %eax
cvtsi2sd %rax, %xmm0
divsd 0x33e61(%rip), %xmm0    # 0x56ea0
movl 0x6a8(%rbx), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
jmp 0x2305b
imull 0x6a8(%rbx), %eax
movl %eax, 0x50(%rbx)
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movl $0x8, %edx
callq 0x7330
movq %r12, %rdi
callq 0x23d70
movq 0x498(%rbx), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7380
movsbl %al, %edx
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x7660
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rsi
cmpb $0xd, -0x1(%rax,%rsi)
jne 0x230c3
decq %rsi
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x70d0
leaq 0x8(%rsp), %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0x23db6
callq 0x281b4
movq %rax, %r14
movq 0x6b0(%rbx), %rax
movq (%rax), %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x7070
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x285aa
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2311d
callq 0x7370
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4bebd(%rip), %rdi     # 0x6eff0
leaq 0x3346e(%rip), %rsi     # 0x565a8
movl $0x6, %edx
callq 0x7400
movq 0x4bea5(%rip), %rdi     # 0x6eff0
leaq 0x34c9e(%rip), %rsi     # 0x57df0
movl $0x26, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4be7f(%rip), %rdi     # 0x6eff0
callq 0x7400
movq %rax, %rdi
callq 0x71c0
movq 0x4be4b(%rip), %rdi     # 0x6efd0
callq 0x7430
jmp 0x22f9f
jmp 0x23195
jmp 0x23195
jmp 0x23195
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x231ac
callq 0x7370
movq %rbx, %rdi
callq 0x7620