// File: narges64[P]SIMBA/ftl.cpp
// Function: allocate_page_in_plane(ssd_info*, local*, bool)
STATE allocate_page_in_plane( ssd_info *ssd, local * location, bool hot){
	int channel = location->channel;
	int lun = location->lun;
	int plane = location->plane;
	int active_block= -1; 
	if (hot) 
		active_block = get_active_block(ssd, location);
	else 
		active_block = get_cold_active_block(ssd, location); 

	if (active_block == -1) return FAIL;
	int active_page = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->
					blk_head[active_block]->last_write_page + 1;

	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[active_block]->last_write_page++;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[active_block]->
					last_write_time = ssd->current_time;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[active_block]->free_page_num--;

	location->block = active_block;
	location->page = active_page;


	return SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
testb $0x1, -0x19(%rbp)
je 0x8333
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x86c0
movl %eax, -0x2c(%rbp)
jmp 0x8343
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x88d0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x8355
movl $0x0, -0x4(%rbp)
jmp 0x846e
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movslq -0x24(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x4(%rax)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)