// File: /workspace/github_cpp_makefile_star2_O3/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 0x1e8d4
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 0x2300c
movq 0x4c289(%rip), %rdi     # 0x6ef88
leaq 0x35111(%rip), %rsi     # 0x57e17
movl $0x20, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4c263(%rip), %rdi     # 0x6ef88
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 0x22e8d
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rsi
cmpb $0xd, -0x1(%rax,%rsi)
jne 0x22dbc
decq %rsi
movl $0x1, %edx
movq %r13, %rdi
callq 0x70d0
movq %r12, %rdi
callq 0x23bd2
movq %r13, %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0x23c18
movq 0x6b0(%rbx), %rax
movq 0x6b8(%rbx), %rcx
subq %rax, %rcx
cmpq $0xa0, %rcx
jne 0x22e8d
incl 0x6a8(%rbx)
movq (%rax), %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x7070
cmpq %rbp, %rax
movq %rax, %rbp
jae 0x22d67
movq %rax, %r15
movq 0x4c1d0(%rip), %rdi     # 0x6eff0
leaq 0x33781(%rip), %rsi     # 0x565a8
movl $0x6, %edx
callq 0x7400
movq 0x4c1b8(%rip), %rdi     # 0x6eff0
leaq 0x34ff9(%rip), %rsi     # 0x57e38
movl $0x21, %edx
callq 0x7400
movq 0x4c1a0(%rip), %rdi     # 0x6eff0
movq %r15, %rsi
callq 0x7280
movq %rax, %rbx
leaq 0x34ff8(%rip), %rsi     # 0x57e5a
movl $0x57, %edx
movq %rax, %rdi
callq 0x7400
movq %rbx, %rdi
callq 0x71c0
movq 0x4c152(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
movq %r14, %rdi
callq 0x70b0
movq 0x4c0ec(%rip), %rdi     # 0x6ef88
leaq 0x3500f(%rip), %rsi     # 0x57eb2
movl $0xc, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4c0c6(%rip), %rdi     # 0x6ef88
callq 0x7400
movq %rax, %r15
leaq 0x34fee(%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 0x22f38
movl 0x470(%rbx), %eax
cvtsi2sd %rax, %xmm0
divsd 0x33f7d(%rip), %xmm0    # 0x56ea0
movl 0x6a8(%rbx), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
jmp 0x22f3f
imull 0x6a8(%rbx), %eax
movl %eax, 0x50(%rbx)
movq %r14, %rdi
movq 0x28(%rsp), %rsi
movl $0x8, %edx
callq 0x7330
movq %r12, %rdi
callq 0x23bd2
movq (%r14), %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 0x22fa3
decq %rsi
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x70d0
leaq 0x8(%rsp), %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0x23c18
callq 0x28018
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 0x2841e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x22ffd
callq 0x7370
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4bfdd(%rip), %rdi     # 0x6eff0
leaq 0x3358e(%rip), %rsi     # 0x565a8
movl $0x6, %edx
callq 0x7400
movq 0x4bfc5(%rip), %rdi     # 0x6eff0
leaq 0x34dbe(%rip), %rsi     # 0x57df0
movl $0x26, %edx
callq 0x7400
movq 0x478(%rbx), %rsi
movq 0x480(%rbx), %rdx
movq 0x4bf9f(%rip), %rdi     # 0x6eff0
callq 0x7400
movq %rax, %rdi
callq 0x71c0
movq 0x4bf6b(%rip), %rdi     # 0x6efd0
callq 0x7430
jmp 0x22e83
jmp 0x23075
jmp 0x23075
jmp 0x23075
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2308c
callq 0x7370
movq %rbx, %rdi
callq 0x7620