// File: jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_node_del
static void
mdb_node_del(MDB_cursor *mc, int ksize)
{
	MDB_page *mp = mc->mc_pg[mc->mc_top];
	indx_t	indx = mc->mc_ki[mc->mc_top];
	unsigned int	 sz;
	indx_t		 i, j, numkeys, ptr;
	MDB_node	*node;
	char		*base;

	DPRINTF(("delete node %u on %s page %"Z"u", indx,
	    IS_LEAF(mp) ? "leaf" : "branch", mdb_dbg_pgno(mp)));
	numkeys = NUMKEYS(mp);
	mdb_cassert(mc, indx < numkeys);

	if (IS_LEAF2(mp)) {
		int x = numkeys - 1 - indx;
		base = LEAF2KEY(mp, indx, ksize);
		if (x)
			memmove(base, base + ksize, x * ksize);
		mp->mp_lower -= sizeof(indx_t);
		mp->mp_upper += ksize - sizeof(indx_t);
		return;
	}

	node = NODEPTR(mp, indx);
	sz = NODESIZE + node->mn_ksize;
	if (IS_LEAF(mp)) {
		if (F_ISSET(node->mn_flags, F_BIGDATA))
			sz += sizeof(pgno_t);
		else
			sz += NODEDSZ(node);
	}
	sz = EVEN(sz);

	ptr = mp->mp_ptrs[indx];
	for (i = j = 0; i < numkeys; i++) {
		if (i != indx) {
			mp->mp_ptrs[j] = mp->mp_ptrs[i];
			if (mp->mp_ptrs[i] < ptr)
				mp->mp_ptrs[j] += sz;
			j++;
		}
	}

	base = (char *)mp + mp->mp_upper + PAGEBASE;
	memmove(base + sz, base, ptr - mp->mp_upper);

	mp->mp_lower -= sizeof(indx_t);
	mp->mp_upper += sz;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x42(%rcx), %ecx
movq 0x48(%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x42(%rcx), %ecx
movw 0x148(%rax,%rcx,2), %ax
movw %ax, -0x1a(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %eax
subl $0x10, %eax
shrl %eax
movw %ax, -0x26(%rbp)
movzwl -0x1a(%rbp), %eax
movzwl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jge 0xa50b
jmp 0xa537
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0xd687(%rip), %rsi      # 0x17ba5
leaq 0xd68f(%rip), %rdx      # 0x17bb4
leaq 0xcee3(%rip), %rcx      # 0x1740f
movl $0x1bfc, %r8d           # imm = 0x1BFC
callq 0x133a0
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x20, %eax
cmpl $0x20, %eax
jne 0xa5c1
movzwl -0x26(%rbp), %eax
subl $0x1, %eax
movzwl -0x1a(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
addq $0x10, %rax
movzwl -0x1a(%rbp), %ecx
imull -0xc(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0xa595
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0xc(%rbp), %rax
addq %rax, %rsi
movl -0x3c(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdx
callq 0x22c0
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %ecx
subq $0x2, %rcx
movw %cx, 0xc(%rax)
movslq -0xc(%rbp), %rdx
subq $0x2, %rdx
movq -0x18(%rbp), %rax
movzwl 0xe(%rax), %ecx
addq %rdx, %rcx
movw %cx, 0xe(%rax)
jmp 0xa731
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movzwl -0x1a(%rbp), %edx
movzwl 0x10(%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x6(%rax), %eax
addq $0x8, %rax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0xa633
movq -0x30(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0xa617
movl -0x20(%rbp), %eax
addq $0x8, %rax
movl %eax, -0x20(%rbp)
jmp 0xa631
movq -0x30(%rbp), %rax
movzwl (%rax), %eax
movq -0x30(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0xa633
movl -0x20(%rbp), %eax
addl $0x1, %eax
andl $-0x2, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movw 0x10(%rax,%rcx,2), %ax
movw %ax, -0x28(%rbp)
movw $0x0, -0x24(%rbp)
movw $0x0, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
movzwl -0x26(%rbp), %ecx
cmpl %ecx, %eax
jge 0xa6d6
movzwl -0x22(%rbp), %eax
movzwl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
je 0xa6c6
movq -0x18(%rbp), %rax
movzwl -0x22(%rbp), %ecx
movw 0x10(%rax,%rcx,2), %dx
movq -0x18(%rbp), %rax
movzwl -0x24(%rbp), %ecx
movw %dx, 0x10(%rax,%rcx,2)
movq -0x18(%rbp), %rax
movzwl -0x22(%rbp), %ecx
movzwl 0x10(%rax,%rcx,2), %eax
movzwl -0x28(%rbp), %ecx
cmpl %ecx, %eax
jge 0xa6ba
movl -0x20(%rbp), %esi
movq -0x18(%rbp), %rax
movzwl -0x24(%rbp), %ecx
movzwl 0x10(%rax,%rcx,2), %edx
addl %esi, %edx
movw %dx, 0x10(%rax,%rcx,2)
movw -0x24(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x24(%rbp)
jmp 0xa6c8
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
jmp 0xa65c
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl -0x20(%rbp), %eax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movzwl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
subl %ecx, %eax
movslq %eax, %rdx
callq 0x22c0
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %ecx
subq $0x2, %rcx
movw %cx, 0xc(%rax)
movl -0x20(%rbp), %edx
movq -0x18(%rbp), %rax
movzwl 0xe(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xe(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)