// File: /workspace/github_cpp_makefile_star2_O1/narges64[P]SIMBA/garbage_collection.cpp
// Function: gc_for_plane(ssd_info*, gc_operation*)
void gc_for_plane(ssd_info * ssd, gc_operation * gc_node){
	unsigned int page_move_count = 0;
	local * location = gc_node->location;
	if (find_victim_block(ssd, location) != SUCCESS) {
		printf("Error: invalid block selected for gc \n");
		return;
	}
	int last_write = ssd->channel_head[location->channel]->lun_head[location->lun]->plane_head[location->plane]->blk_head[location->block]->last_write_page; 
	for(int i=0;i<=last_write;i++)
	{
		if(ssd->channel_head[location->channel]->lun_head[location->lun]->plane_head[location->plane]->blk_head[location->block]->page_head[i]->valid_state == true)
		{
			location->page=i;
			if (move_page(ssd, location, gc_node) == FAIL){
				cout << "Error: problem while moving valid pages in GC " << endl;
				return;
			}
			page_move_count++;
		}
	}
	ssd->stats->gc_moved_page += page_move_count;
	
	sub_request * erase_subreq = create_gc_sub_request( ssd, location, ERASE, gc_node);
	ssd->channel_head[location->channel]->lun_head[location->lun]->GCSubs.push_tail(erase_subreq);
	erase_block(ssd,location);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rbx
movq %rbx, %rsi
callq 0x703a
cmpl $0x1, %eax
jne 0x6f6f
movq 0x90(%r14), %rax
movslq (%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq 0x8(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq 0xc(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %r12d
testl %r12d, %r12d
js 0x6f89
incq %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x90(%r14), %rax
movslq (%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq 0x8(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq 0xc(%rbx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movq (%rax,%r13,8), %rax
cmpb $0x1, (%rax)
jne 0x6f65
movl %r13d, 0x10(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x71da
testl %eax, %eax
je 0x6fea
incl %ebp
incq %r13
cmpq %r13, %r12
jne 0x6f0b
jmp 0x6f8b
leaq 0x3c3b(%rip), %rdi      # 0xabb1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22a0
xorl %ebp, %ebp
movq 0x98(%r14), %rax
addl %ebp, 0xc8(%rax)
movq %r14, %rdi
movq %rbx, %rsi
movl $0x2, %edx
movq %r15, %rcx
callq 0x7368
movq 0x90(%r14), %rcx
movslq (%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x50(%rcx), %rcx
movslq 0x4(%rbx), %rdx
movq (%rcx,%rdx,8), %rdi
addq $0x48, %rdi
movq %rax, %rsi
callq 0x44d6
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x75ea
movq 0x6fdf(%rip), %rbx      # 0xdfd0
leaq 0x3a2c(%rip), %rsi      # 0xaa24
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2050
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20f0