// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xcd0c
jmp 0xccd2
callq 0x20a0
cmpl $0x0, (%rax)
je 0xccf7
leaq 0x129ab(%rip), %rdi     # 0x1f68e
movb $0x0, %al
callq 0x180a0
callq 0x20a0
movl $0x0, (%rax)
jmp 0xcd05
leaq 0x12990(%rip), %rdi     # 0x1f68e
movb $0x0, %al
callq 0x182f0
jmp 0xcd07
jmp 0xced3
cmpl $0x0, -0x18(%rbp)
je 0xcd3c
movq -0x30(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0xcd3c
jmp 0xcd1e
leaq 0x12980(%rip), %rdi     # 0x1f6a5
movb $0x0, %al
callq 0x182f0
callq 0x20a0
movl $0x0, (%rax)
jmp 0xced3
cmpl $0x0, -0x18(%rbp)
jne 0xcddf
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0xf040
cmpl $0x0, %eax
je 0xcd80
jmp 0xcd62
leaq 0x1295c(%rip), %rdi     # 0x1f6c5
movb $0x0, %al
callq 0x182f0
callq 0x20a0
movl $0x0, (%rax)
jmp 0xced3
movq -0x28(%rbp), %rax
movb 0x1c(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xcdcc
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xf9f0
cmpl $0x0, %eax
je 0xcdca
jmp 0xcdac
leaq 0x1292a(%rip), %rdi     # 0x1f6dd
movb $0x0, %al
callq 0x182f0
callq 0x20a0
movl $0x0, (%rax)
jmp 0xced3
jmp 0xcdcc
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb20
jmp 0xce4b
movq -0x28(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0x4, %cl
orb $0x2, %cl
movb %cl, 0x1c(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xcb20
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xcb20
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb20
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x190c0
movq -0x28(%rbp), %rax
movq $0x0, 0x30(%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0xcf60
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0xceb5
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0xcf80
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x111b0
cmpq $0x0, %rax
jne 0xcea5
jmp 0xcee4
jmp 0xcea7
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xce53
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0xcf40
movq -0x30(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0xcf00
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xcb20
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0xcf40
movq -0x30(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)