// File: /workspace/github_cpp_makefile_star2_O3/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 0x6f2a
cmpl $0x1, %eax
jne 0x6e5f
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 0x6e79
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 0x6e55
movl %r13d, 0x10(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x70ca
testl %eax, %eax
je 0x6eda
incl %ebp
incq %r13
cmpq %r13, %r12
jne 0x6dfb
jmp 0x6e7b
leaq 0x3d57(%rip), %rdi      # 0xabbd
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 0x724a
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 0x44b8
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x74c3
movq 0x70ef(%rip), %rbx      # 0xdfd0
leaq 0x3b48(%rip), %rsi      # 0xaa30
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