// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
movq %rax, %r15
subq 0x8(%r14), %r15
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
subq (%r14), %rax
incl 0x160(%rbx)
incl 0x468(%rbx)
addq %r15, 0x170(%rbx)
addq %r15, 0x458(%rbx)
addq %rax, 0x1b8(%rbx)
addq %rax, 0x460(%rbx)
cmpq 0x1a0(%rbx), %r15
jbe 0x17ab2
movq %r15, 0x1a0(%rbx)
cmpq 0x188(%rbx), %r15
jae 0x17ac2
movq %r15, 0x188(%rbx)
cmpq 0x1e8(%rbx), %rax
jbe 0x17ad2
movq %rax, 0x1e8(%rbx)
cmpq 0x1d0(%rbx), %rax
jae 0x17ae2
movq %rax, 0x1d0(%rbx)
movl 0x18(%r14), %ecx
shll $0x9, %ecx
addq %rcx, 0x200(%rbx)
cmpl $0x0, 0x1c(%r14)
je 0x17b52
incl 0x168(%rbx)
addq %r15, 0x180(%rbx)
addq %rax, 0x1c8(%rbx)
cmpq 0x1b0(%rbx), %r15
jbe 0x17b1b
movq %r15, 0x1b0(%rbx)
cmpq 0x198(%rbx), %r15
jae 0x17b2b
movq %r15, 0x198(%rbx)
cmpq 0x1f8(%rbx), %rax
jbe 0x17b3b
movq %rax, 0x1f8(%rbx)
movl $0x210, %edx            # imm = 0x210
cmpq 0x1e0(%rbx), %rax
jae 0x17bae
leaq 0x1e0(%rbx), %rsi
jmp 0x17bab
incl 0x164(%rbx)
addq %r15, 0x178(%rbx)
addq %rax, 0x1c0(%rbx)
cmpq 0x1a8(%rbx), %r15
jbe 0x17b76
movq %r15, 0x1a8(%rbx)
cmpq 0x190(%rbx), %r15
jae 0x17b86
movq %r15, 0x190(%rbx)
cmpq 0x1f0(%rbx), %rax
jbe 0x17b96
movq %rax, 0x1f0(%rbx)
movl $0x208, %edx            # imm = 0x208
cmpq 0x1d8(%rbx), %rax
jae 0x17bae
leaq 0x1d8(%rbx), %rsi
movq %rax, (%rsi)
addq %rcx, (%rbx,%rdx)
movq %r14, %rdi
callq 0x7340
cmpq $0x0, 0x48(%rbx)
je 0x17c16
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
movq %rax, %xmm1
movq 0x2dbf5(%rip), %xmm2    # 0x457d0
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2dbf9(%rip), %xmm3    # 0x457e0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq 0x48(%rbx), %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
jmp 0x17c2d
movl 0x160(%rbx), %eax
cvtsi2sd %rax, %xmm0
movl 0x50(%rbx), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
mulsd 0x2d1fb(%rip), %xmm0    # 0x44e30
cvttsd2si %xmm0, %eax
movl %eax, 0x218(%rbx)
cmpl %eax, 0x21c(%rbx)
jg 0x17d51
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x2dc9b(%rip), %rsi     # 0x458fe
leaq 0x8(%rsp), %rdi
callq 0x7630
movq %rbx, (%rsp)
movl 0x218(%rbx), %ebp
xorl %r15d, %r15d
leaq 0x2b949(%rip), %r12     # 0x435ca
leaq 0x2e076(%rip), %r13     # 0x45cfe
leaq 0x2b9aa(%rip), %rbx     # 0x43639
leaq 0x8(%rsp), %r14
cmpl $0x64, %r15d
jae 0x17cb6
cmpl %r15d, %ebp
movq %r13, %rsi
cmoveq %r12, %rsi
cmovgq %rbx, %rsi
movq %r14, %rdi
callq 0x7630
addl $0x5, %r15d
jmp 0x17c94
leaq 0x2dc43(%rip), %rsi     # 0x45900
leaq 0x8(%rsp), %rdi
callq 0x7630
movq (%rsp), %rbx
movq 0x4a2a6(%rip), %rdi     # 0x61f78
leaq 0x8(%rsp), %rsi
callq 0x7310
leaq 0x2e01b(%rip), %rsi     # 0x45cfe
movq %rax, %rdi
callq 0x7360
movl 0x218(%rbx), %esi
movq %rax, %rdi
callq 0x75a0
leaq 0x2dc03(%rip), %rsi     # 0x45903
movq %rax, %rdi
callq 0x7360
movq %rax, %r14
leaq 0x8(%rbx), %rsi
leaq 0x28(%rsp), %rdi
callq 0x7480
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x71a0
movq %rax, %rdi
callq 0x71a0
leaq 0x28(%rsp), %rdi
callq 0x7678
addl $0x5, 0x21c(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x7678
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
cmpq 0x230(%rbx), %rax
jbe 0x17e4a
leaq 0x458(%rbx), %r12
leaq 0x258(%rbx), %r15
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
xorl %r14d, %r14d
movl $0x3e8, %r13d           # imm = 0x3E8
xorl %edx, %edx
divq %r13
movq %r15, %rdi
movq %rax, %rsi
callq 0x7270
leaq 0x2db44(%rip), %rsi     # 0x458ea
movq %rax, %rdi
callq 0x7360
movq %rax, %rdi
movl 0x468(%rbx), %ecx
testq %rcx, %rcx
je 0x17dcd
movq (%r12), %rax
xorl %edx, %edx
divq %rcx
xorl %edx, %edx
divq %r13
movl %eax, %r14d
movq %r14, %rsi
callq 0x7270
leaq 0x2db0e(%rip), %rsi     # 0x458ea
movq %rax, %rdi
callq 0x7360
movq %rax, %rdi
cmpl $0x0, 0x160(%rbx)
je 0x17e10
movq 0x460(%rbx), %rax
movl 0x468(%rbx), %ecx
xorl %edx, %edx
divq %rcx
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl %eax, %esi
jmp 0x17e12
xorl %esi, %esi
callq 0x7270
movq %rax, %rdi
callq 0x71a0
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
andl $0x0, 0x10(%r12)
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
addq 0x228(%rbx), %rax
movq %rax, 0x230(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17e6e
jmp 0x17e6e
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x7678
jmp 0x17e71
jmp 0x17e6e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x7678
movq %rbx, %rdi
callq 0x75d0
nop