// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl $0x18, %edi
callq 0x2190
movq %rax, %rbx
movl 0x8(%r15), %eax
movq (%r15), %rcx
movq %rcx, (%rbx)
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6f2a
cmpl $0x1, %eax
jne 0x7d0c
movq 0x58(%r14), %rax
cmpl $0x0, 0x234(%rax)
je 0x7d33
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x90(%r14), %rcx
movslq (%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x50(%rcx), %rcx
movslq 0x4(%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
movslq 0x8(%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x20(%rcx), %rcx
movslq 0xc(%rbx), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%r13,8), %rdx
cmpb $0x1, (%rdx)
jne 0x7cfa
movl %r13d, 0x10(%rbx)
movslq %r13d, %rax
movq (%rcx,%rax,8), %rax
movl 0x4(%rax), %ebp
movl $0x18, %edi
callq 0x2190
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x10(%rax)
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x48db
movq %r14, %rdi
movl %ebp, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x499c
cmpl $-0x1, %eax
je 0x7d6b
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x4a26
testl %eax, %eax
je 0x7d6b
incl %r12d
movq 0x58(%r14), %rax
incq %r13
cmpl 0x234(%rax), %r13d
jb 0x7c58
jmp 0x7d36
leaq 0x2eaa(%rip), %rdi      # 0xabbd
callq 0x22a0
movl $0x18, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21a0
xorl %r12d, %r12d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x74c3
movl $0x18, %esi
movq %rbx, %rdi
callq 0x21a0
movq 0x98(%r14), %rax
addl %r12d, 0xc8(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x625e(%rip), %rbx      # 0xdfd0
leaq 0x2e11(%rip), %rsi      # 0xab8a
movl $0x15, %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