// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x20(%rsi), %eax
testl %eax, %eax
je 0x4fe5
cmpl $0x1, %eax
jne 0x4fdd
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 0x444a
testb %al, %al
je 0x50bc
movq (%r14), %rcx
leaq 0x3e8(%rcx), %r9
movq %r9, 0x58(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x9, %r8d
callq 0x6d7e
movq 0x38(%rbx), %rax
movq %rax, 0x88(%rbx)
movq 0x98(%r14), %rax
incq 0xb0(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x50ed
movq 0x60(%rbx), %rdx
movq %r14, %rdi
movl $0x1, %ecx
callq 0x499c
movl %eax, 0x10(%rbx)
cmpl $-0x1, %eax
je 0x5065
movl 0xc(%rbx), %esi
movq %r14, %rdi
movl %eax, %edx
callq 0x4a26
testl %eax, %eax
je 0x5065
movl 0x10(%rbx), %esi
movq 0x60(%rbx), %rdx
movq %r14, %rdi
callq 0x4af9
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 0x44b8
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7a84
movq 0x8f64(%rip), %r14      # 0xdfd0
leaq 0x561b(%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
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
jmp 0x44b8