// File: /workspace/github_cpp_makefile_star2_O1/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
movq (%r15), %rax
movl 0x8(%r15), %ecx
movq %rax, (%rbx)
movl %ecx, 0x8(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x703a
cmpl $0x1, %eax
jne 0x7e17
movq 0x58(%r14), %rax
cmpl $0x0, 0x234(%rax)
setne %r12b
je 0x7e3e
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
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,%r15,8), %rcx
cmpb $0x1, (%rcx)
jne 0x7dfd
movl %r15d, 0x10(%rbx)
movslq %r15d, %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %ebp
movl $0x18, %edi
callq 0x2190
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x10(%rax)
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0x4905
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x49c6
cmpl $-0x1, %eax
je 0x7db4
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
callq 0x4a50
testl %eax, %eax
je 0x7db4
incl 0x4(%rsp)
movb $0x1, %al
jmp 0x7df9
movl $0x15, %edx
movq 0x6210(%rip), %r13      # 0xdfd0
movq %r13, %rdi
leaq 0x2db4(%rip), %rsi      # 0xab7e
callq 0x21e0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r13, %rdi
callq 0x2050
movq %rax, %rdi
callq 0x20f0
xorl %eax, %eax
testb %al, %al
je 0x7e46
movq 0x58(%r14), %rax
incq %r15
cmpl 0x234(%rax), %r15d
setb %r12b
jb 0x7d11
jmp 0x7e46
leaq 0x2d93(%rip), %rdi      # 0xabb1
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
movl $0x0, 0x4(%rsp)
testb $0x1, %r12b
jne 0x7e75
movq %r14, %rdi
movq %rbx, %rsi
callq 0x75ea
movl $0x18, %esi
movq %rbx, %rdi
callq 0x21a0
movq 0x98(%r14), %rax
movl 0x4(%rsp), %ecx
addl %ecx, 0xc8(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq