// File: narges64[P]SIMBA/ftl.cpp
// Function: find_location(ssd_info*, int, local*)
void find_location(ssd_info * ssd, int ppn, local * location){
	int pn,ppn_value=ppn;
	int page_plane=0,page_lun=0,page_channel=0;

	pn = ppn;

	page_plane=ssd->parameter->page_block*ssd->parameter->block_plane;
	page_lun=page_plane*ssd->parameter->plane_lun;

	int page = ppn % (page_lun * ssd->parameter->lun_num);
	int channel = 0;
	while (true){
		page_channel = page_lun * ssd->parameter->lun_channel[location->channel];
		page = page - page_channel;
		if (page < 0){
			page = page + page_channel;
			break;
		}else {
			channel++;
		}
	}
	int lun = page/page_lun;
	int plane = (page%page_lun)/page_plane;
	int block = ((page%page_lun)%page_plane)/ssd->parameter->page_block;
	int page_ = (((page%page_lun)%page_plane)%ssd->parameter->page_block)%ssd->parameter->page_block;

	if (location == NULL) {
		location = new local(channel, lun, plane, block, page_);
	}else {
		location->channel = channel;
		location->lun     = lun;
		location->plane   = plane;
		location->block   = block;
		location->page    = page_;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x234(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
imull 0x230(%rcx), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
imull 0x22c(%rcx), %eax
movl %eax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rdx
movq 0x58(%rdx), %rdx
imull 0x88(%rdx), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x18(%rbp), %rdx
movslq (%rdx), %rdx
imull 0x9c(%rcx,%rdx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0x5d33
movl -0x30(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x5d3e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5cfc
movl -0x30(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %edx, %eax
cltd
idivl -0x24(%rbp)
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %edx, %eax
cltd
idivl -0x24(%rbp)
movl %edx, %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
xorl %edx, %edx
divl 0x234(%rcx)
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %eax
cltd
idivl -0x28(%rbp)
movl %edx, %eax
cltd
idivl -0x24(%rbp)
movl %edx, %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
xorl %edx, %edx
divl 0x234(%rcx)
movl %edx, %eax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
xorl %edx, %edx
divl 0x234(%rcx)
movl %edx, -0x44(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x5e07
movl $0x18, %edi
callq 0x2130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %r8d
movl -0x44(%rbp), %r9d
callq 0x8ae0
jmp 0x5de1
movq -0x60(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x5e38
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x18, %esi
callq 0x2140
jmp 0x5e3e
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x3c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x40(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
addq $0x60, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x2230
nopw (%rax,%rax)