// File: /workspace/github_cpp_makefile_star2_O2/narges64[P]SIMBA/garbage_collection.cpp
// Function: create_gc_sub_request(ssd_info*, local const*, int, gc_operation*)
sub_request * create_gc_sub_request( ssd_info * ssd,const local * location, int operation, gc_operation * gc_node){

	if (gc_node != NULL)	{
		if (location->channel != gc_node->location->channel || location->lun != gc_node->location->lun){
			cout << "Error in location and gc_node incompatible! " << endl;
			return NULL;
		}
	}

	sub_request * sub = new sub_request(ssd->current_time, -1, ssd->subrequest_sequence_number++,operation);

	sub->gc_node = gc_node;
	sub->begin_time=ssd->current_time;

	if (operation != ERASE) {
		sub->lpn = ssd->channel_head[location->channel]->lun_head[location->lun]->plane_head[location->plane]->blk_head[location->block]->page_head[location->page]->lpn;
		if (ssd->dram->map->map_entry[sub->lpn].state){
			sub->state = 1;
			if (sub->lpn == -1) 
				cout << "Error in state of physical page " << endl; 
		}else{
			sub->state = 0;
			if (sub->lpn != -1) 
				cout << "Error in state of invalid physical page " << endl; 
		}
	}

	if (operation == READ)
	{
		if (sub->location != NULL) delete sub->location;
		sub->location = new local(location->channel, location->lun, location->plane,location->block, location->page);
		sub->ppn = ssd->dram->map->map_entry[sub->lpn].pn;
	}
	else if(operation == WRITE)
	{
		if (sub->location != NULL) delete sub->location;
	}
	else if (operation == ERASE)
	{
		if (sub->location != NULL) delete sub->location;
		sub->location = new local(location->channel, location->lun, location->plane, location->block, 0);
		sub->ppn = -1;
	}else {
		delete sub;
		printf("\nERROR ! Unexpected command.\n");
		return NULL;
	}

	return sub;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
testq %rcx, %rcx
je 0x67d0
movl (%r14), %ecx
movq (%r12), %rax
cmpl (%rax), %ecx
jne 0x683a
movl 0x4(%r14), %ecx
cmpl 0x4(%rax), %ecx
jne 0x683a
movl $0xa0, %edi
callq 0x2160
movq %rax, %rbx
movq (%r15), %rsi
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%r15)
pushq $-0x1
popq %rdx
movq %rbx, %rdi
movl %ebp, %r8d
callq 0x5ee2
movq %r12, 0x90(%rbx)
movq (%r15), %rax
movq %rax, 0x48(%rbx)
cmpl $0x2, %ebp
jne 0x6863
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x681d
pushq $0x18
popq %rsi
callq 0x2170
pushq $0x18
popq %rdi
callq 0x2160
movups (%r14), %xmm0
movups %xmm0, (%rax)
andl $0x0, 0x10(%rax)
movq %rax, 0x60(%rbx)
orl $-0x1, 0x10(%rbx)
jmp 0x6857
movq 0x778f(%rip), %rdi      # 0xdfd0
leaq 0x31af(%rip), %rsi      # 0x99f7
callq 0x2140
movq %rax, %rdi
callq 0x20b0
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x90(%r15), %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
movslq 0x10(%r14), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl %eax, 0xc(%rbx)
movq 0x60(%r15), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
cmpb $0x1, 0x4(%rcx,%rdx)
jne 0x68d4
movl $0x1, 0x40(%rbx)
cmpl $-0x1, %eax
jne 0x68f8
leaq 0x3152(%rip), %rsi      # 0x9a24
jmp 0x68e4
andl $0x0, 0x40(%rbx)
cmpl $-0x1, %eax
je 0x68f8
leaq 0x3161(%rip), %rsi      # 0x9a45
movq 0x76e5(%rip), %rdi      # 0xdfd0
callq 0x2140
movq %rax, %rdi
callq 0x20b0
testl %ebp, %ebp
je 0x6949
cmpl $0x1, %ebp
jne 0x6963
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x6912
pushq $0x18
popq %rsi
callq 0x2170
pushq $0x18
popq %rdi
callq 0x2160
movl 0x10(%r14), %ecx
movups (%r14), %xmm0
movups %xmm0, (%rax)
movl %ecx, 0x10(%rax)
movq %rax, 0x60(%rbx)
movq 0x60(%r15), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movl 0xc(%rbx), %ecx
shlq $0x4, %rcx
movl (%rax,%rcx), %eax
movl %eax, 0x10(%rbx)
jmp 0x6857
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x6857
pushq $0x18
popq %rsi
callq 0x2170
jmp 0x6857
movq %rbx, %rdi
callq 0x5d62
movl $0xa0, %esi
movq %rbx, %rdi
callq 0x2170
leaq 0x3119(%rip), %rdi      # 0x9a98
callq 0x2270
jmp 0x6855
movq %rax, %r14
movl $0xa0, %esi
movq %rbx, %rdi
callq 0x2170
movq %r14, %rdi
callq 0x22b0