// File: /workspace/github_cpp_makefile_star2_O2/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 0x179c6
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x498(%rbx), %rdi
leaq 0x478(%rbx), %r14
pushq $0x8
popq %rdx
movq %rdi, (%rsp)
movq %r14, %rsi
callq 0x72f0
leaq 0x510(%rbx), %rdi
callq 0x70d0
testb %al, %al
je 0x1b3a0
movq 0x46de9(%rip), %rdi     # 0x61f78
leaq 0x2ab91(%rip), %rsi     # 0x45d27
callq 0x7360
movq %rax, %rdi
movq %r14, %rsi
callq 0x7310
movq %rax, %rdi
callq 0x71a0
movq %r14, 0x8(%rsp)
leaq 0x6b0(%rbx), %r12
xorl %r15d, %r15d
leaq 0x18(%rsp), %r13
pushq $0x20
popq %rbp
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x7080
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1b297
movq %r13, %rdi
callq 0x1bc76
movq %r12, %rdi
callq 0x1bc90
movq %r13, %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x1bc98
movq 0x6b0(%rbx), %rax
movq 0x6b8(%rbx), %rcx
subq %rax, %rcx
cmpq $0xa0, %rcx
jne 0x1b297
incl 0x6a8(%rbx)
movq (%rax), %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x7660
cmpq %r15, %rax
movq %rax, %r15
jae 0x1b1c5
movq %rax, %r14
movq 0x46dae(%rip), %rdi     # 0x61ff0
leaq 0x2933f(%rip), %rsi     # 0x44588
callq 0x7360
movq 0x46d9b(%rip), %rdi     # 0x61ff0
leaq 0x2aaec(%rip), %rsi     # 0x45d48
callq 0x7360
movq %rax, %rdi
movq %r14, %rsi
callq 0x7270
leaq 0x2aaf7(%rip), %rsi     # 0x45d6a
movq %rax, %rdi
callq 0x7360
movq %rax, %rdi
callq 0x71a0
movq 0x46d46(%rip), %rdi     # 0x61fd0
callq 0x73d0
pushq $0x1
popq %rdi
callq 0x73e0
movq (%rsp), %rdi
callq 0x70a0
movq 0x46cd1(%rip), %rdi     # 0x61f78
leaq 0x2ab14(%rip), %rsi     # 0x45dc2
callq 0x7360
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x7310
leaq 0x2ab08(%rip), %rsi     # 0x45dcf
movq %rax, %rdi
callq 0x7360
movq %rax, %rdi
callq 0x71a0
movl 0x6a0(%rbx), %eax
cmpl $0x1, %eax
jne 0x1b30a
movl 0x470(%rbx), %eax
cvtsi2sd %rax, %xmm0
divsd 0x29b3b(%rip), %xmm0    # 0x44e30
movl 0x6a8(%rbx), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
jmp 0x1b311
imull 0x6a8(%rbx), %eax
movl %eax, 0x50(%rbx)
pushq $0x8
popq %rdx
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x72f0
movq %r12, %rdi
callq 0x1bc90
leaq 0x18(%rsp), %rsi
movq (%rsp), %rdi
callq 0x7080
leaq 0x18(%rsp), %rdi
callq 0x1bc76
leaq 0x18(%rsp), %rdi
pushq $0x20
popq %rsi
movq %r12, %rdx
callq 0x1bc98
callq 0x1f784
movq %rax, %r14
movq 0x6b0(%rbx), %rax
movq (%rax), %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x7660
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1fb00
leaq 0x18(%rsp), %rdi
callq 0x7678
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x46c49(%rip), %rdi     # 0x61ff0
leaq 0x291da(%rip), %rsi     # 0x44588
callq 0x7360
movq 0x46c36(%rip), %rdi     # 0x61ff0
leaq 0x2a93f(%rip), %rsi     # 0x45d00
callq 0x7360
movq %rax, %rdi
movq %r14, %rsi
callq 0x7310
movq %rax, %rdi
callq 0x71a0
movq 0x46bf0(%rip), %rdi     # 0x61fd0
callq 0x73d0
jmp 0x1b28f
jmp 0x1b3f0
jmp 0x1b3f0
jmp 0x1b3f0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x7678
movq %rbx, %rdi
callq 0x75d0
nop