// File: narges64[P]SIMBA/flash.cpp
// Function: change_lun_state(ssd_info*, unsigned int, unsigned int, unsigned int, long, unsigned int, long)
void change_lun_state (ssd_info * ssd, unsigned int channel, unsigned int lun, unsigned int current_state, int64_t current_time, unsigned int next_state, int64_t next_time){
	// have been in the next state for some time 
	int state1 = ssd->channel_head[channel]->lun_head[lun]->current_state; 
	int state2 = ssd->channel_head[channel]->lun_head[lun]->next_state; 
	int64_t state1_time = ssd->channel_head[channel]->lun_head[lun]->current_time; 
	int64_t state2_time = ssd->channel_head[channel]->lun_head[lun]->next_state_predict_time; 

	ssd->channel_head[channel]->lun_head[lun]->state_time[state1] += ((state2_time - state1_time) > 0)? state2_time - state1_time: 0; 
	ssd->channel_head[channel]->lun_head[lun]->state_time[state2] += ((current_time - state2_time) > 0)? (current_time - state2_time): 0; 
	
	ssd->channel_head[channel]->lun_head[lun]->current_state=current_state;	
	ssd->channel_head[channel]->lun_head[lun]->current_time=current_time;
	
	ssd->channel_head[channel]->lun_head[lun]->next_state=next_state; 	
	ssd->channel_head[channel]->lun_head[lun]->next_state_predict_time=next_time;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -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
movl 0x14(%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
movl 0x20(%rax), %eax
movl %eax, -0x2c(%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 0x18(%rax), %rax
movq %rax, -0x38(%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 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0x0, %rax
jle 0x9849
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x9851
xorl %eax, %eax
movq %rax, -0x48(%rbp)
jmp 0x9851
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 0x90(%rax), %rax
movslq -0x28(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x0, %rax
jle 0x98a1
movq -0x20(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x98a9
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x98a9
movq -0x50(%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 0x90(%rax), %rax
movslq -0x2c(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%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
movl %ecx, 0x14(%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 %rcx, 0x18(%rax)
movl -0x24(%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
movl %ecx, 0x20(%rax)
movq 0x10(%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 %rcx, 0x28(%rax)
popq %rbp
retq
nop