// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/kvlds/btree_sync.c
// Function: btree_sync
int
btree_sync(struct btree * T, int (* callback)(void *), void * cookie)
{
	struct write_cookie * WC;
	size_t npages;
	const uint8_t ** bufv;
	uint64_t pn = 0;

	/* Bake a cookie. */
	if ((WC = malloc(sizeof(struct write_cookie))) == NULL)
		goto err0;
	WC->T = T;
	WC->callback = callback;
	WC->cookie = cookie;

	/* Figure out how many pages we need to write. */
	npages = ndirty(T->root_dirty);

	/* Allocate a vector to hold pointers to pages. */
	if (IMALLOC(bufv, npages, const uint8_t *))
		goto err1;

	/* Serialize pages and record pointers into the vector. */
	if (serializetree(T, T->root_dirty, T->pagelen, T->nextblk,
	    bufv, &pn))
		goto err2;

	/* Sanity check the number of pages serialized. */
	assert(pn == npages);
	assert(npages <= UINT32_MAX);

	/* Write pages out. */
	if (proto_lbs_request_append_blks(T->LBS, (uint32_t)npages, T->nextblk,
	    T->pagelen, bufv, callback_append, WC)) {
		warnp("Error writing pages");
		goto err2;
	}

	/* Free the page pointers vector. */
	free(bufv);

	/* Success! */
	return (0);

err2:
	free(bufv);
err1:
	free(WC);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x18, %edi
callq 0x22a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xa265
jmp 0xa3dd
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xa3f0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0xa490
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0xa2bd
cmpq $0x0, -0x30(%rbp)
jbe 0xa2bd
jmp 0xa3d4
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x38(%rbp), %r8
leaq -0x40(%rbp), %r9
callq 0xa530
cmpl $0x0, %eax
je 0xa2ef
jmp 0xa3cb
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0xa2fb
jmp 0xa31a
leaq 0x14e15(%rip), %rdi     # 0x1f117
leaq 0x14e1b(%rip), %rsi     # 0x1f124
movl $0xe1, %edx
leaq 0x14e1c(%rip), %rcx     # 0x1f131
callq 0x21d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
ja 0xa327
jmp 0xa346
leaq 0x14e3b(%rip), %rdi     # 0x1f169
leaq 0x14def(%rip), %rsi     # 0x1f124
movl $0xe2, %edx
leaq 0x14df0(%rip), %rcx     # 0x1f131
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %r8
movq -0x28(%rbp), %rax
leaq 0x35e(%rip), %r9        # 0xa6d0
movq %rax, (%rsp)
callq 0x1a6f0
cmpl $0x0, %eax
je 0xa3b9
jmp 0xa382
callq 0x20a0
cmpl $0x0, (%rax)
je 0xa3a7
leaq 0x14deb(%rip), %rdi     # 0x1f17e
movb $0x0, %al
callq 0x180a0
callq 0x20a0
movl $0x0, (%rax)
jmp 0xa3b5
leaq 0x14dd0(%rip), %rdi     # 0x1f17e
movb $0x0, %al
callq 0x182f0
jmp 0xa3b7
jmp 0xa3cb
movq -0x38(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0xa3e4
movq -0x38(%rbp), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)