// File: /workspace/github_cpp_makefile_star2_O1/narges64[P]SIMBA/ftl.cpp
// Function: service_in_flash(ssd_info*, sub_request*)
void service_in_flash(ssd_info * ssd, sub_request * sub){
	if (sub->operation == READ) {
		if (ssd->channel_head[sub->location->channel]->
			lun_head[sub->location->lun]->
			rsubs_queue.find_subreq(sub)){
			// the request already exists
			sub->complete_time=ssd->current_time+1000;
			change_subrequest_state(ssd, sub,SR_MODE_ST_S,
					ssd->current_time,SR_MODE_COMPLETE,
					sub->complete_time);
			sub->state_current_time = sub->next_state_predict_time;
			ssd->stats->queue_read_count++;
		} else {
			ssd->channel_head[sub->location->channel]->
					lun_head[sub->location->lun]->
					rsubs_queue.push_tail(sub);
		}
	} else if (sub->operation == WRITE){
		if(invalid_old_page(ssd, sub) == FAIL) {
			#if DEBUG 
			cout << "error in invaliding the old page " << endl;
			#endif 
		}
		sub->ppn = get_new_ppn(ssd, sub->lpn, sub->location, true);

		if(sub->ppn == -1 || write_page(ssd, sub->lpn, sub->ppn) == FAIL) {
			cout << "there is problem "<< sub->ppn << endl;
			return;
		}
		find_location(ssd, sub->ppn, sub->location);
		ssd->channel_head[sub->location->channel]->lun_head[sub->location->lun]->
			wsubs_queue.push_tail(sub);

		Schedule_GC(ssd, sub);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x20(%rsi), %eax
testl %eax, %eax
je 0x4ffb
cmpl $0x1, %eax
jne 0x4ff0
movq 0x90(%r14), %rax
movq 0x60(%rbx), %rcx
movslq (%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x60, %rdi
movq %rbx, %rsi
callq 0x4462
testb %al, %al
je 0x50eb
movq (%r14), %rcx
leaq 0x3e8(%rcx), %r9
movq %r9, 0x58(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x9, %r8d
callq 0x6e8e
movq 0x38(%rbx), %rax
movq %rax, 0x88(%rbx)
movq 0x98(%r14), %rax
incq 0xb0(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x511f
movq 0x60(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %ecx
callq 0x49c6
movl %eax, 0x10(%rbx)
cmpl $-0x1, %eax
je 0x5091
movl %eax, %ebp
movl 0xc(%rbx), %r15d
movq %r14, %rdi
movl %r15d, %esi
movl %eax, %edx
callq 0x6060
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x60a2
testl %eax, %eax
je 0x5091
movl 0x10(%rbx), %esi
movq 0x60(%rbx), %rdx
movq %r14, %rdi
callq 0x4b02
movq 0x90(%r14), %rax
movq 0x60(%rbx), %rcx
movslq (%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x78, %rdi
movq %rbx, %rsi
callq 0x44d6
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7b26
movq 0x8f38(%rip), %r14      # 0xdfd0
leaq 0x55ef(%rip), %rsi      # 0xa68e
movl $0x11, %edx
movq %r14, %rdi
callq 0x21e0
movl 0x10(%rbx), %esi
movq %r14, %rdi
callq 0x22d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2050
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x20f0
movq 0x90(%r14), %rax
movq 0x60(%rbx), %rcx
movslq (%rcx), %rdx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x60, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x44d6