// File: /workspace/github_cpp_makefile_star2_O1/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 0x7398
movl (%r14), %ecx
movq (%r12), %rax
cmpl (%rax), %ecx
jne 0x7412
movl 0x4(%r14), %ecx
cmpl 0x4(%rax), %ecx
jne 0x7412
movl $0xa0, %edi
callq 0x2190
movq %rax, %rbx
movq (%r15), %rsi
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0xc(%r15)
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %ebp, %r8d
callq 0x68b4
movq %r12, 0x90(%rbx)
movq (%r15), %rax
movq %rax, 0x48(%rbx)
cmpl $0x2, %ebp
jne 0x7462
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x73ed
movl $0x18, %esi
callq 0x21a0
movl $0x18, %edi
callq 0x2190
movups (%r14), %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x10(%rax)
movq %rax, 0x60(%rbx)
movl $0xffffffff, 0x10(%rbx) # imm = 0xFFFFFFFF
jmp 0x7456
movq 0x6bb7(%rip), %rbx      # 0xdfd0
leaq 0x36d3(%rip), %rsi      # 0xaaf3
movl $0x2c, %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
callq 0x20f0
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 0x74df
movl $0x1, 0x40(%rbx)
cmpl $-0x1, %eax
jne 0x7532
movq 0x6aff(%rip), %rdi      # 0xdfd0
leaq 0x3648(%rip), %rsi      # 0xab20
movl $0x20, %edx
jmp 0x74fe
movl $0x0, 0x40(%rbx)
cmpl $-0x1, %eax
je 0x7532
movq 0x6ade(%rip), %rdi      # 0xdfd0
leaq 0x3648(%rip), %rsi      # 0xab41
movl $0x28, %edx
callq 0x21e0
movq 0x6ac6(%rip), %r12      # 0xdfd0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2050
movq %rax, %rdi
callq 0x20f0
testl %ebp, %ebp
je 0x7590
cmpl $0x2, %ebp
je 0x73da
cmpl $0x1, %ebp
jne 0x75ac
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x7557
movl $0x18, %esi
callq 0x21a0
movl $0x18, %edi
callq 0x2190
movups (%r14), %xmm0
movl 0x10(%r14), %ecx
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 0x7456
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x7456
movl $0x18, %esi
callq 0x21a0
jmp 0x7456
movq %rbx, %rdi
callq 0x66d0
movl $0xa0, %esi
movq %rbx, %rdi
callq 0x21a0
leaq 0x35cc(%rip), %rdi      # 0xab94
callq 0x22a0
jmp 0x7454
movq %rax, %r14
movl $0xa0, %esi
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x22e0