// File: narges64[P]SIMBA/ftl.cpp
// Function: get_cold_active_block(ssd_info*, local*)
int get_cold_active_block(ssd_info *ssd, local * location){
	int channel = location->channel;
	int lun = location->lun;
	int plane = location->plane;

	int cold_active_block = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->cold_active_block;
	int free_page_num = ssd->channel_head[channel]->lun_head[lun]->
					plane_head[plane]->blk_head[cold_active_block]->free_page_num;
	int active_block = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->active_block; 
	int count=0;
	while(((free_page_num==0))&&(count<ssd->parameter->block_plane))
	{
		cold_active_block=(cold_active_block+1)%ssd->parameter->block_plane;
		if (cold_active_block == active_block) 
			cold_active_block=(cold_active_block+1)%ssd->parameter->block_plane;
		free_page_num=ssd->channel_head[channel]->lun_head[lun]->
					plane_head[plane]->blk_head[cold_active_block]->free_page_num;
		count++;
	}
	if (count == ssd->parameter->block_plane) {
		cout << "could not find cold active_block " << endl;
		return -1;
	}
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->cold_active_block=cold_active_block;

	return cold_active_block;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x35(%rbp)
jne 0x89c4
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
cmpl 0x230(%rcx), %eax
setb %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x89d0
jmp 0x8a54
movl -0x28(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
xorl %edx, %edx
divl 0x230(%rcx)
movl %edx, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jne 0x8a0a
movl -0x28(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
xorl %edx, %edx
divl 0x230(%rcx)
movl %edx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x89a2
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
cmpl 0x230(%rcx), %eax
jne 0x8a92
movq 0xb562(%rip), %rdi      # 0x13fd0
leaq 0x6ccd(%rip), %rsi      # 0xf742
callq 0x2110
movq %rax, %rdi
movq 0xb53c(%rip), %rsi      # 0x13fc0
callq 0x2150
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8aca
movslq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x18(%rax)
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)