// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
je 0xc0de
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x3, %eax
jne 0xc0e0
jmp 0xc0ff
leaq 0x13514(%rip), %rdi     # 0x1f5fb
leaq 0x13348(%rip), %rsi     # 0x1f436
movl $0xc8, %edx
leaq 0x1353a(%rip), %rcx     # 0x1f634
callq 0x21d0
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %al
andb $0x3, %al
movzbl %al, %eax
cmpl $0x2, %eax
jne 0xc1f7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbfc0
cmpl $0x0, %eax
je 0xc12b
jmp 0xc28c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xc570
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xc570
movl $0x20, %edi
callq 0x22a0
movq -0x18(%rbp), %rcx
movq %rax, 0x40(%rcx)
cmpq $0x0, %rax
jne 0xc16a
jmp 0xc26f
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq %rcx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl %ecx, 0x18(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0xcc70
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xc1ba
jmp 0xc262
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x18(%rbp), %r8
leaq 0xac5(%rip), %rcx       # 0xcca0
callq 0x1a390
cmpl $0x0, %eax
je 0xc1e7
jmp 0xc252
movq -0x18(%rbp), %rax
movb 0x1c(%rax), %cl
andb $-0x4, %cl
orb $0x3, %cl
movb %cl, 0x1c(%rax)
cmpl $0x0, -0x2c(%rbp)
jne 0xc20c
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rdi
leaq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0xcf10
cmpl $0x0, %eax
je 0xc23c
jmp 0xc28c
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xc570
movl $0x0, -0x4(%rbp)
jmp 0xc293
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rdi
callq 0xcf40
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x190c0
movq -0x18(%rbp), %rax
movq $0x0, 0x30(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)