// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]kivaloo/kvlds/btree_node.c
// Function: btree_node_fetch_canfail
static int
btree_node_fetch_canfail(struct btree * T, struct node * N,
    int (* callback)(void *), void * cookie, int canfail)
{
	struct reader r;

	/* Sanity check. */
	assert((N->type == NODE_TYPE_NP) || (N->type == NODE_TYPE_READ));

	/* If we're not already reading, do so. */
	if (N->type == NODE_TYPE_NP) {
		/* Make this page present. */
		if (makepresent(T, N))
			goto err0;
		btree_node_lock(T, N->p_shadow);
		btree_node_lock(T, N->p_dirty);

		/* Create a read-in-progress structure. */
		if ((N->u.reading = malloc(sizeof(struct reading))) == NULL)
			goto err1;
		N->u.reading->pagelen = T->pagelen;
		N->u.reading->T = T;
		N->u.reading->canfail = canfail;

		/* Create a list of reader callbacks. */
		if ((N->u.reading->list = readerlist_init(0)) == NULL)
			goto err2;

		/* Read the page. */
		if (proto_lbs_request_get(T->LBS, N->pagenum, T->pagelen,
		    callback_fetch, N))
			goto err3;

		/* This page is now being read. */
		N->type = NODE_TYPE_READ;
	}

	/* If we can't fail, mark the read as such. */
	if (!canfail)
		N->u.reading->canfail = 0;

	/* Add our callback to the list. */
	r.callback = callback;
	r.cookie = cookie;
	if (readerlist_append(N->u.reading->list, &r, 1))
		goto err0;

	/* Add a lock for this callback. */
	btree_node_lock(T, N);

	/* Success! */
	return (0);

err3:
	readerlist_free(N->u.reading->list);
err2:
	free(N->u.reading);
err1:
	pool_rec_free(T->P, N);
	N->pool_cookie = NULL;
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movb 0x1c(%rsi), %al
testb $0x2, %al
je 0x8dbf
movl %r8d, %r13d
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
andb $0x3, %al
cmpb $0x2, %al
jne 0x8d47
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8bc4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x8d82
movq 0x20(%rbx), %rsi
testq %rsi, %rsi
je 0x8c98
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 0x8c98
callq 0x107a3
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
je 0x8cc1
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 0x8cc1
callq 0x107a3
movl $0x20, %edi
callq 0x22a0
movq %rax, 0x40(%rbx)
testq %rax, %rax
je 0x8d2d
movq (%r14), %rcx
movq %rcx, 0x10(%rax)
movq %r14, 0x8(%rax)
movl %r13d, 0x18(%rax)
movl $0x10, %esi
xorl %edi, %edi
callq 0xacf0
movq 0x40(%rbx), %rcx
movq %rax, (%rcx)
testq %rax, %rax
je 0x8d24
movq (%r14), %rdx
movq 0x18(%r14), %rdi
movq (%rbx), %rsi
leaq 0x7a6(%rip), %rcx       # 0x94b2
movq %rbx, %r8
callq 0x11244
testl %eax, %eax
je 0x8d43
movq 0x40(%rbx), %rax
movq (%rax), %rdi
callq 0xada1
movq 0x40(%rbx), %rdi
callq 0x2040
movq 0x30(%r14), %rdi
movq %rbx, %rsi
callq 0x1080b
movq $0x0, 0x30(%rbx)
jmp 0x8d82
orb $0x3, 0x1c(%rbx)
testl %r13d, %r13d
jne 0x8d57
movq 0x40(%rbx), %rax
movl $0x0, 0x18(%rax)
leaq 0x8(%rsp), %rsi
movq %r12, (%rsi)
movq %r15, 0x8(%rsi)
movq 0x40(%rbx), %rax
movq (%rax), %rdi
movl $0x1, %edx
movl $0x10, %ecx
callq 0xae68
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x8d93
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x8d82
movq 0x30(%r14), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x8d82
movq %rbx, %rsi
callq 0x107a3
jmp 0x8d82
leaq 0xc465(%rip), %rdi      # 0x1522b
leaq 0xc299(%rip), %rsi      # 0x15066
leaq 0xc490(%rip), %rcx      # 0x15264
movl $0xc8, %edx
callq 0x21c0