// File: narges64[P]SIMBA/garbage_collection.cpp
// Function: erase_block(ssd_info*, local const*)
int erase_block(ssd_info * ssd,const local * location){

	
	unsigned int channel = location->channel;
	unsigned int lun = location->lun;
	unsigned int plane = location->plane;
	unsigned int block = location->block;

//	int initial_free = ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->free_page_num;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->free_page_num=ssd->parameter->page_block;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->invalid_page_num=0;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->last_write_page=-1;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->erase_count++;

	for (int i=0;i<ssd->parameter->page_block;i++)
	{
		ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->page_head[i]->valid_state=false;
		ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->blk_head[block]->page_head[i]->lpn=-1;
	}

	ssd->stats->flash_erase_count++;
	ssd->channel_head[channel]->erase_count++;
	ssd->channel_head[channel]->lun_head[lun]->erase_count++;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->erase_count++;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->free_page += ssd->parameter->page_block;
	ssd->channel_head[channel]->lun_head[lun]->plane_head[plane]->invalid_page -= ssd->parameter->page_block;

//	cout << "erase block " << channel << " "<< lun << " "<< plane << " "<< block << endl;
	return SUCCESS;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x234(%rax), %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
cmpl 0x234(%rcx), %eax
jae 0xaa43
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movl -0x20(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa998
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movq 0x98(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x98(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x234(%rax), %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %edx
movq (%rax,%rdx,8), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x234(%rax), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movl -0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl $0x1, %eax
popq %rbp
retq
nopl (%rax)