// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x40(%rdi), %rbx
testl %esi, %esi
je 0x7f00
callq 0x20a0
cmpl $0x0, (%rax)
je 0x7f99
movq %rax, %r15
leaq 0xa3a9(%rip), %rdi      # 0x12299
xorl %eax, %eax
callq 0xdf55
andl $0x0, (%r15)
jmp 0x7fde
testl %edx, %edx
je 0x7fa9
cmpl $0x0, 0x18(%rbx)
je 0x7fc8
movb 0x1c(%r14), %al
andb $-0x4, %al
orb $0x2, %al
movb %al, 0x1c(%r14)
movq 0x8(%rbx), %rdi
movq 0x20(%r14), %rsi
callq 0x7dc2
movq 0x8(%rbx), %rdi
movq 0x28(%r14), %rsi
callq 0x7dc2
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x7dc2
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq %r14, %rsi
callq 0xe776
andq $0x0, 0x30(%r14)
xorl %r14d, %r14d
pushq $0x10
popq %r15
xorl %r12d, %r12d
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x94e1
movq (%rbx), %rdi
cmpq %rax, %r12
jae 0x7ff1
movq %r12, %rsi
movq %r15, %rdx
callq 0x9618
movq (%rax), %rdi
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x9f40
incq %r12
testq %rax, %rax
jne 0x7f63
jmp 0x7fea
leaq 0xa2f9(%rip), %rdi      # 0x12299
xorl %eax, %eax
callq 0xe0e4
jmp 0x7fde
movq %rcx, %r15
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rcx, %rsi
callq 0x8f0f
testl %eax, %eax
je 0x800d
leaq 0xa30a(%rip), %rdi      # 0x122d0
jmp 0x7fcf
leaq 0xa2e1(%rip), %rdi      # 0x122b0
xorl %eax, %eax
callq 0xe0e4
callq 0x20a0
andl $0x0, (%rax)
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x7dc2
movq (%rbx), %rdi
pushq $-0x1
popq %r14
callq 0x9427
movq %rbx, %rdi
callq 0x2040
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
testb $0x10, 0x1c(%r14)
je 0x802d
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x931b
testl %eax, %eax
je 0x802d
leaq 0xa2bd(%rip), %rdi      # 0x122e8
jmp 0x7fcf
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x7dc2
jmp 0x7f59
nop