// File: jvanns[P]verbatim/sub/lmdb/libraries/liblmdb/mdb.c
// Function: mdb_drop0
static int
mdb_drop0(MDB_cursor *mc, int subs)
{
	int rc;

	rc = mdb_page_search(mc, NULL, MDB_PS_FIRST);
	if (rc == MDB_SUCCESS) {
		MDB_txn *txn = mc->mc_txn;
		MDB_node *ni;
		MDB_cursor mx;
		unsigned int i;

		/* DUPSORT sub-DBs have no ovpages/DBs. Omit scanning leaves.
		 * This also avoids any P_LEAF2 pages, which have no nodes.
		 */
		if (mc->mc_flags & C_SUB)
			mdb_cursor_pop(mc);

		mdb_cursor_copy(mc, &mx);
		while (mc->mc_snum > 0) {
			MDB_page *mp = mc->mc_pg[mc->mc_top];
			unsigned n = NUMKEYS(mp);
			if (IS_LEAF(mp)) {
				for (i=0; i<n; i++) {
					ni = NODEPTR(mp, i);
					if (ni->mn_flags & F_BIGDATA) {
						MDB_page *omp;
						pgno_t pg;
						memcpy(&pg, NODEDATA(ni), sizeof(pg));
						rc = mdb_page_get(txn, pg, &omp, NULL);
						if (rc != 0)
							goto done;
						mdb_cassert(mc, IS_OVERFLOW(omp));
						rc = mdb_midl_append_range(&txn->mt_free_pgs,
							pg, omp->mp_pages);
						if (rc)
							goto done;
					} else if (subs && (ni->mn_flags & F_SUBDATA)) {
						mdb_xcursor_init1(mc, ni);
						rc = mdb_drop0(&mc->mc_xcursor->mx_cursor, 0);
						if (rc)
							goto done;
					}
				}
			} else {
				if ((rc = mdb_midl_need(&txn->mt_free_pgs, n)) != 0)
					goto done;
				for (i=0; i<n; i++) {
					pgno_t pg;
					ni = NODEPTR(mp, i);
					pg = NODEPGNO(ni);
					/* free it */
					mdb_midl_xappend(txn->mt_free_pgs, pg);
				}
			}
			if (!mc->mc_top)
				break;
			mc->mc_ki[mc->mc_top] = i;
			rc = mdb_cursor_sibling(mc, 1);
			if (rc) {
				if (rc != MDB_NOTFOUND)
					goto done;
				/* no more siblings, go back to beginning
				 * of previous level.
				 */
				mdb_cursor_pop(mc);
				mc->mc_ki[0] = 0;
				for (i=1; i<mc->mc_snum; i++) {
					mc->mc_ki[i] = 0;
					mc->mc_pg[i] = mx.mc_pg[i];
				}
			}
		}
		/* free it */
		rc = mdb_midl_append(&txn->mt_free_pgs, mc->mc_db->md_root);
done:
		if (rc)
			txn->mt_flags |= MDB_TXN_ERROR;
	} else if (rc == MDB_NOTFOUND) {
		rc = MDB_SUCCESS;
	}
	return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x4, %edx
callq 0xeec0
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0xd605
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x44(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xd255
movq -0x8(%rbp), %rdi
callq 0x10080
movq -0x8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x11080
movq -0x8(%rbp), %rax
movzwl 0x40(%rax), %eax
cmpl $0x0, %eax
jle 0xd5d4
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x42(%rcx), %ecx
movq 0x48(%rax,%rcx,8), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b8(%rbp), %rax
movzwl 0xc(%rax), %eax
subl $0x10, %eax
shrl %eax
movl %eax, -0x1bc(%rbp)
movq -0x1b8(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0xd420
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x1bc(%rbp), %eax
jae 0xd41b
movq -0x1b8(%rbp), %rax
movq -0x1b8(%rbp), %rcx
movl -0x1ac(%rbp), %edx
movzwl 0x10(%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd3c1
movq -0x20(%rbp), %rax
movq -0x20(%rbp), %rcx
movzwl 0x6(%rcx), %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx), %rax
movq %rax, -0x1d0(%rbp)
movq -0x18(%rbp), %rdi
movq -0x1d0(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0xa740
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xd352
jmp 0xd5f0
movq -0x1c8(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x4, %eax
cmpl $0x4, %eax
jne 0xd367
jmp 0xd393
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0xa8f7(%rip), %rsi      # 0x17c71
leaq 0xa901(%rip), %rdx      # 0x17c82
leaq 0xa087(%rip), %rcx      # 0x1740f
movl $0x2522, %r8d           # imm = 0x2522
callq 0x133a0
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x12a30
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xd3bf
jmp 0xd5f0
jmp 0xd405
cmpl $0x0, -0xc(%rbp)
je 0xd403
movq -0x20(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xd403
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8800
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %esi, %esi
callq 0xd200
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xd401
jmp 0xd5f0
jmp 0xd403
jmp 0xd405
jmp 0xd407
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0xd2c5
jmp 0xd503
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movl -0x1bc(%rbp), %esi
callq 0x127b0
movl %eax, -0x10(%rbp)
cmpl $0x0, %eax
je 0xd440
jmp 0xd5f0
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x1bc(%rbp), %eax
jae 0xd501
movq -0x1b8(%rbp), %rax
movq -0x1b8(%rbp), %rcx
movl -0x1ac(%rbp), %edx
movzwl 0x10(%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
shlq $0x10, %rcx
orq %rcx, %rax
movq -0x20(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rcx
movq (%rcx), %rax
addq $0x1, %rax
movq %rax, (%rcx)
movq %rax, -0x1e8(%rbp)
movq -0x1d8(%rbp), %rdx
movq -0x1e0(%rbp), %rax
movq -0x1e8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0xd4ed
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0xd44a
jmp 0xd503
movq -0x8(%rbp), %rax
cmpw $0x0, 0x42(%rax)
jne 0xd513
jmp 0xd5d4
movl -0x1ac(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x42(%rcx), %ecx
movw %dx, 0x148(%rax,%rcx,2)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0xfe30
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xd5cf
cmpl $0xffff87b2, -0x10(%rbp) # imm = 0xFFFF87B2
je 0xd559
jmp 0xd5f0
movq -0x8(%rbp), %rdi
callq 0x10080
movq -0x8(%rbp), %rax
movw $0x0, 0x148(%rax)
movl $0x1, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x40(%rcx), %ecx
cmpl %ecx, %eax
jae 0xd5cd
movq -0x8(%rbp), %rax
movl -0x1ac(%rbp), %ecx
movw $0x0, 0x148(%rax,%rcx,2)
movl -0x1ac(%rbp), %eax
movq -0x160(%rbp,%rax,8), %rdx
movq -0x8(%rbp), %rax
movl -0x1ac(%rbp), %ecx
movq %rdx, 0x48(%rax,%rcx,8)
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0xd579
jmp 0xd5cf
jmp 0xd265
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rsi
callq 0x12860
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xd603
movq -0x18(%rbp), %rax
movl 0x7c(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x7c(%rax)
jmp 0xd617
cmpl $0xffff87b2, -0x10(%rbp) # imm = 0xFFFF87B2
jne 0xd615
movl $0x0, -0x10(%rbp)
jmp 0xd617
movl -0x10(%rbp), %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
nopw %cs:(%rax,%rax)