// File: narges64[P]SIMBA/flash.cpp
// Function: change_plane_state(ssd_info*, unsigned int, unsigned int, unsigned int, unsigned int, long, unsigned int, long)
void change_plane_state (ssd_info * ssd, unsigned int channel, unsigned int lun, unsigned int plane, unsigned int current_state, int64_t current_time, unsigned int next_state, int64_t next_time){
	int state1 = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->current_state; 
	int state2 = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->next_state; 
	int64_t state1_time = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->current_time; 
	int64_t state2_time = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->next_state_predict_time; 	
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->state_time[state1] += (state2_time - state1_time)>0? state2_time - state1_time : 0; 
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->state_time[state2] += (current_time - state2_time)>0? current_time - state2_time : 0;  
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->current_state=current_state;	
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->current_time=current_time;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->next_state=next_state; 	
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->next_state_predict_time=next_time;

/*
	sub_request * rhead = ssd->channel_head[channel]->lun_head[lun]->rsubs_queue.queue_head; 
	while(rhead != NULL){
		if (rhead->location->plane == plane){
			if (current_state == PLANE_MODE_GC)
				change_subrequest_state (ssd, rhead, SR_MODE_GCC_S, current_time, SR_MODE_WAIT, next_time);
			else 
				change_subrequest_state (ssd, rhead, SR_MODE_IOC_S, current_time, SR_MODE_WAIT, next_time);
				 	
		}
		else {
			if (current_state == PLANE_MODE_GC) 
				change_subrequest_state(ssd, rhead, SR_MODE_GCC_O, current_time, SR_MODE_WAIT, next_time); 
			else
				change_subrequest_state(ssd, rhead, SR_MODE_IOC_O, current_time, SR_MODE_WAIT, next_time); 
		}
		rhead = rhead->next_node; 
	}	
	sub_request * whead = ssd->channel_head[channel]->lun_head[lun]->wsubs_queue.queue_head; 
	while(whead != NULL){
		if (whead->location->plane == plane){
			if (current_state == PLANE_MODE_GC)
				change_subrequest_state (ssd, whead, SR_MODE_GCC_S, current_time, SR_MODE_WAIT, next_time);
			else 
				change_subrequest_state (ssd, whead, SR_MODE_IOC_S, current_time, SR_MODE_WAIT, next_time);
				 	
		}
		else {
			if (current_state == PLANE_MODE_GC) 
				change_subrequest_state(ssd, whead, SR_MODE_GCC_O, current_time, SR_MODE_WAIT, next_time); 
			else
				change_subrequest_state(ssd, whead, SR_MODE_IOC_O, current_time, SR_MODE_WAIT, next_time); 
		}
		whead = whead->next_node; 
	}	
	sub_request * gchead = ssd->channel_head[channel]->lun_head[lun]->GCSubs.queue_head; 

	while(rhead != NULL){
		if (gchead->location->plane == plane){
			if (current_state == PLANE_MODE_GC)
				change_subrequest_state (ssd, gchead, SR_MODE_GCC_S, current_time, SR_MODE_WAIT, next_time);
			else 
				change_subrequest_state (ssd, gchead, SR_MODE_IOC_S, current_time, SR_MODE_WAIT, next_time);
				 	
		}
		else {
			if (current_state == PLANE_MODE_GC) 
				change_subrequest_state(ssd, gchead, SR_MODE_GCC_O, current_time, SR_MODE_WAIT, next_time); 
			else
				change_subrequest_state(ssd, gchead, SR_MODE_IOC_O, current_time, SR_MODE_WAIT, next_time); 
		}
		gchead = gchead->next_node; 
	}	
*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x48(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x58(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
cmpq $0x0, %rax
jle 0x9a64
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x9a6c
xorl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0x9a6c
movq -0x40(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x60(%rax), %rax
movslq -0x24(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0x0, %rax
jle 0x9ac3
movq -0x20(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x9acb
xorl %eax, %eax
movq %rax, -0x48(%rbp)
jmp 0x9acb
movq -0x48(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x60(%rax), %rax
movslq -0x28(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x48(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x50(%rax)
movl 0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x4c(%rax)
movq 0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x10(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x58(%rax)
popq %rbp
retq