// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_cursor_del0
static int
mdb_cursor_del0(MDB_cursor *mc)
{
	int rc;
	MDB_page *mp;
	indx_t ki;
	unsigned int nkeys;

	ki = mc->mc_ki[mc->mc_top];
	mdb_node_del(mc, mc->mc_db->md_pad);
	mc->mc_db->md_entries--;
	rc = mdb_rebalance(mc);

	if (rc == MDB_SUCCESS) {
		MDB_cursor *m2, *m3;
		MDB_dbi dbi = mc->mc_dbi;

		/* DB is totally empty now, just bail out.
		 * Other cursors adjustments were already done
		 * by mdb_rebalance and aren't needed here.
		 */
		if (!mc->mc_snum)
			return rc;

		mp = mc->mc_pg[mc->mc_top];
		nkeys = NUMKEYS(mp);

		/* if mc points past last node in page, find next sibling */
		if (mc->mc_ki[mc->mc_top] >= nkeys) {
			rc = mdb_cursor_sibling(mc, 1);
			if (rc == MDB_NOTFOUND) {
				mc->mc_flags |= C_EOF;
				rc = MDB_SUCCESS;
			}
		}

		/* Adjust other cursors pointing to mp */
		for (m2 = mc->mc_txn->mt_cursors[dbi]; !rc && m2; m2=m2->mc_next) {
			m3 = (mc->mc_flags & C_SUB) ? &m2->mc_xcursor->mx_cursor : m2;
			if (! (m2->mc_flags & m3->mc_flags & C_INITIALIZED))
				continue;
			if (m3 == mc || m3->mc_snum < mc->mc_snum)
				continue;
			if (m3->mc_pg[mc->mc_top] == mp) {
				if (m3->mc_ki[mc->mc_top] >= ki) {
					m3->mc_flags |= C_DEL;
					if (m3->mc_ki[mc->mc_top] > ki)
						m3->mc_ki[mc->mc_top]--;
					else if (mc->mc_db->md_flags & MDB_DUPSORT)
						m3->mc_xcursor->mx_cursor.mc_flags |= C_EOF;
				}
				if (m3->mc_ki[mc->mc_top] >= nkeys) {
					rc = mdb_cursor_sibling(m3, 1);
					if (rc == MDB_NOTFOUND) {
						m3->mc_flags |= C_EOF;
						rc = MDB_SUCCESS;
					}
				}
			}
		}
		mc->mc_flags |= C_DEL;
	}

	if (rc)
		mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movzwl 0x42(%rdi), %eax
movzwl 0x148(%rdi,%rax,2), %r15d
movq 0x28(%rdi), %rax
movl (%rax), %esi
callq 0x776d
movq 0x28(%rbx), %rax
decq 0x20(%rax)
movq %rbx, %rdi
callq 0xae39
testl %eax, %eax
jne 0x960d
movzwl 0x40(%rbx), %ecx
xorl %ebp, %ebp
movl $0x0, %eax
testw %cx, %cx
je 0x9608
movw %cx, 0x6(%rsp)
movl 0x20(%rbx), %r14d
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r13
movzwl 0xc(%r13), %r12d
addl $-0x10, %r12d
shrl %r12d
movzwl 0x148(%rbx,%rax,2), %ecx
xorl %eax, %eax
cmpl %ecx, %r12d
ja 0x9523
movq %rbx, %rdi
movl $0x1, %esi
callq 0xaab8
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x9523
orb $0x2, 0x44(%rbx)
xorl %eax, %eax
testl %eax, %eax
jne 0x95ff
movq 0x18(%rbx), %rcx
movq 0x68(%rcx), %rcx
movq (%rcx,%r14,8), %r14
testq %r14, %r14
je 0x95ff
movw %r15w, 0x4(%rsp)
testb $0x4, 0x44(%rbx)
movq %r14, %r15
je 0x9553
movq 0x10(%r14), %r15
cmpq %rbx, %r15
je 0x95ef
movl 0x44(%r15), %ecx
movl 0x44(%r14), %edx
andl %ecx, %edx
andl $0x1, %edx
je 0x95ef
movzwl 0x40(%r15), %edx
cmpw 0x40(%rbx), %dx
jb 0x95ef
movzwl 0x42(%rbx), %edx
cmpq %r13, 0x48(%r15,%rdx,8)
jne 0x95ef
movzwl 0x148(%r15,%rdx,2), %esi
cmpw 0x4(%rsp), %si
jb 0x95c2
orl $0x8, %ecx
movl %ecx, 0x44(%r15)
cmpw 0x4(%rsp), %si
jbe 0x95b0
decl %esi
movw %si, 0x148(%r15,%rdx,2)
jmp 0x95c2
movq 0x28(%rbx), %rcx
testb $0x4, 0x4(%rcx)
je 0x95c2
movq 0x10(%r15), %rcx
orl $0x2, 0x44(%rcx)
movzwl 0x42(%rbx), %ecx
movzwl 0x148(%r15,%rcx,2), %ecx
cmpl %ecx, %r12d
ja 0x95ef
movq %r15, %rdi
movl $0x1, %esi
callq 0xaab8
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x95ef
orb $0x2, 0x44(%r15)
xorl %eax, %eax
testl %eax, %eax
jne 0x95ff
movq (%r14), %r14
testq %r14, %r14
jne 0x9546
orb $0x8, 0x44(%rbx)
movzwl 0x6(%rsp), %ecx
testw %cx, %cx
je 0x961b
testl %eax, %eax
je 0x9619
movq 0x18(%rbx), %rcx
orl $0x2, 0x7c(%rcx)
movl %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq