// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18(%rdi), %rax
movl 0x7c(%rax), %eax
testl $0x20013, %eax          # imm = 0x20013
je 0x8454
btl $0x11, %eax
movl $0xffff87c2, %ecx       # imm = 0xFFFF87C2
pushq $0xd
popq %rax
cmovael %ecx, %eax
jmp 0x864b
movq %rdi, %rbx
testb $0x1, 0x44(%rdi)
jne 0x8465
pushq $0x16
popq %rax
jmp 0x864b
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 0x864b
movl %esi, %ebp
testw %bp, %bp
js 0x84a7
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x665e
testl %eax, %eax
jne 0x864b
movq %rbx, %rdi
callq 0x68e6
testl %eax, %eax
jne 0x864b
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r14
testb $0x20, 0xa(%r14)
jne 0x8614
movzwl 0x148(%rbx,%rax,2), %eax
movzwl 0x10(%r14,%rax,2), %eax
leaq (%r14,%rax), %r15
movzwl 0x4(%r14,%rax), %ecx
movzwl %cx, %edx
testb $0x4, %dl
jne 0x8500
xorl %ebp, %edx
movl $0xffff87c0, %eax       # imm = 0xFFFF87C0
testb $0x2, %dl
je 0x860b
jmp 0x8643
testb $0x20, %bpl
jne 0x85dc
testb $0x2, %dl
jne 0x8523
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 0x8427
testl %eax, %eax
jne 0x864b
movq 0x10(%rbx), %rdi
cmpq $0x0, 0x1a8(%rdi)
movzwl 0x4(%r15), %ecx
je 0x85f6
testb $0x2, %cl
jne 0x87c6
movl $0xfffffff0, %r12d      # imm = 0xFFFFFFF0
movzwl 0x42(%rbx), %ecx
movzwl 0x148(%rbx,%rcx,2), %r15d
movzwl 0x10(%r14,%r15,2), %edx
leaq (%r14,%rdx), %rsi
movzwl 0x6(%r14,%rdx), %eax
movzwl 0x16(%rax,%rsi), %ebp
movzwl 0x14(%rax,%rsi), %r8d
subl %r8d, %ebp
movzwl (%r14,%rdx), %r9d
subl %ebp, %r9d
testb $0x20, 0x12(%rax,%rsi)
jne 0x8802
movzwl %bp, %edi
leal (%r8,%r12), %r10d
movl %r10d, %ecx
shrl %ecx
andl $-0x2, %r10d
addq %rax, %rdx
addq %r10, %rdx
leaq (%r14,%rdx), %r10
addq $0x16, %r10
pushq $0x10
popq %rdx
testq %rcx, %rcx
jle 0x8813
decq %rcx
movzwl (%r10), %r11d
subl %ebp, %r11d
movw %r11w, (%r10,%rdi)
addq $-0x2, %r10
jmp 0x85be
movq 0x10(%rbx), %rdi
movq 0x28(%rbx), %rax
movq 0x20(%rax), %rdx
subq 0x1a8(%rdi), %rdx
incq %rdx
movq %rdx, 0x20(%rax)
testb $0x2, %cl
je 0x860b
xorl %esi, %esi
callq 0x88e8
testl %eax, %eax
jne 0x8643
movzwl 0x4(%r15), %ecx
testb $0x1, %cl
jne 0x878d
movzwl 0x42(%rbx), %eax
movzwl 0x148(%rbx,%rax,2), %r15d
movq 0x28(%rbx), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x6e79
movq 0x28(%rbx), %rax
decq 0x20(%rax)
movq %rbx, %rdi
callq 0xa19a
testl %eax, %eax
je 0x865a
movq 0x18(%rbx), %rcx
orl $0x2, 0x7c(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpw $0x0, 0x40(%rbx)
je 0x87fb
movl 0x20(%rbx), %r12d
movzwl 0x42(%rbx), %eax
movq 0x48(%rbx,%rax,8), %r13
movzwl 0xc(%r13), %ebp
addl $-0x10, %ebp
shrl %ebp
movzwl 0x148(%rbx,%rax,2), %ecx
xorl %eax, %eax
cmpl %ecx, %ebp
ja 0x86a2
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x9e6c
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x86a2
orb $0x2, 0x44(%rbx)
xorl %eax, %eax
movq 0x18(%rbx), %rcx
shlq $0x3, %r12
addq 0x68(%rcx), %r12
movl 0x44(%rbx), %ecx
testl %eax, %eax
jne 0x877d
movq (%r12), %r12
testq %r12, %r12
je 0x877d
movq %r12, %r14
testb $0x4, %cl
je 0x86d3
movq 0x10(%r12), %r14
movl $0x0, %eax
cmpq %rbx, %r14
je 0x86ae
movl 0x44(%r14), %ecx
movl 0x44(%r12), %edx
andl %ecx, %edx
andl $0x1, %edx
je 0x86ae
movzwl 0x40(%r14), %edx
cmpw 0x40(%rbx), %dx
jb 0x86ae
movzwl 0x42(%rbx), %edx
cmpq %r13, 0x48(%r14,%rdx,8)
jne 0x86ae
movzwl 0x148(%r14,%rdx,2), %eax
cmpw %r15w, %ax
jb 0x874b
orl $0x8, %ecx
movl %ecx, 0x44(%r14)
cmpw %r15w, %ax
jbe 0x8739
decl %eax
movw %ax, 0x148(%r14,%rdx,2)
movzwl 0x42(%rbx), %eax
movzwl 0x148(%r14,%rax,2), %eax
jmp 0x874b
movq 0x28(%rbx), %rcx
testb $0x4, 0x4(%rcx)
je 0x874b
movq 0x10(%r14), %rcx
orl $0x2, 0x44(%rcx)
movzwl %ax, %ecx
movl $0x0, %eax
cmpl %ecx, %ebp
ja 0x86ae
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x9e6c
cmpl $0xffff87b2, %eax       # imm = 0xFFFF87B2
jne 0x86ae
orb $0x2, 0x44(%r14)
xorl %eax, %eax
jmp 0x86ae
orl $0x8, %ecx
movl %ecx, 0x44(%rbx)
testl %eax, %eax
jne 0x8643
jmp 0x87fb
movzwl 0x6(%r15), %eax
movq 0x8(%r15,%rax), %rsi
movq 0x18(%rbx), %rdi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x6fba
testl %eax, %eax
jne 0x8643
movq (%rsp), %rsi
movq %rbx, %rdi
callq 0x725b
testl %eax, %eax
jne 0x8643
jmp 0x8614
addq $0x188, %rdi            # imm = 0x188
movzwl 0x6(%r15), %eax
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movups %xmm2, 0x28(%r15,%rax)
movups %xmm1, 0x18(%r15,%rax)
movups %xmm0, 0x8(%r15,%rax)
movq 0x28(%rbx), %rax
decq 0x20(%rax)
orb $0x8, 0x44(%rbx)
xorl %eax, %eax
jmp 0x864b
testb $0x1, %r9b
jne 0x8894
movzwl %bp, %edi
movzwl %r9w, %edx
addq %rsi, %rax
addq $0x8, %rax
movw %r8w, 0xe(%rax)
movq (%r14), %rcx
movq %rcx, (%rax)
movw %r9w, (%rsi)
andw $0x0, 0x2(%rsi)
movzwl 0xe(%r14), %esi
addq %r14, %rsi
addq %rsi, %rdi
addq %rax, %rdx
subq %rsi, %rdx
callq 0x22e0
movzwl 0x10(%r14,%r15,2), %eax
movzwl 0xc(%r14), %ecx
addl %ecx, %r12d
shrl %r12d
testq %r12, %r12
jle 0x8872
movzwl 0xe(%r14,%r12,2), %ecx
cmpw %ax, %cx
ja 0x886d
addl %ebp, %ecx
movw %cx, 0xe(%r14,%r12,2)
decq %r12
jmp 0x8855
addw %bp, 0xe(%r14)
movzwl 0x42(%rbx), %ecx
movzwl 0x148(%rbx,%rcx,2), %r15d
movzwl 0x10(%r14,%r15,2), %edx
movzwl 0x6(%r14,%rdx), %eax
movq 0x10(%rbx), %rdi
addq %r14, %rdx
addq %rdx, %rax
addq $0x8, %rax
movq %rax, 0x48(%rdi)
movq 0x18(%rbx), %rsi
movl 0x20(%rbx), %edx
shlq $0x3, %rdx
addq 0x68(%rsi), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x87ef
cmpq %rbx, %rdx
je 0x88b1
movzwl 0x40(%rdx), %esi
cmpw 0x40(%rbx), %si
jb 0x88b1
cmpq %r14, 0x48(%rdx,%rcx,8)
jne 0x88b1
cmpw %r15w, 0x148(%rdx,%rcx,2)
jne 0x88b1
movq 0x10(%rdx), %rsi
movq %rax, 0x48(%rsi)
jmp 0x88b1