// File: CMU-SAFARI[P]MQSim/src/host/IO_Flow_Base.cpp
// Function: Host_Components::IO_Flow_Base::Submit_io_request(Host_Components::Host_IO_Request*)
void IO_Flow_Base::Submit_io_request(Host_IO_Request* request)
	{
		switch (SSD_device_type) {
			case HostInterface_Types::NVME:
				//If either of software or hardware queue is full
				if (NVME_SQ_FULL(nvme_queue_pair) || available_command_ids.size() == 0) {
					waiting_requests.push_back(request);
				} else {
					if (nvme_software_request_queue[*available_command_ids.begin()] != NULL) {
						PRINT_ERROR("Unexpteced situation in IO_Flow_Base! Overwriting an unhandled I/O request in the queue!")
					} else {
						request->IO_queue_info = *available_command_ids.begin();
						nvme_software_request_queue[*available_command_ids.begin()] = request;
						available_command_ids.erase(available_command_ids.begin());
						request_queue_in_memory[nvme_queue_pair.Submission_queue_tail] = request;
						NVME_UPDATE_SQ_TAIL(nvme_queue_pair);
					}
					request->Enqueue_time = Simulator->Time();
					pcie_root_complex->Write_to_device(nvme_queue_pair.Submission_tail_register_address_on_device, nvme_queue_pair.Submission_queue_tail);//Based on NVMe protocol definition, the updated tail pointer should be informed to the device
				}
				break;
			case HostInterface_Types::SATA:
				request->Source_flow_id = flow_id;
				sata_hba->Submit_io_request(request);
				break;
		}
	}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x54(%rax), %eax
movl %eax, 0x3c(%rsp)
testl %eax, %eax
je 0x3235d
jmp 0x320e2
movl 0x3c(%rsp), %eax
subl $0x1, %eax
jne 0x3237d
jmp 0x320f1
movq 0x30(%rsp), %rcx
movzwl 0x82(%rcx), %eax
movzwl 0x84(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x32127
movq 0x30(%rsp), %rcx
movzwl 0x82(%rcx), %eax
addl $0x1, %eax
movzwl 0x80(%rcx), %ecx
cmpl %ecx, %eax
je 0x3214f
jmp 0x32138
movq 0x30(%rsp), %rax
movzwl 0x80(%rax), %eax
cmpl $0x0, %eax
je 0x3214f
movq 0x30(%rsp), %rdi
addq $0xb8, %rdi
callq 0x343a0
cmpq $0x0, %rax
jne 0x3216a
movq 0x30(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq 0x78(%rsp), %rsi
callq 0x344d0
jmp 0x3235b
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x118, %rax            # imm = 0x118
movq %rax, 0x28(%rsp)
addq $0xb8, %rdi
callq 0x34410
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x34440
movq 0x28(%rsp), %rdi
movzwl (%rax), %eax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x34310
cmpq $0x0, (%rax)
je 0x32200
movq 0xa7e34(%rip), %rdi     # 0xd9ff0
leaq 0x78725(%rip), %rsi     # 0xaa8e8
callq 0x8440
movq 0xa7e21(%rip), %rdi     # 0xd9ff0
leaq 0x79968(%rip), %rsi     # 0xabb3e
callq 0x8440
movq %rax, %rdi
movq 0xa7d73(%rip), %rsi     # 0xd9f58
callq 0x8480
movq 0xa7ddf(%rip), %rdi     # 0xd9fd0
callq 0x84f0
movl $0x1, %edi
callq 0x8500
movq 0x30(%rsp), %rdi
addq $0xb8, %rdi
callq 0x34410
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x34440
movq 0x30(%rsp), %rdi
movw (%rax), %cx
movq 0x78(%rsp), %rax
movw %cx, 0x20(%rax)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rdi, %rax
addq $0x118, %rax            # imm = 0x118
movq %rax, 0x8(%rsp)
addq $0xb8, %rdi
callq 0x34410
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x34440
movq 0x8(%rsp), %rdi
movzwl (%rax), %eax
movq %rax, 0x58(%rsp)
leaq 0x58(%rsp), %rsi
callq 0x34310
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %rdi
movq %rcx, (%rax)
movq %rdi, %rax
addq $0xb8, %rax
movq %rax, 0x18(%rsp)
addq $0xb8, %rdi
callq 0x34410
movq 0x18(%rsp), %rdi
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rsi
callq 0x34460
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x40(%rsp)
movq 0x78(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, %rdi
addq $0xe8, %rdi
movzwl 0x82(%rax), %eax
movl %eax, %esi
callq 0x344b0
movq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq %rdx, (%rax)
movw 0x82(%rcx), %ax
addw $0x1, %ax
movw %ax, 0x82(%rcx)
movzwl 0x82(%rcx), %eax
movzwl 0x84(%rcx), %ecx
cmpl %ecx, %eax
jne 0x32324
movq 0x30(%rsp), %rax
movw $0x0, 0x82(%rax)
jmp 0x32326
callq 0x46500
movq %rax, %rdi
callq 0x46c50
movq %rax, %rdx
movq 0x30(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rdx, 0x8(%rcx)
movq 0x58(%rax), %rdi
movq 0x88(%rax), %rsi
movzwl 0x82(%rax), %edx
callq 0x3f620
jmp 0x3237d
movq 0x30(%rsp), %rax
movw 0x38(%rax), %dx
movq 0x78(%rsp), %rcx
movw %dx, 0x22(%rcx)
movq 0x60(%rax), %rdi
movq 0x78(%rsp), %rsi
callq 0x405c0
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)