// File: /workspace/github_c_makefile_star2_O3/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 0x949c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x95b7
movq %rax, %r15
leaq 0xbdf0(%rip), %rdi      # 0x15279
xorl %eax, %eax
callq 0xffd0
movl $0x0, (%r15)
jmp 0x95ff
testl %edx, %edx
je 0x95c7
cmpl $0x0, 0x18(%rbx)
je 0x95e6
movb 0x1c(%r14), %al
andb $-0x4, %al
orb $0x2, %al
movb %al, 0x1c(%r14)
movq 0x20(%r14), %rsi
movq 0x8(%rbx), %rax
testq %rsi, %rsi
je 0x94f0
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rcx
movq (%rsi,%rcx), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x96a8
decq %rdx
movq %rdx, (%rcx)
jne 0x94f0
callq 0x107ea
movq 0x8(%rbx), %rax
movq 0x28(%r14), %rsi
testq %rsi, %rsi
je 0x9522
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rcx
movq (%rsi,%rcx), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x96a8
decq %rdx
movq %rdx, (%rcx)
jne 0x9522
callq 0x107ea
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x96a8
decq %rcx
movq %rcx, (%rax)
jne 0x9552
movq %r14, %rsi
callq 0x107ea
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq %r14, %rsi
callq 0x10770
movq $0x0, 0x30(%r14)
movq (%rbx), %rdi
movl $0x10, %esi
callq 0xad0e
testq %rax, %rax
je 0x95b3
xorl %r14d, %r14d
movq (%rbx), %rdi
movl $0x10, %edx
movq %r14, %rsi
callq 0xae50
movq (%rax), %rdi
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0xb910
testq %rax, %rax
je 0x964d
incq %r14
movq (%rbx), %rdi
movl $0x10, %esi
callq 0xad0e
cmpq %rax, %r14
jb 0x9577
xorl %ebp, %ebp
jmp 0x9630
leaq 0xbcbb(%rip), %rdi      # 0x15279
xorl %eax, %eax
callq 0x100ef
jmp 0x95ff
movq %rcx, %r15
movq 0x10(%rbx), %rdx
movq %r14, %rdi
movq %rcx, %rsi
callq 0xa6ad
testl %eax, %eax
je 0x9654
leaq 0xbccc(%rip), %rdi      # 0x152b0
jmp 0x95ed
leaq 0xbca3(%rip), %rdi      # 0x15290
xorl %eax, %eax
callq 0x100ef
callq 0x20a0
movl $0x0, (%rax)
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x96a8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
decq %rcx
movq %rcx, (%rax)
jne 0x9630
movq %r14, %rsi
callq 0x107ea
movq (%rbx), %rdi
callq 0xac50
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x9630
testb $0x10, 0x1c(%r14)
je 0x9677
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0xab2f
testl %eax, %eax
je 0x9677
leaq 0xbc56(%rip), %rdi      # 0x152c8
jmp 0x95ed
movq 0x8(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x96a8
decq %rcx
movq %rcx, (%rax)
jne 0x9562
movq %r14, %rsi
callq 0x107ea
jmp 0x9562
leaq 0xafa1(%rip), %rdi      # 0x14650
leaq 0xafc0(%rip), %rsi      # 0x14676
leaq 0xafd2(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
nop