// File: /workspace/github_cpp_makefile_star2_O3/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), %ebp
movq 0x28(%rdi), %rax
movl (%rax), %esi
callq 0x7385
movq 0x28(%rbx), %rax
decq 0x20(%rax)
movq %rbx, %rdi
callq 0xa9b7
testl %eax, %eax
je 0x9129
movq 0x18(%rbx), %rcx
orl $0x2, 0x7c(%rcx)
jmp 0x9254
cmpw $0x0, 0x40(%rbx)
je 0x9252
movl 0x20(%rbx), %r14d
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r15
movzwl 0xc(%r15), %r12d
addl $-0x10, %r12d
shrl %r12d
movzwl 0x148(%rbx,%rax,2), %ecx
xorl %eax, %eax
cmpl %ecx, %r12d
ja 0x9176
movq %rbx, %rdi
movl $0x1, %esi
callq 0xa6a4
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x9176
orb $0x2, 0x44(%rbx)
xorl %eax, %eax
testl %eax, %eax
jne 0x9246
movq 0x18(%rbx), %rcx
movq 0x68(%rcx), %rcx
movq (%rcx,%r14,8), %r13
testq %r13, %r13
je 0x9246
testb $0x4, 0x44(%rbx)
movq %r13, %r14
je 0x91a0
movq 0x10(%r13), %r14
xorl %eax, %eax
cmpq %rbx, %r14
je 0x9239
movl 0x44(%r14), %edx
movl 0x44(%r13), %ecx
andl %edx, %ecx
andl $0x1, %ecx
je 0x9239
movzwl 0x40(%r14), %ecx
cmpw 0x40(%rbx), %cx
jb 0x9239
movzwl 0x42(%rbx), %esi
cmpq %r15, 0x48(%r14,%rsi,8)
jne 0x9239
movzwl 0x148(%r14,%rsi,2), %ecx
cmpw %bp, %cx
jb 0x9216
orl $0x8, %edx
movl %edx, 0x44(%r14)
cmpw %bp, %cx
jbe 0x9204
decl %ecx
movw %cx, 0x148(%r14,%rsi,2)
movzwl 0x42(%rbx), %ecx
movzwl 0x148(%r14,%rcx,2), %ecx
jmp 0x9216
movq 0x28(%rbx), %rdx
testb $0x4, 0x4(%rdx)
je 0x9216
movq 0x10(%r14), %rdx
orl $0x2, 0x44(%rdx)
movzwl %cx, %ecx
cmpl %ecx, %r12d
ja 0x9239
movq %r14, %rdi
movl $0x1, %esi
callq 0xa6a4
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x9239
orb $0x2, 0x44(%r14)
xorl %eax, %eax
testl %eax, %eax
jne 0x9246
movq (%r13), %r13
jmp 0x918a
orb $0x8, 0x44(%rbx)
testl %eax, %eax
jne 0x911c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq