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

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x38(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x40(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0x0, %rax
jle 0x9c5a
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x9c62
xorl %eax, %eax
movq %rax, -0x50(%rbp)
jmp 0x9c62
movq -0x50(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x58(%rax), %rax
movslq -0x2c(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x0, %rax
jle 0x9ca4
movq -0x18(%rbp), %rax
subq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x9cac
xorl %eax, %eax
movq %rax, -0x58(%rbp)
jmp 0x9cac
movq -0x58(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x58(%rax), %rax
movslq -0x30(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x38(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
subq 0x40(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x58(%rax), %rax
movslq -0x44(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x40(%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x3c(%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0xc(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x48(%rax)
popq %rbp
retq
nopl (%rax)