// File: CMU-SAFARI[P]MQSim/src/host/IO_Flow_Base.cpp
// Function: Host_Components::IO_Flow_Base::SATA_consume_io_request(Host_Components::Host_IO_Request*)
void IO_Flow_Base::SATA_consume_io_request(Host_IO_Request* request)
	{
		sim_time_type device_response_time = Simulator->Time() - request->Enqueue_time;
		sim_time_type request_delay = Simulator->Time() - request->Arrival_time;
		
		STAT_serviced_request_count++;
		STAT_serviced_request_count_short_term++;
		STAT_sum_device_response_time += device_response_time;
		STAT_sum_device_response_time_short_term += device_response_time;
		STAT_sum_request_delay += request_delay;
		STAT_sum_request_delay_short_term += request_delay;
		if (device_response_time > STAT_max_device_response_time) {
			STAT_max_device_response_time = device_response_time;
		}
		if (device_response_time < STAT_min_device_response_time) {
			STAT_min_device_response_time = device_response_time;
		}
		if (request_delay > STAT_max_request_delay) {
			STAT_max_request_delay = request_delay;
		}
		if (request_delay < STAT_min_request_delay) {
			STAT_min_request_delay = request_delay;
		}
		STAT_transferred_bytes_total += request->LBA_count * SECTOR_SIZE_IN_BYTE;

		if (request->Type == Host_IO_Request_Type::READ) {
			STAT_serviced_read_request_count++;
			STAT_sum_device_response_time_read += device_response_time;
			STAT_sum_request_delay_read += request_delay;
			if (device_response_time > STAT_max_device_response_time_read) {
				STAT_max_device_response_time_read = device_response_time;
			}
			if (device_response_time < STAT_min_device_response_time_read) {
				STAT_min_device_response_time_read = device_response_time;
			}
			if (request_delay > STAT_max_request_delay_read) {
				STAT_max_request_delay_read = request_delay;
			}
			if (request_delay < STAT_min_request_delay_read) {
				STAT_min_request_delay_read = request_delay;
			}
			STAT_transferred_bytes_read += request->LBA_count * SECTOR_SIZE_IN_BYTE;
		} else {
			STAT_serviced_write_request_count++;
			STAT_sum_device_response_time_write += device_response_time;
			STAT_sum_request_delay_write += request_delay;
			if (device_response_time > STAT_max_device_response_time_write) {
				STAT_max_device_response_time_write = device_response_time;
			}
			if (device_response_time < STAT_min_device_response_time_write) {
				STAT_min_device_response_time_write = device_response_time;
			}
			if (request_delay > STAT_max_request_delay_write) {
				STAT_max_request_delay_write = request_delay;
			}
			if (request_delay < STAT_min_request_delay_write) {
				STAT_min_request_delay_write = request_delay;
			}
			STAT_transferred_bytes_write += request->LBA_count * SECTOR_SIZE_IN_BYTE;
		}

		delete request;

		//Announce simulation progress
		if (stop_time > 0) {
			progress = int(Simulator->Time() / (double)stop_time * 100);
		} else {
			progress = int(STAT_serviced_request_count / (double)total_requests_to_be_generated * 100);
		}
		if (progress >= next_progress_step) {
			std::string progress_bar;
			int barWidth = 100;
			progress_bar += "[";
			int pos = progress;
			for (int i = 0; i < barWidth; i += 5) {
				if (i < pos) {
					progress_bar += "=";
				} else if (i == pos) {
					progress_bar += ">";
				} else {
					progress_bar += " ";
				}
			}
			progress_bar += "] ";
			PRINT_MESSAGE(progress_bar << " " << progress << "% progress in " << ID() << std::endl)
				next_progress_step += 5;
		}

		if (Simulator->Time() > next_logging_milestone) {
			log_file << Simulator->Time() / SIM_TIME_TO_MICROSECONDS_COEFF << "\t" << Get_device_response_time_short_term() << "\t" << Get_end_to_end_request_delay_short_term() << std::endl;
			STAT_sum_device_response_time_short_term = 0;
			STAT_sum_request_delay_short_term = 0;
			STAT_serviced_request_count_short_term = 0;
			next_logging_milestone = Simulator->Time() + logging_period;
		}
	}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq 0xd8(%rsp), %rcx
subq 0x8(%rcx), %rax
movq %rax, 0xd0(%rsp)
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq 0x60(%rsp), %rcx
movq 0xd8(%rsp), %rdx
subq (%rdx), %rax
movq %rax, 0xc8(%rsp)
movl 0x160(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x160(%rcx)
movl 0x468(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x468(%rcx)
movq 0xd0(%rsp), %rax
addq 0x170(%rcx), %rax
movq %rax, 0x170(%rcx)
movq 0xd0(%rsp), %rax
addq 0x458(%rcx), %rax
movq %rax, 0x458(%rcx)
movq 0xc8(%rsp), %rax
addq 0x1b8(%rcx), %rax
movq %rax, 0x1b8(%rcx)
movq 0xc8(%rsp), %rax
addq 0x460(%rcx), %rax
movq %rax, 0x460(%rcx)
movq 0xd0(%rsp), %rax
cmpq 0x1a0(%rcx), %rax
jbe 0x30a75
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x1a0(%rax)
movq 0x60(%rsp), %rcx
movq 0xd0(%rsp), %rax
cmpq 0x188(%rcx), %rax
jae 0x30a9f
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x188(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1e8(%rcx), %rax
jbe 0x30ac9
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1e8(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1d0(%rcx), %rax
jae 0x30af3
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1d0(%rax)
movq 0x60(%rsp), %rax
movq 0xd8(%rsp), %rcx
movl 0x18(%rcx), %ecx
shll $0x9, %ecx
movl %ecx, %ecx
addq 0x200(%rax), %rcx
movq %rcx, 0x200(%rax)
movq 0xd8(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x30c33
movq 0x60(%rsp), %rcx
movl 0x164(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x164(%rcx)
movq 0xd0(%rsp), %rax
addq 0x178(%rcx), %rax
movq %rax, 0x178(%rcx)
movq 0xc8(%rsp), %rax
addq 0x1c0(%rcx), %rax
movq %rax, 0x1c0(%rcx)
movq 0xd0(%rsp), %rax
cmpq 0x1a8(%rcx), %rax
jbe 0x30b8d
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x1a8(%rax)
movq 0x60(%rsp), %rcx
movq 0xd0(%rsp), %rax
cmpq 0x190(%rcx), %rax
jae 0x30bb7
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x190(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1f0(%rcx), %rax
jbe 0x30be1
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1f0(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1d8(%rcx), %rax
jae 0x30c0b
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1d8(%rax)
movq 0x60(%rsp), %rax
movq 0xd8(%rsp), %rcx
movl 0x18(%rcx), %ecx
shll $0x9, %ecx
movl %ecx, %ecx
addq 0x208(%rax), %rcx
movq %rcx, 0x208(%rax)
jmp 0x30d39
movq 0x60(%rsp), %rcx
movl 0x168(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x168(%rcx)
movq 0xd0(%rsp), %rax
addq 0x180(%rcx), %rax
movq %rax, 0x180(%rcx)
movq 0xc8(%rsp), %rax
addq 0x1c8(%rcx), %rax
movq %rax, 0x1c8(%rcx)
movq 0xd0(%rsp), %rax
cmpq 0x1b0(%rcx), %rax
jbe 0x30c98
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x1b0(%rax)
movq 0x60(%rsp), %rcx
movq 0xd0(%rsp), %rax
cmpq 0x198(%rcx), %rax
jae 0x30cc2
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x198(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1f8(%rcx), %rax
jbe 0x30cec
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1f8(%rax)
movq 0x60(%rsp), %rcx
movq 0xc8(%rsp), %rax
cmpq 0x1e0(%rcx), %rax
jae 0x30d16
movq 0x60(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq %rcx, 0x1e0(%rax)
movq 0x60(%rsp), %rax
movq 0xd8(%rsp), %rcx
movl 0x18(%rcx), %ecx
shll $0x9, %ecx
movl %ecx, %ecx
addq 0x210(%rax), %rcx
movq %rcx, 0x210(%rax)
movq 0xd8(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
je 0x30d56
movq 0x58(%rsp), %rdi
callq 0x8410
movq 0x60(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jbe 0x30dd2
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, %xmm0
movaps 0x7ac2d(%rip), %xmm3    # 0xab9b0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x7ac31(%rip), %xmm2    # 0xab9c0
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x48(%rax), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x7a316(%rip), %xmm1    # 0xab0d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x218(%rax)
jmp 0x30e04
movq 0x60(%rsp), %rax
movl 0x50(%rax), %ecx
movl 0x160(%rax), %edx
cvtsi2sd %rdx, %xmm0
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movsd 0x7a2e2(%rip), %xmm1    # 0xab0d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x218(%rax)
movq 0x60(%rsp), %rcx
movl 0x218(%rcx), %eax
cmpl 0x21c(%rcx), %eax
jl 0x31043
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x85e0
movq 0x50(%rsp), %rdi
movl $0x64, 0xa4(%rsp)
leaq 0x7ac4e(%rip), %rsi     # 0xaba92
callq 0x8430
jmp 0x30e4b
movq 0x60(%rsp), %rax
movl 0x218(%rax), %eax
movl %eax, 0x90(%rsp)
movl $0x0, 0x8c(%rsp)
movl 0x8c(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jge 0x30f17
movl 0x8c(%rsp), %eax
cmpl 0x90(%rsp), %eax
jge 0x30ebd
leaq 0x7875e(%rip), %rsi     # 0xa95f1
leaq 0xa8(%rsp), %rdi
callq 0x8430
jmp 0x30ea2
jmp 0x30eff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x31031
movl 0x8c(%rsp), %eax
cmpl 0x90(%rsp), %eax
jne 0x30ee5
leaq 0x786ae(%rip), %rsi     # 0xa9582
leaq 0xa8(%rsp), %rdi
callq 0x8430
jmp 0x30ee3
jmp 0x30efd
leaq 0x7afb2(%rip), %rsi     # 0xabe9e
leaq 0xa8(%rsp), %rdi
callq 0x8430
jmp 0x30efb
jmp 0x30efd
jmp 0x30eff
jmp 0x30f01
movl 0x8c(%rsp), %eax
addl $0x5, %eax
movl %eax, 0x8c(%rsp)
jmp 0x30e68
leaq 0x7ab76(%rip), %rsi     # 0xaba94
leaq 0xa8(%rsp), %rdi
callq 0x8430
jmp 0x30f2d
movq 0xa9064(%rip), %rdi     # 0xd9f98
leaq 0xa8(%rsp), %rsi
callq 0x83e0
movq %rax, 0x48(%rsp)
jmp 0x30f48
movq 0x48(%rsp), %rdi
leaq 0x7af4a(%rip), %rsi     # 0xabe9e
callq 0x8440
movq %rax, 0x40(%rsp)
jmp 0x30f60
movq 0x40(%rsp), %rdi
movq 0x60(%rsp), %rax
movl 0x218(%rax), %esi
callq 0x8730
movq %rax, 0x38(%rsp)
jmp 0x30f7c
movq 0x38(%rsp), %rdi
leaq 0x7ab0f(%rip), %rsi     # 0xaba97
callq 0x8440
movq %rax, 0x30(%rsp)
jmp 0x30f94
movq 0x60(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0xcdf0
jmp 0x30fa5
movq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x83e0
movq %rax, 0x28(%rsp)
jmp 0x30fbb
movq 0x28(%rsp), %rdi
movq 0xa8f91(%rip), %rsi     # 0xd9f58
callq 0x8480
movq %rax, 0x20(%rsp)
jmp 0x30fd3
movq 0x20(%rsp), %rdi
movq 0xa8f79(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x30fe6
leaq 0x68(%rsp), %rdi
callq 0x8848
movq 0x60(%rsp), %rax
movl 0x21c(%rax), %ecx
addl $0x5, %ecx
movl %ecx, 0x21c(%rax)
leaq 0xa8(%rsp), %rdi
callq 0x8848
jmp 0x31043
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x8848
leaq 0xa8(%rsp), %rdi
callq 0x8848
jmp 0x31149
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq 0x60(%rsp), %rcx
cmpq 0x230(%rcx), %rax
jbe 0x31141
movq 0x60(%rsp), %rax
addq $0x258, %rax            # imm = 0x258
movq %rax, 0x8(%rsp)
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq 0x8(%rsp), %rdi
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movq %rax, %rsi
callq 0x8100
movq %rax, %rdi
leaq 0x7a9de(%rip), %rsi     # 0xaba7e
callq 0x8440
movq 0x60(%rsp), %rdi
movq %rax, 0x10(%rsp)
callq 0x31160
movq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x85b0
movq %rax, %rdi
leaq 0x7a9b4(%rip), %rsi     # 0xaba7e
callq 0x8440
movq 0x60(%rsp), %rdi
movq %rax, 0x18(%rsp)
callq 0x311b0
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x85b0
movq %rax, %rdi
movq 0xa8e64(%rip), %rsi     # 0xd9f58
callq 0x8480
movq 0x60(%rsp), %rax
movq $0x0, 0x458(%rax)
movq $0x0, 0x460(%rax)
movl $0x0, 0x468(%rax)
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq %rax, %rcx
movq 0x60(%rsp), %rax
addq 0x228(%rax), %rcx
movq %rcx, 0x230(%rax)
addq $0xe8, %rsp
retq
movq 0x98(%rsp), %rdi
callq 0x8770
nopw %cs:(%rax,%rax)