LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/dispatch_mr.c
// Function: mpool_reqcookie_free
static struct node *
finddirty(struct nodepair * V, size_t N, struct node * shadow)
{
	struct nodepair * pair;
	struct nodepair k;

	/* Binary search. */
	k.shadow = shadow;
	pair = bsearch(&k, V, N, sizeof(struct nodepair), compar_snp);

	/* If we found the shadow node, return the matching dirty node. */
	if (pair != NULL)
		return (pair->dirty);

	/* Otherwise, return the shadow node we were given. */
	return (shadow);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x5138
movq %rdi, %rbx
movq 0x181ef(%rip), %r12     # 0x1d260
movq 0x181f0(%rip), %r13     # 0x1d268
cmpq %r13, %r12
jae 0x5099
movq 0x181ec(%rip), %rax     # 0x1d270
leaq 0x1(%r12), %rcx
movq %rcx, 0x181d0(%rip)     # 0x1d260
movq %rbx, (%rax,%r12,8)
jmp 0x5138
movq 0x181d8(%rip), %rax     # 0x1d278
shrq $0x8, %rax
cmpq %rax, 0x181d5(%rip)     # 0x1d280
jbe 0x5126
testq %r13, %r13
je 0x5142
movq %r13, %rdi
shlq $0x4, %rdi
callq 0x22a0
testq %rax, %rax
je 0x5126
movq %rax, %r14
movq 0x1819f(%rip), %r15     # 0x1d270
leaq (,%r13,8), %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2280
cmpq 0x181a5(%rip), %r15     # 0x1d290
je 0x5103
movq %r15, %rdi
callq 0x2040
movq 0x1816c(%rip), %r13     # 0x1d268
movq 0x1815d(%rip), %r12     # 0x1d260
movq %r14, 0x18166(%rip)     # 0x1d270
addq %r13, %r13
movq %r13, 0x18154(%rip)     # 0x1d268
leaq 0x1(%r12), %rax
movq %rax, 0x18140(%rip)     # 0x1d260
movq %rbx, (%r14,%r12,8)
jmp 0x512e
movq %rbx, %rdi
callq 0x2040
xorps %xmm0, %xmm0
movups %xmm0, 0x18140(%rip)    # 0x1d278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xf38c(%rip), %rdi      # 0x144d5
leaq 0xf396(%rip), %rsi      # 0x144e6
leaq 0xf3b1(%rip), %rcx      # 0x14508
movl $0x5a, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/dispatch_mr.c
// Function: callback_synced
static int
callback_synced(void * cookie)
{
	struct batch * B = cookie;
	struct req_cookie * req;
	struct proto_kvlds_request * R;
	size_t i;

	/* Send response packets. */
	for (i = 0; i < B->nreqs; i++) {
		req = B->reqs[i];
		R = req->R;

		switch (R->type) {
		case PROTO_KVLDS_SET:
			if (proto_kvlds_response_set(B->WQ, R->ID))
				goto err0;
			break;
		case PROTO_KVLDS_CAS:
			if (proto_kvlds_response_cas(B->WQ, R->ID,
			    req->opdone ? 0 : 1))
				goto err0;
			break;
		case PROTO_KVLDS_ADD:
			if (proto_kvlds_response_add(B->WQ, R->ID,
			    req->opdone ? 0 : 1))
				goto err0;
			break;
		case PROTO_KVLDS_MODIFY:
			if (proto_kvlds_response_modify(B->WQ, R->ID,
			    req->opdone ? 0 : 1))
				goto err0;
			break;
		case PROTO_KVLDS_DELETE:
			if (proto_kvlds_response_delete(B->WQ, R->ID))
				goto err0;
			break;
		case PROTO_KVLDS_CAD:
			if (proto_kvlds_response_cad(B->WQ, R->ID,
			    req->opdone ? 0 : 1))
				goto err0;
			break;
		}
	}

	/* Schedule completion callback. */
	if (!events_immediate_register(B->callback_done, B->cookie, 0))
		goto err0;

	/* Clean up requests and request cookies. */
	for (i = 0; i < B->nreqs; i++) {
		proto_kvlds_request_free(B->reqs[i]->R);
		mpool_reqcookie_free(B->reqs[i]);
	}

	/* Free batch cookie. */
	free(B->reqs);
	free(B);

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0x10(%rdi)
je 0x524e
xorl %r14d, %r14d
leaq 0xf451(%rip), %r15      # 0x14640
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rcx
movl 0x8(%rcx), %edx
leal -0x110(%rdx), %esi
cmpl $0x3, %esi
ja 0x5211
movslq (%r15,%rsi,4), %rdx
addq %r15, %rdx
jmpq *%rdx
cmpl $0x120, %edx            # imm = 0x120
je 0x5233
cmpl $0x121, %edx            # imm = 0x121
jne 0x5245
movq 0x20(%rbx), %rdi
movq (%rcx), %rsi
xorl %edx, %edx
cmpl $0x0, 0x18(%rax)
sete %dl
jmp 0x523c
movq 0x20(%rbx), %rdi
movq (%rcx), %rsi
xorl %edx, %edx
callq 0x10ce7
testl %eax, %eax
jne 0x52a6
incq %r14
cmpq 0x10(%rbx), %r14
jb 0x51ef
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %edx, %edx
callq 0xb910
testq %rax, %rax
je 0x52a6
cmpq $0x0, 0x10(%rbx)
je 0x5291
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rdi
callq 0x10b73
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x5055
incq %r14
cmpq 0x10(%rbx), %r14
jb 0x526b
movq 0x28(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
xorl %eax, %eax
jmp 0x52ab
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/dispatch_nmr.c
// Function: dispatch_nmr_launch
int
dispatch_nmr_launch(struct btree * T, struct proto_kvlds_request * R,
    struct netbuf_write * WQ,
    int (* callback_done)(void *), void * cookie_done)
{
	struct nmr_cookie * C;

	/* Sanity-check: The NMR type must be reasonable. */
	assert((R->type == PROTO_KVLDS_GET) ||
	    (R->type == PROTO_KVLDS_RANGE));

	/* Bake a cookie. */
	if ((C = malloc(sizeof(struct nmr_cookie))) == NULL)
		goto err0;
	C->callback_done = callback_done;
	C->cookie_done = cookie_done;
	C->T = T;
	C->R = R;
	C->WQ = WQ;

	/* Different NMRs need different handling. */
	switch (R->type) {
	case PROTO_KVLDS_GET:
		/* Find the node containing (or not) this key. */
		if (btree_find_leaf(C->T, C->T->root_shadow, C->R->key,
		    callback_get_gotleaf, C))
			goto err1;
		break;
	case PROTO_KVLDS_RANGE:
		/*
		 * Find a node of height 1 or less which is responsible for a
		 * range containing the start key.
		 */
		if (btree_find_range(C->T, C->T->root_shadow,
		    C->R->range_start, 1, callback_range_gotnode, C))
			goto err1;
		break;
	}

	/* Success! */
	return (0);

err1:
	free(C);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movl 0x8(%rsi), %r13d
movl %r13d, %eax
andl $-0x2, %eax
cmpl $0x130, %eax            # imm = 0x130
jne 0x5387
movq %r8, %rbp
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r15
movl $0x58, %edi
callq 0x22a0
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x5378
movq %rbx, (%r14)
movq %rbp, 0x8(%r14)
movq %r15, 0x10(%r14)
movq %r12, 0x18(%r14)
movq (%rsp), %rax
movq %rax, 0x20(%r14)
movq 0x20(%r15), %rsi
movq 0x10(%r12), %rdx
cmpl $0x130, %r13d           # imm = 0x130
jne 0x534c
leaq 0x67(%rip), %rcx        # 0x53a6
movq %r15, %rdi
movq %r14, %r8
callq 0x800f
jmp 0x5363
leaq 0x13b(%rip), %r8        # 0x548e
movq %r15, %rdi
movl $0x1, %ecx
movq %r14, %r9
callq 0x8310
testl %eax, %eax
je 0x5376
movq %r14, %rdi
callq 0x2040
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x5378
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf32d(%rip), %rdi      # 0x146bb
leaq 0xf365(%rip), %rsi      # 0x146fa
leaq 0xf36d(%rip), %rcx      # 0x14709
movl $0x39, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/dispatch_nmr.c
// Function: callback_get_gotleaf
static int
callback_get_gotleaf(void * cookie, struct node * N)
{
	struct nmr_cookie * C = cookie;
	struct kvpair_const * kv;

	/* Find the key in this node. */
	kv = btree_find_kvpair(N, C->R->key);

	/* Send the response. */
	if (kv != NULL) {
		/* Send the requested value back to the client. */
		if (proto_kvlds_response_get(C->WQ, C->R->ID, 0,
		    kv->v))
			goto err1;
	} else {
		/* Send a non-present response back to the client. */
		if (proto_kvlds_response_get(C->WQ, C->R->ID, 1,
		    NULL))
			goto err1;
	}

	/* Schedule the request-done callback. */
	if (!events_immediate_register(C->callback_done, C->cookie_done, 0))
		goto err1;

	/* Unlock the node. */
	btree_node_unlock(C->T, N);

	/* Free the request. */
	proto_kvlds_request_free(C->R);

	/* Free the cookie. */
	free(C);

	/* Success! */
	return (0);

err1:
	btree_node_unlock(C->T, N);
	proto_kvlds_request_free(C->R);
	free(C);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x7ee4
movq 0x18(%rbx), %rcx
movq 0x20(%rbx), %rdi
movq (%rcx), %rsi
testq %rax, %rax
je 0x53d8
movq 0x8(%rax), %rcx
xorl %edx, %edx
jmp 0x53df
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x10d53
testl %eax, %eax
je 0x540c
testq %r14, %r14
je 0x5452
movq 0x10(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x546f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5440
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xb910
testq %rax, %rax
je 0x53e8
testq %r14, %r14
je 0x5457
movq 0x10(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x546f
xorl %ebp, %ebp
decq %rcx
movq %rcx, (%rax)
jne 0x5457
movq %r14, %rsi
callq 0x107ea
jmp 0x5457
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rbx), %rdi
callq 0x10b73
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
leaq 0xf1da(%rip), %rdi      # 0x14650
leaq 0xf1f9(%rip), %rsi      # 0x14676
leaq 0xf20b(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree.c
// Function: callback_gc
static int
callback_gc(void * cookie)
{
	struct btree * T = cookie;

	/* The timer is no longer scheduled. */
	T->gc_timer = NULL;

	/*
	 * Instruct the backing store to free everything older than the
	 * oldest leaf node accessible via the B+Tree root.
	 */
	if (proto_lbs_request_free(T->LBS, T->root_shadow->oldestleaf,
	    callback_free_done, NULL))
		goto err0;

	/* Schedule another FREE. */
	if ((T->gc_timer =
	    events_timer_register(callback_gc, T, &free_time)) == NULL)
		goto err0;

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq $0x0, 0x38(%rdi)
movq 0x18(%rdi), %rdi
movq 0x20(%r14), %rax
movq 0x8(%rax), %rsi
leaq 0x165(%rip), %rdx       # 0x6211
xorl %ebx, %ebx
xorl %ecx, %ecx
callq 0x11748
testl %eax, %eax
je 0x60c0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x60df
leaq -0x3d(%rip), %rdi       # 0x608a
leaq 0xe932(%rip), %rdx      # 0x14a00
movq %r14, %rsi
callq 0xc618
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x60b9
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree.c
// Function: btree_free
void
btree_free(struct btree * T)
{

	/* Sanity-check. */
	assert(T->root_shadow == T->root_dirty);

	/* Shut down the background cleaner. */
	btree_cleaning_stop(T->cstate);

	/* Kill the garbage collection timer. */
	if (T->gc_timer != NULL)
		events_timer_cancel(T->gc_timer);

	/* Release the root locks. */
	btree_node_unlock(T, T->root_shadow);
	btree_node_unlock(T, T->root_dirty);

	/* Page out all pages in the tree. */
	btree_node_pageout_recursive(T, T->root_shadow);

	/* Free the (paged-out) root node. */
	node_free(T->root_shadow);

	/* Free the page pool. */
	pool_free(T->P);

	/* Free the tree structure. */
	free(T);
}

// Assembly:
pushq %rbx
movq 0x20(%rdi), %rax
cmpq 0x28(%rdi), %rax
jne 0x61ac
movq %rdi, %rbx
movq 0x40(%rdi), %rdi
callq 0x7245
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x6112
callq 0xc792
movq 0x20(%rbx), %rsi
testq %rsi, %rsi
je 0x613c
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x618d
decq %rcx
movq %rcx, (%rax)
jne 0x613c
callq 0x107ea
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
je 0x6166
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x618d
decq %rcx
movq %rcx, (%rax)
jne 0x6166
callq 0x107ea
movq 0x20(%rbx), %rsi
movq %rbx, %rdi
callq 0x8ee6
movq 0x20(%rbx), %rdi
callq 0xab9b
movq 0x30(%rbx), %rdi
callq 0x107b8
movq %rbx, %rdi
popq %rbx
jmp 0x2040
leaq 0xe4bc(%rip), %rdi      # 0x14650
leaq 0xe4db(%rip), %rsi      # 0x14676
leaq 0xe4ed(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xe7ee(%rip), %rdi      # 0x149a1
leaq 0xe630(%rip), %rsi      # 0x147ea
leaq 0xe800(%rip), %rcx      # 0x149c1
movl $0x1a0, %edx            # imm = 0x1A0
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_balance.c
// Function: domerge
static int
domerge(void * cookie)
{
	struct balance_cookie * B = cookie;
	struct btree * T = B->T;

	/* We should have all the nodes we need. */
	assert(B->nmergefetch == 0);

	/* Do the merging. */
	if (domergenode(B, T->root_dirty))
		goto err0;

#ifdef SANITY_CHECKS
	/* Sanity check the B+Tree. */
	btree_sanity(T);
#endif

	/* If the tree is not fully merged, plan more merges. */
	if (T->root_dirty->needmerge) {
		if (planmerge(B))
			goto err0;
	} else {
		/* Remove extraneous root nodes. */
		deroot(B);

		/* We're done!  Schedule the callback and free the cookie. */
		if (!events_immediate_register(B->callback, B->cookie, 0))
			goto err0;
		free(B);
	}

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
cmpq $0x0, 0x18(%rdi)
jne 0x6c30
movq %rdi, %rbx
movq 0x10(%rdi), %r14
movq 0x28(%r14), %rsi
callq 0x6c7d
testl %eax, %eax
je 0x6ae0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%r14), %rax
testb $0x40, 0x1c(%rax)
jne 0x6bfa
movq 0x10(%rbx), %r14
movq 0x28(%r14), %r15
testb $0x3, 0x1c(%r15)
jne 0x6bd4
leaq 0x1c(%r15), %r12
cmpq $0x0, 0x38(%r15)
jne 0x6bd4
movq 0x48(%r15), %rax
movq (%rax), %rax
movq %rax, 0x28(%r14)
orb $0x10, 0x1c(%rax)
movq 0x28(%r14), %rsi
movl $0xffffffff, 0x18(%rsi) # imm = 0xFFFFFFFF
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x6b4e
callq 0x1070f
movq 0x28(%r14), %rsi
movq $0x0, 0x28(%rsi)
andb $-0x11, (%r12)
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x6c11
decq %rcx
movq %rcx, (%rax)
jne 0x6b83
movq %r15, %rsi
callq 0x107ea
movq 0x48(%r15), %rax
movq $0x0, (%rax)
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x6c11
decq %rcx
movq %rcx, (%rax)
jne 0x6bb2
movq %r15, %rsi
callq 0x107ea
movq %r14, %rdi
movq %r15, %rsi
callq 0x8d62
decq 0x48(%r14)
movq 0x28(%r14), %r15
leaq 0x1c(%r15), %r12
testb $0x3, 0x1c(%r15)
je 0x6b05
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xb910
testq %rax, %rax
je 0x6ad0
movq %rbx, %rdi
callq 0x2040
jmp 0x6ad5
movq %rbx, %rdi
callq 0x6591
testl %eax, %eax
jne 0x6ad0
xorl %ebp, %ebp
jmp 0x6ad5
leaq 0xda38(%rip), %rdi      # 0x14650
leaq 0xda57(%rip), %rsi      # 0x14676
leaq 0xda69(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xdeea(%rip), %rdi      # 0x14b21
leaq 0xdde7(%rip), %rsi      # 0x14a25
leaq 0xdef0(%rip), %rcx      # 0x14b35
movl $0x27e, %edx            # imm = 0x27E
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: btree_cleaning_start
struct cleaner *
btree_cleaning_start(struct btree * T, double Scost)
{
	struct cleaner * C;

	(void)Scost;

	/* Create a cleaner state structure. */
	if ((C = malloc(sizeof(struct cleaner))) == NULL)
		goto err0;
	C->T = T;
	C->group_pending = 0;
	C->head = NULL;
	C->pending_cleans = 0;

	/**
	 * The optimal rate of cleaning is when the cost accrued to store
	 * garbage (inaccessible pages) is equal to the cost accrued to
	 * cleaning (both deliberate and the cleaning which occurs as a side
	 * effect of modifying operations).
	 *
	 * Based on the page size, the ratio of storage cost to I/O cost, and
	 * conversion factors, we can compute a factor which tells us how
	 * many I/Os we should perform per second per block of garbage.
	 */
	C->cleanrate =
	    ((double)T->pagelen / 1000000000.) *	/* GB per page. */
	    (1.0 / 86400. / 30.) *			/* months per s. */
	    Scost *				/* 10^6 I/Os per GB-month. */
	    1000000.;				/* I/Os per (10^6 I/Os). */

	/**
	 * Every second we will look at how much garbage we have and increase
	 * our "cleaning debt"; when this value gets too large, we'll make a
	 * "payment" on the debt by performing some cleaning.
	 */
	C->cleandebt = 0;
	if ((C->cleantimer =
	    events_timer_register(tick, C, &onesec)) == NULL) {
		warnp("events_timer_register");
		goto err1;
	}

	/* Success! */
	return (C);

err1:
	free(C);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movsd %xmm0, (%rsp)
movq %rdi, %r14
movl $0x38, %edi
callq 0x22a0
testq %rax, %rax
je 0x6f78
movq %rax, %rbx
movq %r14, (%rax)
movl $0x0, 0x20(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rax)
movsd (%r14), %xmm0
unpcklps 0xdc6f(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xdc77(%rip), %xmm0     # 0x14b60
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0xdc83(%rip), %xmm1     # 0x14b80
mulsd 0xdc83(%rip), %xmm1     # 0x14b88
mulsd (%rsp), %xmm1
mulsd 0xd4b6(%rip), %xmm1     # 0x143c8
movsd %xmm1, 0x8(%rax)
movq $0x0, 0x10(%rax)
leaq 0x5f(%rip), %rdi        # 0x6f85
leaq 0xdc63(%rip), %rdx      # 0x14b90
movq %rax, %rsi
callq 0xc618
movq %rax, 0x18(%rbx)
testq %rax, %rax
jne 0x6f7a
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6f62
movq %rax, %r14
leaq 0xd49e(%rip), %rdi      # 0x143f0
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%r14)
jmp 0x6f70
leaq 0xd487(%rip), %rdi      # 0x143f0
xorl %eax, %eax
callq 0x100ef
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: btree_cleaning_notify_dirtying
void
btree_cleaning_notify_dirtying(struct cleaner * C, struct node * N)
{
	struct btree * T = C->T;

	/*
	 * Adjust our "cleaning debt" based on this page.  We count a page
	 * which is x% of the maximum age as being x% of a page-cleaning;
	 * this is based on the arbitrary assumption that recently modified
	 * pages are somewhat more likely to be modified again, but not
	 * dramatically so.
	 */
	C->cleandebt -= (double)(T->nextblk - N->pagenum) / (double)(T->npages);

	/*
	 * If this node is waiting to be dirtied by the cleaner, remove it
	 * from the queue.
	 */
	if ((N->type == NODE_TYPE_LEAF) && (N->state == NODE_STATE_CLEAN) &&
	    (N->v.cstate != NULL)) {
		/* Remove the node from the cleaning group. */
		free_cstate(N->v.cstate);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq (%rdi), %rax
movq 0x10(%rax), %rcx
subq (%rsi), %rcx
movq %rcx, %xmm0
movq 0xda9e(%rip), %xmm1     # 0x14b50
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xdaa2(%rip), %xmm2     # 0x14b60
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq 0x50(%rax), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movsd 0x10(%rdi), %xmm0
subsd %xmm3, %xmm0
movsd %xmm0, 0x10(%rdi)
movb 0x1c(%rsi), %al
andb $0xf, %al
cmpb $0x1, %al
jne 0x71a5
movq 0x48(%rsi), %rbx
testq %rbx, %rbx
je 0x71a5
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
leaq 0x8(%r14), %r15
leaq 0x10(%rcx), %rdx
testq %rcx, %rcx
cmoveq %r15, %rdx
movq %rax, (%rdx)
testq %rax, %rax
je 0x713a
movq %rcx, 0x18(%rax)
movq (%rbx), %rax
movq $0x0, 0x48(%rax)
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
testq %rsi, %rsi
je 0x717c
movq (%rax), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %rdi
movq 0x20(%rdi), %rcx
movq (%rsi,%rcx), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x71ab
decq %rdx
movq %rdx, (%rcx)
jne 0x717c
callq 0x107ea
movq 0x8(%rbx), %rax
movq (%rax), %rax
decq 0x30(%rax)
cmpq $0x0, (%r15)
jne 0x7198
cmpq $0x0, 0x20(%r14)
jne 0x7198
movq %r14, %rdi
callq 0x7609
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x2040
popq %rbx
popq %r14
popq %r15
retq
leaq 0xd49e(%rip), %rdi      # 0x14650
leaq 0xd4bd(%rip), %rsi      # 0x14676
leaq 0xd4cf(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: btree_cleaning_clean
int
btree_cleaning_clean(struct cleaner * C)
{
	struct cleaning_group * G;
	struct cleaning_group * Gnext;
	struct cleaning * CC;
	struct cleaning * CCnext;

	/* Scan through the list of groups. */
	for (G = C->head; G != NULL; G = Gnext) {
		/* Record the next group, since G will be freed. */
		Gnext = G->next;

		/* Is this group ready for cleaning? */
		if (G->pending_fetches != 0)
			continue;

		/* Scan through the list of cleaning structures. */
		for (CC = G->head; CC != NULL; CC = CCnext) {
			/* Record the next struct, since CC will be freed. */
			CCnext = CC->next;

			/* Dirty the node. */
			if (btree_node_dirty(C->T, CC->N) == 0)
				goto err0;
		}
	}

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq 0x28(%rdi), %rax
xorl %ebx, %ebx
testq %rax, %rax
je 0x7237
movq %rdi, %r14
movq 0x10(%rax), %r15
cmpq $0x0, 0x20(%rax)
je 0x7213
movq %r15, %rax
testq %r15, %r15
jne 0x71fe
jmp 0x7237
movq 0x8(%rax), %r12
testq %r12, %r12
je 0x7209
movq (%r12), %rsi
movq 0x10(%r12), %r12
movq (%r14), %rdi
callq 0x8f61
testq %rax, %rax
jne 0x7217
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: btree_cleaning_stop
void
btree_cleaning_stop(struct cleaner * C)
{

	/* Stop the timer if it is running. */
	if (C->cleantimer != NULL) {
		events_timer_cancel(C->cleantimer);
		C->cleantimer = NULL;
	}

	/* Loop until we have no cleaning pending. */
	do {
		/* If we have nodes ready to be dirtied, dirty them. */
		if (btree_cleaning_clean(C)) {
			warnp("Failure dirtying nodes in cleaner");
			exit(1);
		}

		/* Do we have any cleaning groups left? */
		if ((C->group_pending == 0) && (C->pending_cleans == 0))
			break;

		/* Run any available events. */
		if (events_run()) {
			warnp("Error running event loop");
			exit(1);
		}
	} while (1);

	/* We should have no cleaning groups. */
	assert(C->head == NULL);

	/* Free the cleaner state structure. */
	free(C);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0x725f
callq 0xc792
movq $0x0, 0x18(%rbx)
movq %rbx, %rdi
callq 0x71e8
testl %eax, %eax
jne 0x72a4
cmpl $0x0, 0x20(%rbx)
jne 0x7278
cmpq $0x0, 0x30(%rbx)
je 0x7294
callq 0xb638
testl %eax, %eax
je 0x725f
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x72ca
leaq 0xd008(%rip), %rdi      # 0x1429a
jmp 0x72b5
cmpq $0x0, 0x28(%rbx)
jne 0x72eb
movq %rbx, %rdi
popq %rbx
jmp 0x2040
callq 0x20a0
cmpl $0x0, (%rax)
jne 0x72be
leaq 0xd8eb(%rip), %rdi      # 0x14ba0
xorl %eax, %eax
callq 0x100ef
jmp 0x72e1
movq %rax, %rbx
leaq 0xd8d8(%rip), %rdi      # 0x14ba0
jmp 0x72d4
movq %rax, %rbx
leaq 0xcfc6(%rip), %rdi      # 0x1429a
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%rbx)
movl $0x1, %edi
callq 0x2370
leaq 0xd8d0(%rip), %rdi      # 0x14bc2
leaq 0xd8d9(%rip), %rsi      # 0x14bd2
leaq 0xd8e3(%rip), %rcx      # 0x14be3
movl $0x253, %edx            # imm = 0x253
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: free_cg
static void
free_cg(struct cleaning_group * CG)
{
	struct cleaner * C = CG->C;

	/* Sanity-check: The group must have no nodes. */
	assert(CG->head == NULL);
	assert(CG->pending_fetches == 0);

	/* Remove from the list of groups. */
	if (CG->prev != NULL)
		CG->prev->next = CG->next;
	else
		C->head = CG->next;
	if (CG->next != NULL)
		CG->next->prev = CG->prev;

	/* Free the group. */
	free(CG);
}

// Assembly:
pushq %rax
cmpq $0x0, 0x8(%rdi)
jne 0x7644
cmpq $0x0, 0x20(%rdi)
jne 0x7663
movq (%rdi), %rdx
movq 0x10(%rdi), %rax
movq 0x18(%rdi), %rcx
addq $0x28, %rdx
leaq 0x10(%rcx), %rsi
testq %rcx, %rcx
cmoveq %rdx, %rsi
movq %rax, (%rsi)
testq %rax, %rax
je 0x763e
movq %rcx, 0x18(%rax)
popq %rax
jmp 0x2040
leaq 0xd638(%rip), %rdi      # 0x14c83
leaq 0xd580(%rip), %rsi      # 0x14bd2
leaq 0xd63b(%rip), %rcx      # 0x14c94
movl $0x4d, %edx
callq 0x21c0
leaq 0xd650(%rip), %rdi      # 0x14cba
leaq 0xd561(%rip), %rsi      # 0x14bd2
leaq 0xd61c(%rip), %rcx      # 0x14c94
movl $0x4e, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: callback_clean
static int
callback_clean(void * cookie, struct node * N)
{
	struct cleaning_group * CG = cookie;
	struct cleaning * C;

	/* This must be a leaf node. */
	assert(N->type == NODE_TYPE_LEAF);

	/* We're not fetching this node any more. */
	CG->pending_fetches--;

	/* If this node is not CLEAN, we don't need to clean it any more. */
	if (N->state != NODE_STATE_CLEAN) {
		CG->C->pending_cleans--;
		btree_node_unlock(CG->C->T, N);
		goto done;
	}

	/* Bake a cookie. */
	if ((C = malloc(sizeof(struct cleaning))) == NULL)
		goto err1;
	C->N = N;
	C->G = CG;

	/* Hook this node into the group. */
	C->next = CG->head;
	C->prev = NULL;
	CG->head = C;
	if (C->next != NULL)
		C->next->prev = C;

	/* Mark this node as pending cleaning. */
	N->v.cstate = C;

done:
	/* Success! */
	return (0);

err1:
	btree_node_unlock(CG->C->T, N);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movb 0x1c(%rsi), %al
andb $0x3, %al
cmpb $0x1, %al
jne 0x773a
movq %rsi, %rbx
movq %rdi, %r14
decq 0x20(%rdi)
testb $0xc, 0x1c(%rsi)
je 0x76d9
movq (%r14), %rax
decq 0x30(%rax)
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7759
xorl %ebp, %ebp
decq %rcx
movq %rcx, (%rax)
jne 0x7712
movq %rbx, %rsi
callq 0x107ea
jmp 0x7712
movl $0x20, %edi
callq 0x22a0
testq %rax, %rax
je 0x7719
movq %rbx, (%rax)
movq %r14, 0x8(%rax)
movq 0x8(%r14), %rcx
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x8(%r14)
testq %rcx, %rcx
je 0x770c
movq %rax, 0x18(%rcx)
movq %rax, 0x48(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
movq (%r14), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7759
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x76c7
leaq 0xd592(%rip), %rdi      # 0x14cd3
leaq 0xd48a(%rip), %rsi      # 0x14bd2
leaq 0xd59e(%rip), %rcx      # 0x14ced
movl $0x83, %edx
callq 0x21c0
leaq 0xcef0(%rip), %rdi      # 0x14650
leaq 0xcf0f(%rip), %rsi      # 0x14676
leaq 0xcf21(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: recompute_oncl
static void
recompute_oncl(struct node * N)
{
	size_t i;

	/* If we've gone past the top of the tree, do nothing. */
	if (N == NULL)
		return;

	/* Find the lowest value. */
	N->oldestncleaf = (uint64_t)(-1);
	for (i = 0; i <= N->nkeys; i++) {
		if (N->v.children[i]->oldestncleaf < N->oldestncleaf)
			N->oldestncleaf = N->v.children[i]->oldestncleaf;
	}

	/* Move up the tree. */
	recompute_oncl(N->p_shadow);
}

// Assembly:
testq %rdi, %rdi
je 0x77c4
movq $-0x1, 0x10(%rdi)
movq 0x38(%rdi), %rax
movq 0x48(%rdi), %rcx
leaq 0x1(%rax), %rdx
cmpq $0x1, %rdx
adcq $0x1, %rax
movq $-0x1, %rsi
xorl %edx, %edx
movq (%rcx,%rdx,8), %r8
movq 0x10(%r8), %r8
cmpq %rsi, %r8
jae 0x77b6
movq %r8, 0x10(%rdi)
movq %r8, %rsi
incq %rdx
cmpq %rdx, %rax
jne 0x77a2
movq 0x20(%rdi), %rdi
jmp 0x7778
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_mlen.c
// Function: mlen_traverse
static void
mlen_traverse(struct node * N, const struct kvldskey * start,
    const struct kvldskey * end)
{
	size_t i;

	/* If this node is not dirty, we have nothing to do. */
	if (N->state != NODE_STATE_DIRTY)
		return;

	/* If this node has children, recurse down. */
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++)
			mlen_traverse(N->v.children[i],
			    (i == 0) ? start : N->u.keys[i - 1],
			    (i < N->nkeys) ? N->u.keys[i] : end);
	}

	/* Store the matching prefix length for this node. */
	if ((start == NULL) || (end == NULL))
		N->mlen_t = 0;
	else
		N->mlen_t = (uint8_t)kvldskey_mlen(start, end);
}

// Assembly:
movb 0x1c(%rdi), %al
movl %eax, %ecx
andb $0xc, %cl
cmpb $0x8, %cl
jne 0x7866
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
testb $0x3, %al
jne 0x7839
movq 0x38(%rbx), %rax
xorl %r12d, %r12d
movq %r15, %rsi
testq %r12, %r12
je 0x7810
movq 0x40(%rbx), %rcx
movq -0x8(%rcx,%r12,8), %rsi
movq %r14, %rdx
cmpq %rax, %r12
jae 0x7820
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %rdx
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x77d2
incq %r12
movq 0x38(%rbx), %rax
cmpq %rax, %r12
jbe 0x77ff
testq %r15, %r15
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
je 0x784d
xorl %eax, %eax
jmp 0x7858
movq %r15, %rdi
movq %r14, %rsi
callq 0x1032f
movb %al, 0x1e(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: btree_sync
int
btree_sync(struct btree * T, int (* callback)(void *), void * cookie)
{
	struct write_cookie * WC;
	size_t npages;
	const uint8_t ** bufv;
	uint64_t pn = 0;

	/* Bake a cookie. */
	if ((WC = malloc(sizeof(struct write_cookie))) == NULL)
		goto err0;
	WC->T = T;
	WC->callback = callback;
	WC->cookie = cookie;

	/* Figure out how many pages we need to write. */
	npages = ndirty(T->root_dirty);

	/* Allocate a vector to hold pointers to pages. */
	if (IMALLOC(bufv, npages, const uint8_t *))
		goto err1;

	/* Serialize pages and record pointers into the vector. */
	if (serializetree(T, T->root_dirty, T->pagelen, T->nextblk,
	    bufv, &pn))
		goto err2;

	/* Sanity check the number of pages serialized. */
	assert(pn == npages);
	assert(npages <= UINT32_MAX);

	/* Write pages out. */
	if (proto_lbs_request_append_blks(T->LBS, (uint32_t)npages, T->nextblk,
	    T->pagelen, bufv, callback_append, WC)) {
		warnp("Error writing pages");
		goto err2;
	}

	/* Free the page pointers vector. */
	free(bufv);

	/* Success! */
	return (0);

err2:
	free(bufv);
err1:
	free(WC);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
movq $0x0, 0x10(%rsp)
movl $0x18, %edi
callq 0x22a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x7923
movq %rax, %r14
movq %r12, 0x10(%rax)
movq %r13, (%rax)
movq %r15, 0x8(%rax)
movq 0x28(%r12), %rbp
movq %rbp, %rdi
callq 0x79f8
movq %rax, %r13
testq %rax, %rax
je 0x78d9
movq %r13, %rax
shrq $0x3d, %rax
je 0x78de
callq 0x20a0
movl $0xc, (%rax)
jmp 0x791b
xorl %r15d, %r15d
jmp 0x78f3
leaq (,%r13,8), %rdi
callq 0x22a0
movq %rax, %r15
testq %rax, %rax
je 0x791b
movq (%r12), %rdx
movq 0x10(%r12), %rcx
leaq 0x10(%rsp), %r9
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %r8
callq 0x7a48
testl %eax, %eax
je 0x7934
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq %r13, 0x10(%rsp)
jne 0x79ba
movq %r13, %rax
shrq $0x20, %rax
jne 0x79d9
movq 0x18(%r12), %rdi
movq (%r12), %rcx
movq 0x10(%r12), %rdx
movq %r14, (%rsp)
leaq 0x1d9(%rip), %r9        # 0x7b3a
movl %r13d, %esi
movq %r15, %r8
callq 0x113fe
testl %eax, %eax
je 0x7998
callq 0x20a0
cmpl $0x0, (%rax)
je 0x79a7
movq %rax, %r12
leaq 0xd3fa(%rip), %rdi      # 0x14d7e
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%r12)
jmp 0x7913
movq %r15, %rdi
callq 0x2040
xorl %ebx, %ebx
jmp 0x7923
leaq 0xd3d0(%rip), %rdi      # 0x14d7e
xorl %eax, %eax
callq 0x100ef
jmp 0x7913
leaq 0xd356(%rip), %rdi      # 0x14d17
leaq 0xd35c(%rip), %rsi      # 0x14d24
leaq 0xd362(%rip), %rcx      # 0x14d31
movl $0xe1, %edx
callq 0x21c0
leaq 0xd389(%rip), %rdi      # 0x14d69
leaq 0xd33d(%rip), %rsi      # 0x14d24
leaq 0xd343(%rip), %rcx      # 0x14d31
movl $0xe2, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: ndirty
static size_t
ndirty(struct node * N)
{
	size_t n, i;

	/* If this node is not dirty, there are no dirty nodes. */
	if (N->state != NODE_STATE_DIRTY)
		return (0);

	/* If this node is not a parent, it is the only dirty node. */
	if (N->type != NODE_TYPE_PARENT)
		return (1);

	/* Otherwise, we have 1 + the sum of children. */
	for (n = 1, i = 0; i <= N->nkeys; i++)
		n += ndirty(N->v.children[i]);
	return (n);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movb 0x1c(%rdi), %al
movl %eax, %ecx
andb $0xc, %cl
cmpb $0x8, %cl
jne 0x7a37
movl $0x1, %ebx
testb $0x3, %al
jne 0x7a39
movq 0x38(%rdi), %r14
movq 0x48(%rdi), %r15
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x79f8
addq %rax, %rbx
incq %r12
cmpq %r14, %r12
jbe 0x7a21
jmp 0x7a39
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: serializetree
static int
serializetree(struct btree * T, struct node * N, size_t pagelen,
    uint64_t nextblk, const uint8_t ** bufv, uint64_t * pn)
{
	size_t i;

	/* If this node is not dirty, return immediately. */
	if (N->state != NODE_STATE_DIRTY)
		return (0);

	/* If this node has children, serialize them first. */
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++)
			if (serializetree(T, N->v.children[i], pagelen,
			    nextblk, bufv, pn))
				goto err0;
	}

	/* Record this node's page number. */
	N->pagenum = nextblk + *pn;

	/*
	 * Figure out what the oldest leaf number under this node is.  The
	 * oldest not-being-cleaned leaf is computed in makeclean.
	 */
	N->oldestleaf = N->pagenum;
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++) {
			if (N->v.children[i]->oldestleaf < N->oldestleaf)
				N->oldestleaf = N->v.children[i]->oldestleaf;
		}
	}

	/* Serialize the page and record the page pointer. */
	if (serialize(T, N, pagelen))
		goto err0;
	bufv[(*pn)++] = N->pagebuf;

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, (%rsp)
movq %rcx, %rbp
movq %rdx, %r12
movb 0x1c(%rsi), %cl
movl %ecx, %edx
andb $0xc, %dl
xorl %eax, %eax
cmpb $0x8, %dl
jne 0x7b2b
movq %r9, %r14
movq %rsi, %r15
movq %rdi, %r13
testb $0x3, %cl
jne 0x7ab2
xorl %ebx, %ebx
movq 0x48(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r13, %rdi
movq %r12, %rdx
movq %rbp, %rcx
movq (%rsp), %r8
movq %r14, %r9
callq 0x7a48
testl %eax, %eax
jne 0x7b26
incq %rbx
cmpq 0x38(%r15), %rbx
jbe 0x7a80
movb 0x1c(%r15), %cl
addq (%r14), %rbp
movq %rbp, (%r15)
movq %rbp, 0x8(%r15)
testb $0x3, %cl
jne 0x7af3
movq 0x38(%r15), %rax
movq 0x48(%r15), %rcx
leaq 0x1(%rax), %rdx
cmpq $0x1, %rdx
adcq $0x1, %rax
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movq 0x8(%rsi), %rsi
cmpq %rbp, %rsi
jae 0x7aeb
movq %rsi, 0x8(%r15)
movq %rsi, %rbp
incq %rdx
cmpq %rdx, %rax
jne 0x7ad7
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xa2ec
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x7b2b
movq 0x50(%r15), %rax
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq (%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
xorl %eax, %eax
jmp 0x7b2b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: callback_append
static int
callback_append(void * cookie, int failed, int status, uint64_t blkno)
{
	struct write_cookie * WC = cookie;
	struct btree * T = WC->T;

	/* Throw a fit if we didn't manage to write the pages. */
	if (failed) {
		warnp("LBS APPEND request failed");
		goto err1;
	}
	if (status) {
		warn0("Failed to write dirty nodes to backing store");
		goto err1;
	}

	/* Record the next available block number. */
	T->nextblk = blkno;

	/* Mark the nodes in the dirty tree as clean. */
	makeclean(T, T->root_dirty);

	/*
	 * Make sure no callbacks are pending on the shadow tree before we
	 * garbage collect it.
	 */
	if (!events_immediate_register(callback_unshadow, WC, 1))
		goto err1;

	/* Success! */
	return (0);

err1:
	free(WC);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl %esi, %esi
je 0x7b69
callq 0x20a0
cmpl $0x0, (%rax)
je 0x7b88
movq %rax, %r14
leaq 0xd239(%rip), %rdi      # 0x14d92
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%r14)
jmp 0x7b96
testl %edx, %edx
je 0x7bab
leaq 0xd238(%rip), %rdi      # 0x14dac
xorl %eax, %eax
callq 0x100ef
callq 0x20a0
movl $0x0, (%rax)
jmp 0x7b96
leaq 0xd203(%rip), %rdi      # 0x14d92
xorl %eax, %eax
callq 0x100ef
movq %rbx, %rdi
callq 0x2040
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x10(%rbx), %rdi
movq %rcx, 0x10(%rdi)
movq 0x28(%rdi), %rsi
callq 0x7bdc
leaq 0x13e(%rip), %rdi       # 0x7d01
movq %rbx, %rsi
movl $0x1, %edx
callq 0xb910
movq %rax, %rcx
xorl %eax, %eax
testq %rcx, %rcx
jne 0x7ba3
jmp 0x7b96
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: makeclean
static void
makeclean(struct btree * T, struct node * N)
{
	size_t i;

	/* Sanity-check: We should not have reached a shadow node. */
	assert(N->state != NODE_STATE_SHADOW);

	/* If this node is not dirty, return immediately. */
	if (N->state != NODE_STATE_DIRTY)
		return;

	/* If this node has children, recurse down. */
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++)
			makeclean(T, N->v.children[i]);
	}

	/*
	 * Figure out what the page number of the oldest leaf under this node
	 * which isn't currently being cleaned is.  (We computed the overall
	 * oldest leaf during serializetree since it gets written out.)
	 */
	N->oldestncleaf = N->pagenum;
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++) {
			if (N->v.children[i]->oldestncleaf < N->oldestncleaf)
				N->oldestncleaf =
				    N->v.children[i]->oldestncleaf;
		}
	}

	/* Mark this node as clean. */
	N->state = NODE_STATE_CLEAN;

	/* Remove the node-is-dirty lock on the node. */
	btree_node_unlock(T, N);

	/* This node's dirty parent is also its shadow parent. */
	N->p_shadow = N->p_dirty;
	btree_node_lock(T, N->p_shadow);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl 0x1c(%rsi), %eax
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x3, %ecx
cmpl $0x2, %ecx
je 0x7c19
cmpl $0x1, %ecx
jne 0x7cd2
leaq 0xd1d8(%rip), %rdi      # 0x14dd9
leaq 0xd11c(%rip), %rsi      # 0x14d24
leaq 0xd1e8(%rip), %rcx      # 0x14df7
movl $0x68, %edx
callq 0x21c0
movq %rsi, %r14
movq %rdi, %rbx
testb $0x3, %al
jne 0x7c43
xorl %r15d, %r15d
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
callq 0x7bdc
incq %r15
cmpq 0x38(%r14), %r15
jbe 0x7c26
movb 0x1c(%r14), %al
movq (%r14), %rcx
movq %rcx, 0x10(%r14)
testb $0x3, %al
jne 0x7c80
movq 0x38(%r14), %rdx
movq 0x48(%r14), %rsi
leaq 0x1(%rdx), %rdi
cmpq $0x1, %rdi
adcq $0x1, %rdx
xorl %edi, %edi
movq (%rsi,%rdi,8), %r8
movq 0x10(%r8), %r8
cmpq %rcx, %r8
jae 0x7c78
movq %r8, 0x10(%r14)
movq %r8, %rcx
incq %rdi
cmpq %rdi, %rdx
jne 0x7c64
andb $-0xd, %al
movb %al, 0x1c(%r14)
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7ce2
decq %rcx
movq %rcx, (%rax)
jne 0x7caa
movq %r14, %rsi
callq 0x107ea
movq 0x28(%r14), %rsi
movq %rsi, 0x20(%r14)
testq %rsi, %rsi
je 0x7cd2
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
je 0x7cd8
popq %rbx
popq %r14
popq %r15
retq
popq %rbx
popq %r14
popq %r15
jmp 0x1070f
leaq 0xc967(%rip), %rdi      # 0x14650
leaq 0xc986(%rip), %rsi      # 0x14676
leaq 0xc998(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: callback_unshadow
static int
callback_unshadow(void * cookie)
{
	struct write_cookie * WC = cookie;
	struct btree * T = WC->T;
	struct node * root_shadow;

	/*
	 * Grab the root of the shadow tree, and use the (now clean) dirty
	 * tree as the shadow tree henceforth.
	 */
	root_shadow = T->root_shadow;
	T->root_shadow = T->root_dirty;
	btree_node_lock(T, T->root_shadow);

	/* Kill the old shadow tree, if there was one. */
	if (root_shadow != NULL) {
		/* This isn't a root any more, so release the root lock. */
		btree_node_unlock(T, root_shadow);

		/*
		 * Traverse the tree, re-pointing clean children at their
		 * dirty parents and freeing shadow nodes.
		 */
		unshadow(T, root_shadow);
	}

	/* Update number-of-pages-used value. */
	T->npages = T->nextblk - T->root_dirty->oldestleaf;

	/*
	 * We could issue a FREE call here, but since FREE is only advisory
	 * we need to call it elsewhere as well in order to avoid having data
	 * permanently stored even when it could all be freed.  Since we're
	 * calling FREE elsewhere anyway, don't bother calling it here.
	 */

	/* Register post-sync callback to be performed. */
	if (!events_immediate_register(WC->callback, WC->cookie, 0))
		goto err1;

	/* Free cookie. */
	free(WC);

	/* Success! */
	return (0);

err1:
	free(WC);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %r14
movq 0x20(%r14), %r15
movq 0x28(%r14), %rsi
movq %rsi, 0x20(%r14)
testq %rsi, %rsi
je 0x7d40
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x7d40
callq 0x1070f
testq %r15, %r15
je 0x7d74
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%r15,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7db2
decq %rcx
movq %rcx, (%rax)
jne 0x7d69
movq %r15, %rsi
callq 0x107ea
movq %r14, %rdi
movq %r15, %rsi
callq 0x7dd1
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
subq 0x8(%rcx), %rax
movq %rax, 0x50(%r14)
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xb910
movq %rax, %r14
movq %rbx, %rdi
callq 0x2040
cmpq $0x1, %r14
sbbl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc897(%rip), %rdi      # 0x14650
leaq 0xc8b6(%rip), %rsi      # 0x14676
leaq 0xc8c8(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: unshadow
static void
unshadow(struct btree * T, struct node * N)
{
	size_t i;

#ifdef SANITY_CHECKS
	/* Sanity check the B+Tree. */
	btree_sanity(T);
#endif

	/* Sanity-check: We should not have reached a dirty node. */
	assert(N->state != NODE_STATE_DIRTY);

	/* If this node is clean, reparent it and return. */
	if (N->state == NODE_STATE_CLEAN) {
		/* Do we need to release a lock on our shadow parent? */
		if (node_hasplock(N))
			btree_node_unlock(T, N->p_shadow);

		/* Our dirty parent is our only parent. */
		N->p_shadow = N->p_dirty;

		/* Acquire a lock on our new shadow parent. */
		if (node_hasplock(N))
			btree_node_lock(T, N->p_shadow);

		/* We're done. */
		return;
	}

	/* If this node has children, recurse down. */
	if (N->type == NODE_TYPE_PARENT) {
		for (i = 0; i <= N->nkeys; i++) {
			/* Recurse down. */
			unshadow(T, N->v.children[i]);

			/* Clear the child pointer. */
			N->v.children[i] = NULL;
		}
	}

#ifdef SANITY_CHECKS
	/* Sanity check the B+Tree. */
	btree_sanity(T);
#endif

	/* Destroy this node. */
	btree_node_destroy(T, N);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movl 0x1c(%rsi), %eax
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x3, %ecx
je 0x7e2e
cmpl $0x2, %ecx
je 0x7ea6
testb $0x3, %al
jne 0x7e1e
xorl %r15d, %r15d
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
callq 0x7dd1
movq 0x48(%r14), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
cmpq 0x38(%r14), %r15
jbe 0x7df9
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0x8d62
andb $0x3, %al
cmpb $0x2, %al
je 0x7e5e
movq 0x20(%r14), %rsi
testq %rsi, %rsi
je 0x7e5e
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x7ec5
decq %rcx
movq %rcx, (%rax)
jne 0x7e5e
callq 0x107ea
movq 0x28(%r14), %rsi
movq %rsi, 0x20(%r14)
movb 0x1c(%r14), %al
andb $0x3, %al
cmpb $0x2, %al
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x7e96
movq 0x30(%rbx), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
je 0x7e9c
popq %rbx
popq %r14
popq %r15
retq
popq %rbx
popq %r14
popq %r15
jmp 0x1070f
leaq 0xcf78(%rip), %rdi      # 0x14e25
leaq 0xce70(%rip), %rsi      # 0x14d24
leaq 0xcf87(%rip), %rcx      # 0x14e42
movl $0x99, %edx
callq 0x21c0
leaq 0xc784(%rip), %rdi      # 0x14650
leaq 0xc7a3(%rip), %rsi      # 0x14676
leaq 0xc7b5(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_find.c
// Function: btree_find_kvpair
struct kvpair_const *
btree_find_kvpair(struct node * N, const struct kvldskey * k)
{
	size_t min, max, mid;
	int rc;

	/* We must be in a leaf node. */
	assert(N->type == NODE_TYPE_LEAF);

	/*
	 * This key could be anywhere from position 0 (less than key #0) up
	 * to position N->nkeys (greater than key #(nkeys - 1)).
	 */
	min = 0;
	max = N->nkeys;

	/* Keep looking until we figure out where it belongs. */
	while (min != max) {
		/* Compare to the midpoint. */
		mid = min + (max - min) / 2;
		rc = kvldskey_cmp2(k, N->u.pairs[mid].k, N->mlen_t);

		/* Adjust endpoints. */
		if (rc < 0) {
			/* The key is less than key #mid. */
			max = mid;
		} else if (rc > 0) {
			/* The key is greater than key #mid. */
			min = mid + 1;
		} else {
			/* Found it! */
			return (&N->u.pairs[mid]);
		}
	}

	/* We didn't find it. */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movb 0x1c(%rdi), %al
andb $0x3, %al
cmpb $0x1, %al
jne 0x7f62
movq %rdi, %rbx
movq 0x38(%rdi), %r12
testq %r12, %r12
je 0x7f47
movq %rsi, %r14
xorl %r13d, %r13d
movq %r12, %rbp
subq %r13, %rbp
shrq %rbp
addq %r13, %rbp
movq 0x40(%rbx), %rax
movq %rbp, %r15
shlq $0x4, %r15
movq (%rax,%r15), %rsi
movzbl 0x1e(%rbx), %edx
movq %r14, %rdi
callq 0x102fb
testl %eax, %eax
js 0x7f3f
je 0x7f4c
incq %rbp
movq %rbp, %r13
jmp 0x7f42
movq %rbp, %r12
cmpq %r12, %r13
jne 0x7f0a
xorl %r15d, %r15d
jmp 0x7f50
addq 0x40(%rbx), %r15
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcd6a(%rip), %rdi      # 0x14cd3
leaq 0xceff(%rip), %rsi      # 0x14e6f
leaq 0xcf05(%rip), %rcx      # 0x14e7c
movl $0x29, %edx
callq 0x21c0
// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_find.c
// Function: btree_find_child
size_t
btree_find_child(struct node * N, const struct kvldskey * k)
{
	size_t min, max, mid;
	int rc;

	/* We must be in a parent node. */
	assert(N->type == NODE_TYPE_PARENT);

	/* This key could belong anywhere from child 0 up to N->nkeys. */
	min = 0;
	max = N->nkeys;

	/* Keep looking until we figure out where it belongs. */
	while (min != max) {
		/* Compare to the midpoint. */
		mid = min + (max - min) / 2;
		rc = kvldskey_cmp2(k, N->u.keys[mid], N->mlen_t);

		/* Adjust endpoints. */
		if (rc < 0) {
			/* The key is less than key #mid. */
			max = mid;
		} else if (rc > 0) {
			/* The key is greater than or equal to key #mid. */
			min = mid + 1;
		} else {
			/* Found it! */
			return (mid + 1);
		}
	}

	/* This must be it. */
	return (min);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testb $0x3, 0x1c(%rdi)
jne 0x7ff0
movq %rdi, %r14
movq 0x38(%rdi), %r12
testq %r12, %r12
je 0x7fe0
movq %rsi, %rbx
xorl %r13d, %r13d
movq %r12, %r15
subq %r13, %r15
shrq %r15
addq %r13, %r15
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rsi
movzbl 0x1e(%r14), %edx
movq %rbx, %rdi
callq 0x102fb
testl %eax, %eax
js 0x7fd3
incq %r15
movq %r15, %r13
testl %eax, %eax
jne 0x7fd6
jmp 0x7fe3
movq %r15, %r12
movq %r12, %r15
cmpq %r12, %r13
jne 0x7fa2
jmp 0x7fe3
xorl %r15d, %r15d
movq %r15, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xced4(%rip), %rdi      # 0x14ecb
leaq 0xce71(%rip), %rsi      # 0x14e6f
leaq 0xcee2(%rip), %rcx      # 0x14ee7
movl $0x55, %edx
callq 0x21c0