// File: /workspace/github_cpp_makefile_star2_O1/jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_cursor_del
int
mdb_cursor_del(MDB_cursor *mc, unsigned int flags)
{
	MDB_node	*leaf;
	MDB_page	*mp;
	int rc;

	if (mc->mc_txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_BLOCKED))
		return (mc->mc_txn->mt_flags & MDB_TXN_RDONLY) ? EACCES : MDB_BAD_TXN;

	if (!(mc->mc_flags & C_INITIALIZED))
		return EINVAL;

	if (mc->mc_ki[mc->mc_top] >= NUMKEYS(mc->mc_pg[mc->mc_top]))
		return MDB_NOTFOUND;

	if (!(flags & MDB_NOSPILL) && (rc = mdb_page_spill(mc, NULL, NULL)))
		return rc;

	rc = mdb_cursor_touch(mc);
	if (rc)
		return rc;

	mp = mc->mc_pg[mc->mc_top];
	if (IS_LEAF2(mp))
		goto del_key;
	leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);

	if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
		if (flags & MDB_NODUPDATA) {
			/* mdb_cursor_del0() will subtract the final entry */
			mc->mc_db->md_entries -= mc->mc_xcursor->mx_db.md_entries - 1;
		} else {
			if (!F_ISSET(leaf->mn_flags, F_SUBDATA)) {
				mc->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
			}
			rc = mdb_cursor_del(&mc->mc_xcursor->mx_cursor, MDB_NOSPILL);
			if (rc)
				return rc;
			/* If sub-DB still has entries, we're done */
			if (mc->mc_xcursor->mx_db.md_entries) {
				if (leaf->mn_flags & F_SUBDATA) {
					/* update subDB info */
					void *db = NODEDATA(leaf);
					memcpy(db, &mc->mc_xcursor->mx_db, sizeof(MDB_db));
				} else {
					MDB_cursor *m2;
					/* shrink fake page */
					mdb_node_shrink(mp, mc->mc_ki[mc->mc_top]);
					leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
					mc->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
					/* fix other sub-DB cursors pointed at this fake page */
					for (m2 = mc->mc_txn->mt_cursors[mc->mc_dbi]; m2; m2=m2->mc_next) {
						if (m2 == mc || m2->mc_snum < mc->mc_snum) continue;
						if (m2->mc_pg[mc->mc_top] == mp &&
							m2->mc_ki[mc->mc_top] == mc->mc_ki[mc->mc_top])
							m2->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(leaf);
					}
				}
				mc->mc_db->md_entries--;
				mc->mc_flags |= C_DEL;
				return rc;
			}
			/* otherwise fall thru and delete the sub-DB */
		}

		if (leaf->mn_flags & F_SUBDATA) {
			/* add all the child DB's pages to the free list */
			rc = mdb_drop0(&mc->mc_xcursor->mx_cursor, 0);
			if (rc)
				goto fail;
		}
	}
	/* LMDB passes F_SUBDATA in 'flags' to delete a DB record */
	else if ((leaf->mn_flags ^ flags) & F_SUBDATA) {
		rc = MDB_INCOMPATIBLE;
		goto fail;
	}

	/* add overflow pages to free list */
	if (F_ISSET(leaf->mn_flags, F_BIGDATA)) {
		MDB_page *omp;
		pgno_t pg;

		memcpy(&pg, NODEDATA(leaf), sizeof(pg));
		if ((rc = mdb_page_get(mc->mc_txn, pg, &omp, NULL)) ||
			(rc = mdb_ovpage_free(mc, omp)))
			goto fail;
	}

del_key:
	return mdb_cursor_del0(mc);

fail:
	mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
	return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x18(%rdi), %rax
movl 0x7c(%rax), %eax
testl $0x20013, %eax          # imm = 0x20013
je 0x8e66
btl $0x11, %eax
movl $0xffff87c2, %ecx       # imm = 0xFFFF87C2
movl $0xd, %eax
cmovael %ecx, %eax
jmp 0x8eba
movq %rdi, %rbx
movl $0x16, %eax
testb $0x1, 0x44(%rdi)
je 0x8eba
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %ecx
movq 0x48(%rbx,%rax,8), %rax
movzwl 0xc(%rax), %edx
addl $-0x10, %edx
shrl %edx
movl $0xffff87b2, %eax       # imm = 0xFFFF87B2
cmpl %ecx, %edx
jbe 0x8eba
movl %esi, %ebp
testw %bp, %bp
js 0x8eae
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x6e5b
testl %eax, %eax
jne 0x8eba
movq %rbx, %rdi
callq 0x7124
testl %eax, %eax
je 0x8ec5
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r14
testb $0x20, 0xa(%r14)
jne 0x9060
movzwl 0x148(%rbx,%rax,2), %eax
movzwl 0x10(%r14,%rax,2), %eax
leaq (%r14,%rax), %r15
movzwl 0x4(%r14,%rax), %ecx
testb $0x4, %cl
jne 0x8f0b
xorl %ebp, %ecx
movl $0xffff87c0, %eax       # imm = 0xFFFF87C0
testb $0x2, %cl
je 0x9013
jmp 0x9072
testb $0x20, %bpl
jne 0x8fe3
testb $0x2, %cl
jne 0x8f2e
movzwl 0x6(%r15), %eax
addq %r15, %rax
addq $0x8, %rax
movq 0x10(%rbx), %rcx
movq %rax, 0x48(%rcx)
movq 0x10(%rbx), %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x8e3e
testl %eax, %eax
jne 0x8eba
movq 0x10(%rbx), %rax
cmpq $0x0, 0x1a8(%rax)
je 0x8ffd
testb $0x2, 0x4(%r15)
jne 0x907f
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %esi
movq %r14, %rdi
callq 0x90ba
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %ecx
movzwl 0x10(%r14,%rcx,2), %edx
leaq (%r14,%rdx), %rsi
movzwl 0x6(%r14,%rdx), %edx
leaq 0x8(%rdx,%rsi), %rdx
movq 0x10(%rbx), %rsi
movq %rdx, 0x48(%rsi)
movq 0x18(%rbx), %rsi
movq 0x68(%rsi), %rsi
movl 0x20(%rbx), %edi
movq (%rsi,%rdi,8), %rsi
testq %rsi, %rsi
je 0x90a7
cmpq %rbx, %rsi
je 0x8fde
movzwl 0x40(%rsi), %edi
cmpw 0x40(%rbx), %di
jb 0x8fde
cmpq %r14, 0x48(%rsi,%rax,8)
jne 0x8fde
cmpw %cx, 0x148(%rsi,%rax,2)
jne 0x8fde
movq 0x10(%rsi), %rdi
movq %rdx, 0x48(%rdi)
movq (%rsi), %rsi
jmp 0x8fad
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %rcx
movq 0x20(%rcx), %rdx
subq 0x1a8(%rax), %rdx
incq %rdx
movq %rdx, 0x20(%rcx)
testb $0x2, 0x4(%r15)
je 0x9013
movq 0x10(%rbx), %rdi
xorl %esi, %esi
callq 0x91ac
testl %eax, %eax
jne 0x9072
testb $0x1, 0x4(%r15)
je 0x9060
movzwl 0x6(%r15), %eax
movq 0x8(%r15,%rax), %rsi
movq 0x18(%rbx), %rdi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x789a
testl %eax, %eax
je 0x903d
movl $0x6, %ecx
jmp 0x9053
movq (%rsp), %rsi
movq %rbx, %rdi
callq 0x7b8f
testl %eax, %eax
movl $0x6, %ecx
cmovel %eax, %ecx
cmpl $0x6, %ecx
je 0x9072
testl %ecx, %ecx
jne 0x8eba
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x948a
movq 0x18(%rbx), %rcx
orl $0x2, 0x7c(%rcx)
jmp 0x8eba
addq $0x188, %rax            # imm = 0x188
movzwl 0x6(%r15), %ecx
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x28(%r15,%rcx)
movups %xmm1, 0x18(%r15,%rcx)
movups %xmm0, 0x8(%r15,%rcx)
movq 0x28(%rbx), %rax
decq 0x20(%rax)
orb $0x8, 0x44(%rbx)
xorl %eax, %eax
jmp 0x8eba