// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/ssd/Host_Interface_SATA.cpp
// Function: SSD_Components::Input_Stream_Manager_SATA::Handle_serviced_request(SSD_Components::User_Request*)
inline void Input_Stream_Manager_SATA::Handle_serviced_request(User_Request* request)
	{
		((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Waiting_user_requests.remove(request);
		((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->On_the_fly_requests--;

		DEBUG("** Host Interface: Request #" << request->ID << " is finished")

		//If this is a read request, then the read data should be written to host memory
		if (request->Type == UserRequestType::READ) {
			((Host_Interface_SATA*)host_interface)->request_fetch_unit->Send_read_data(request);
		}

		if (((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Submission_head != ((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Submission_tail) {
			((Host_Interface_SATA*)host_interface)->request_fetch_unit->Fetch_next_request(SATA_STREAM_ID);
			((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->On_the_fly_requests++;
			((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Submission_head++;//Update submission queue head after starting fetch request
			if (((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Submission_head == ncq_depth) {//Circular queue implementation
				((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Submission_head = 0;
			}
		}

		//Check if completion queue is full
		if (((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_head > ((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_tail) {
			//completion queue is full
			if (((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_tail + 1 == ((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_head) {
				((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completed_user_requests.push_back(request);//Wait while the completion queue is full
				return;
			}
		} else if (((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_tail - ((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completion_head
			== ncq_depth - 1) {
			((Input_Stream_SATA*)input_streams[SATA_STREAM_ID])->Completed_user_requests.push_back(request);//Wait while the completion queue is full
			return;
		}

		inform_host_request_completed(request);//Completion queue is not full, so the device can DMA the completion queue entry to the host
		DELETE_REQUEST_NVME(request);
	}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %rsi, (%r14)
movq 0x10(%rdi), %rax
movq (%rax), %rdi
addq $0x78, %rdi
movq %r14, %rsi
callq 0x2c194
movq 0x10(%rbx), %rax
movq (%rax), %rdi
decw 0xc0(%rdi)
movq (%r14), %rsi
cmpl $0x0, 0x64(%rsi)
jne 0x3725e
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movzwl 0x68(%rdi), %eax
cmpw 0x6c(%rdi), %ax
je 0x3729f
movq 0x8(%rbx), %rax
movq 0x58(%rax), %rdi
movq (%rdi), %rax
xorl %ebp, %ebp
xorl %esi, %esi
callq *0x10(%rax)
movq 0x10(%rbx), %rax
movq (%rax), %rax
incw 0xc0(%rax)
movl 0x68(%rax), %ecx
incl %ecx
cmpw 0x28(%rbx), %cx
cmovel %ebp, %ecx
movw %cx, 0x68(%rax)
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movzwl 0x6e(%rdi), %ecx
movzwl 0x70(%rdi), %eax
cmpw %ax, %cx
jbe 0x372b0
incl %eax
jmp 0x372b8
subl %ecx, %eax
movzwl 0x28(%rbx), %ecx
decl %ecx
cmpl %ecx, %eax
jne 0x372cf
addq $0x90, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2ab34
jmp 0x3732a
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x37398
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rdi
callq 0x7340
callq 0x1f784
movq %rax, %rdi
callq 0x1fb60
movq 0x8(%rsp), %rbx
testb %al, %al
je 0x37313
movq 0x78(%rbx), %rdi
testq %rdi, %rdi
je 0x37313
callq 0x7430
movq 0x8(%rsp), %rbx
cmpq $0x0, 0x50(%rbx)
jne 0x37333
movq %rbx, %rdi
callq 0x2ab0c
movq %rbx, %rdi
callq 0x7340
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x2acb6(%rip), %rbx     # 0x61ff0
leaq 0xd247(%rip), %rsi      # 0x44588
movq %rbx, %rdi
callq 0x7360
leaq 0x10cd2(%rip), %rsi     # 0x48022
movq %rbx, %rdi
callq 0x7360
movq %rax, %rdi
callq 0x71a0
movq 0x2ac69(%rip), %rdi     # 0x61fd0
callq 0x73d0
pushq $0x1
popq %rdi
callq 0x73e0