// File: /workspace/github_cpp_makefile_star2_O2/narges64[P]SIMBA/garbage_collection.cpp
// Function: pre_process_gc(ssd_info*, local const*)
void pre_process_gc(ssd_info * ssd, const local * location){

	int pre_process_move = 0;
	local * gc_location = new local(location->channel, location->lun, location->plane);
	if (find_victim_block(ssd, gc_location) != SUCCESS) {
		printf("Error: invalid block selected for gc \n");
		delete gc_location;
		return;
	}
	//location->print();
	for(unsigned int i=0;i<ssd->parameter->page_block;i++)
	{
		if(ssd->channel_head[gc_location->channel]->lun_head[gc_location->lun]->plane_head[gc_location->plane]->blk_head[gc_location->block]->page_head[i]->valid_state == true)
		{
			gc_location->page=i;

			int lpn = ssd->channel_head[gc_location->channel]->lun_head[gc_location->lun]->plane_head[gc_location->plane]->blk_head[gc_location->block]->page_head[gc_location->page]->lpn;
			local * location = new local(0,0,0,0,0); 
			invalid_old_page(ssd, lpn, location);
			int ppn = get_new_ppn(ssd, lpn, location, false); // false indicate we want cold active block 
			if (ppn ==-1 || write_page(ssd, lpn, ppn) == FAIL) {
				cout << "error in pre-process " << endl; 
				return; 
			}
				
			pre_process_move++;
		}
	}
	erase_block(ssd, gc_location);
	delete gc_location;
	ssd->stats->gc_moved_page += pre_process_move;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
pushq $0x18
popq %rdi
callq 0x2160
movq %rax, %r14
movl 0x8(%r15), %eax
movq (%r15), %rcx
movq %rcx, (%r14)
movl %eax, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64eb
cmpl $0x1, %eax
jne 0x70cd
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x58(%rbx), %rax
cmpl 0x234(%rax), %r15d
jae 0x70f2
movq 0x90(%rbx), %rax
movslq (%r14), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movslq 0x4(%r14), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq 0x8(%r14), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movslq 0xc(%r14), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rcx
cmpb $0x1, (%rcx)
jne 0x70c5
movl %r15d, 0x10(%r14)
movslq %r15d, %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %ebp
pushq $0x18
popq %rdi
callq 0x2160
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andl $0x0, 0x10(%rax)
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x4445
movq %rbx, %rdi
movl %ebp, %esi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x44c6
cmpl $-0x1, %eax
je 0x7125
movq %rbx, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x4544
testl %eax, %eax
je 0x7125
incl %r13d
incq %r15
jmp 0x701f
leaq 0x29e1(%rip), %rdi      # 0x9ab5
callq 0x2270
pushq $0x18
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2170
movq %rbx, %rdi
movq %r14, %rsi
callq 0x69a1
pushq $0x18
popq %rsi
movq %r14, %rdi
callq 0x2170
movq 0x98(%rbx), %rax
addl %r13d, 0xc8(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6ea4(%rip), %rdi      # 0xdfd0
leaq 0x294f(%rip), %rsi      # 0x9a82
callq 0x2140
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20b0