// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/kvlds/btree_node.c
// Function: callback_fetch
static int
callback_fetch(void * cookie, int failed, int status, const uint8_t * buf)
{
	struct node * N = cookie;
	struct reading * R = N->u.reading;
	struct reader * r;
	size_t i;

	/* Throw a fit if the read request failed. */
	if (failed) {
		warnp("LBS GET request failed");
		goto err2;
	}

	/* Throw a fit if the block does not exist and we can't fail. */
	if ((status != 0) && (R->canfail == 0)) {
		warn0("Failed to read a mandatory page");
		goto err2;
	}

	/* If the block exists, parse it. */
	if (status == 0) {
		/* Parse the page. */
		if (deserialize(N, buf, R->pagelen)) {
			warn0("Cannot deserialize page");
			goto err2;
		}

		/* If this was a root, parse global tree data. */
		if (N->root) {
			if (deserialize_root(R->T, buf)) {
				warn0("Error parsing root data");
				goto err2;
			}
		}

		/* Release our lock on the page. */
		btree_node_unlock(R->T, N);
	} else {
		/* Otherwise, mark it back as non-present. */
		N->type = NODE_TYPE_NP;

		/* Unlock the node's parents. */
		btree_node_unlock(R->T, N->p_shadow);
		btree_node_unlock(R->T, N->p_dirty);

		/* Release our lock on the page. */
		btree_node_unlock(R->T, N);

		/* Remove from the node pool. */
		pool_rec_free(R->T->P, N);
		N->pool_cookie = NULL;
	}

	/* Schedule callbacks. */
	for (i = 0; i < readerlist_getsize(R->list); i++) {
		/* Get a reader structure. */
		r = readerlist_get(R->list, i);

		/* Schedule a callback. */
		if (!events_immediate_register(r->callback, r->cookie, 0))
			goto err1;
	}

	/* We've finished reading this page. */
	readerlist_free(R->list);
	free(R);

	/* Success! */
	return (0);

err2:
	btree_node_unlock(R->T, N);
err1:
	readerlist_free(R->list);
	free(R);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x40(%rdi), %rbx
testl %esi, %esi
je 0x94ef
callq 0x20a0
cmpl $0x0, (%rax)
je 0x9612
movq %rax, %r15
leaq 0xbde2(%rip), %rdi      # 0x152be
xorl %eax, %eax
callq 0x10048
movl $0x0, (%r15)
jmp 0x965a
testl %edx, %edx
je 0x9622
cmpl $0x0, 0x18(%rbx)
je 0x9641
movb 0x1c(%r14), %al
andb $-0x4, %al
orb $0x2, %al
movb %al, 0x1c(%r14)
movq 0x20(%r14), %rsi
testq %rsi, %rsi
je 0x953f
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9711
decq %rcx
movq %rcx, (%rax)
jne 0x953f
callq 0x10885
movq 0x28(%r14), %rsi
testq %rsi, %rsi
je 0x9571
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9711
decq %rcx
movq %rcx, (%rax)
jne 0x9571
callq 0x10885
testq %r14, %r14
je 0x95a2
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9711
decq %rcx
movq %rcx, (%rax)
jne 0x95a2
movq %r14, %rsi
callq 0x10885
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq %r14, %rsi
callq 0x1080b
movq $0x0, 0x30(%r14)
movq (%rbx), %rdi
movl $0x10, %esi
callq 0xae5f
testq %rax, %rax
je 0x960b
xorl %r14d, %r14d
movq (%rbx), %rdi
movl $0x10, %edx
movq %r14, %rsi
callq 0xafa1
movq (%rax), %rdi
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0xba4c
testq %rax, %rax
je 0x9692
incq %r14
movq (%rbx), %rdi
movl $0x10, %esi
callq 0xae5f
cmpq %rax, %r14
jb 0x95cf
xorl %ebp, %ebp
jmp 0x9697
leaq 0xbca5(%rip), %rdi      # 0x152be
xorl %eax, %eax
callq 0x10167
jmp 0x965a
movq %rcx, %r15
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rcx, %rsi
callq 0xa7c9
testl %eax, %eax
je 0x96b4
leaq 0xbcb6(%rip), %rdi      # 0x152f5
jmp 0x9648
leaq 0xbc8d(%rip), %rdi      # 0x152d5
xorl %eax, %eax
callq 0x10167
callq 0x20a0
movl $0x0, (%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x9697
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9711
decq %rcx
movq %rcx, (%rax)
jne 0x9697
movq %r14, %rsi
callq 0x10885
jmp 0x9697
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rbx), %rdi
callq 0xada1
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, 0x1c(%r14)
je 0x96d7
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0xac53
testl %eax, %eax
je 0x96d7
leaq 0xbc3b(%rip), %rdi      # 0x1530d
jmp 0x9648
testq %r14, %r14
je 0x95ba
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x9711
decq %rcx
movq %rcx, (%rax)
jne 0x95ba
movq %r14, %rsi
callq 0x10885
jmp 0x95ba
leaq 0xaf68(%rip), %rdi      # 0x14680
leaq 0xaf87(%rip), %rsi      # 0x146a6
leaq 0xaf99(%rip), %rcx      # 0x146bf
movl $0x88, %edx
callq 0x21c0