// File: CMU-SAFARI[P]MQSim/src/host/IO_Flow_Trace_Based.cpp
// Function: Host_Components::IO_Flow_Trace_Based::Generate_next_request()
Host_IO_Request *IO_Flow_Trace_Based::Generate_next_request()
{
	if (current_trace_line.size() == 0 || STAT_generated_request_count >= total_requests_to_be_generated)
	{
		return NULL;
	}

	Host_IO_Request *request = new Host_IO_Request;
	if (current_trace_line[ASCIITraceTypeColumn].compare(ASCIITraceWriteCode) == 0)
	{
		request->Type = Host_IO_Request_Type::WRITE;
		STAT_generated_write_request_count++;
	}
	else
	{
		request->Type = Host_IO_Request_Type::READ;
		STAT_generated_read_request_count++;
	}

	char *pEnd;
	request->LBA_count = std::strtoul(current_trace_line[ASCIITraceSizeColumn].c_str(), &pEnd, 0);

	request->Start_LBA = std::strtoull(current_trace_line[ASCIITraceAddressColumn].c_str(), &pEnd, 0);
	if (request->Start_LBA <= (end_lsa_on_device - start_lsa_on_device))
	{
		request->Start_LBA += start_lsa_on_device;
	}
	else
	{
		request->Start_LBA = start_lsa_on_device + request->Start_LBA % (end_lsa_on_device - start_lsa_on_device);
	}

	request->Arrival_time = time_offset + Simulator->Time();
	STAT_generated_request_count++;

	return request;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq %rdi, 0x10(%rsp)
addq $0x6b0, %rdi            # imm = 0x6B0
callq 0x3aef0
cmpq $0x0, %rax
je 0x395e5
movq 0x10(%rsp), %rcx
movl 0x150(%rcx), %eax
cmpl 0x50(%rcx), %eax
jb 0x395f3
movq $0x0, 0x30(%rsp)
jmp 0x3978b
movl $0x28, %edi
callq 0x8450
movq 0x10(%rsp), %rdi
movq %rax, 0x20(%rsp)
addq $0x6b0, %rdi            # imm = 0x6B0
movl $0x4, %esi
callq 0x3af10
movq %rax, %rdi
leaq 0x731c7(%rip), %rsi     # 0xac7e9
callq 0x8140
cmpl $0x0, %eax
jne 0x3964e
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movl $0x1, 0x1c(%rcx)
movl 0x158(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x158(%rax)
jmp 0x3966e
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movl $0x0, 0x1c(%rcx)
movl 0x154(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x154(%rax)
movq 0x10(%rsp), %rdi
addq $0x6b0, %rdi            # imm = 0x6B0
movl $0x3, %esi
callq 0x3af10
movq %rax, %rdi
callq 0x8190
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x8838
movq 0x10(%rsp), %rdi
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x18(%rax)
addq $0x6b0, %rdi            # imm = 0x6B0
movl $0x2, %esi
callq 0x3af10
movq %rax, %rdi
callq 0x8190
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x8850
movq 0x10(%rsp), %rdx
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x70(%rdx), %rcx
subq 0x68(%rdx), %rcx
cmpq %rcx, %rax
ja 0x39711
movq 0x10(%rsp), %rax
movq 0x68(%rax), %rcx
movq 0x20(%rsp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x3973c
movq 0x10(%rsp), %rdx
movq 0x68(%rdx), %rcx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x70(%rdx), %rsi
subq 0x68(%rdx), %rsi
xorl %edx, %edx
divq %rsi
addq %rdx, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rsp), %rax
movq 0x6c8(%rax), %rax
movq %rax, 0x8(%rsp)
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq 0x8(%rsp), %rdx
movq %rax, %rcx
movq 0x10(%rsp), %rax
addq %rcx, %rdx
movq 0x20(%rsp), %rcx
movq %rdx, (%rcx)
movl 0x150(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x150(%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)