// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/btree_balance.c
// Function: btree_balance
int
btree_balance(struct btree * T, int (* callback)(void *), void * cookie)
{
	struct balance_cookie * B;

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

	/* Split nodes as necessary. */
	if (splittree(T))
		goto err1;

	/* Merge nodes as necessary and perform callback. */
	if (planmerge(B))
		goto err1;

	/* Success! */
	return (0);

err1:
	free(B);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl $0x20, %edi
callq 0x22a0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x6523
movq %rax, %r12
movq %r14, (%rax)
movq %rbx, 0x8(%rax)
movq %r15, 0x10(%rax)
movq 0x28(%r15), %rsi
movq %r15, %rdi
callq 0x65e4
testl %eax, %eax
jne 0x651b
movq %r12, 0x8(%rsp)
movq 0x28(%r15), %rdi
callq 0xa5e7
cmpq (%r15), %rax
jbe 0x6460
movq 0x28(%r15), %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x96c8
movq %rax, %r13
movq %rax, %rbx
decq %rbx
je 0x62fe
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbx
ja 0x64f1
leaq (,%rbx,8), %rdi
callq 0x22a0
testq %rax, %rax
je 0x6511
movq %rax, %r12
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %r13
jbe 0x6301
jmp 0x64fe
xorl %r12d, %r12d
shlq $0x3, %r13
movq %r13, %rdi
callq 0x22a0
testq %rax, %rax
je 0x6509
movsbl 0x1d(%rbp), %edx
cmpl $0x3f, %edx
jge 0x6534
movq %rax, %r14
incl %edx
movq $0x0, (%rsp)
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rcx
movq %r12, %r8
movq %rax, %r9
callq 0x8a48
testq %rax, %rax
je 0x6481
movq %rax, %r13
incq 0x48(%r15)
orb $0x10, 0x1c(%rax)
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rax
movq (%r13,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x637b
movq %r13, %rsi
callq 0x1070f
andb $-0x11, 0x1c(%rbp)
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rax
movq (%rbp,%rax), %rcx
movq (%rcx), %rdx
testq %rdx, %rdx
je 0x6553
decq %rdx
movq %rdx, (%rcx)
jne 0x63b0
movq %rbp, %rsi
callq 0x107ea
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rax
movq %r13, 0x28(%rbp)
movq (%r13,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x63d0
movq %r13, %rsi
callq 0x1070f
movq 0x40(%r13), %rdx
movq 0x48(%r13), %rcx
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %r8
callq 0x97c7
testl %eax, %eax
jne 0x648b
movq 0x38(%r13), %rax
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x10(%rsp)
jne 0x6572
xorl %ebx, %ebx
movq 0x48(%r13), %rcx
movq (%rcx,%rbx,8), %rcx
movq %r13, 0x28(%rcx)
movq 0x48(%r13), %rcx
movq (%rcx,%rbx,8), %rcx
movb 0x1c(%rcx), %cl
andb $0x3, %cl
cmpb $0x2, %cl
je 0x644c
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rcx
movq (%r13,%rcx), %rcx
movq (%rcx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rcx)
testq %rdx, %rdx
jne 0x644c
movq %r13, %rsi
callq 0x1070f
movq 0x38(%r13), %rax
incq %rbx
cmpq %rax, %rbx
jbe 0x6405
movq %r13, 0x28(%r15)
movq %r13, %rdi
jmp 0x6296
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x6591
testl %eax, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jne 0x651b
xorl %ebp, %ebp
jmp 0x6523
movq %r14, %rdi
callq 0x2040
jmp 0x6509
orb $0x10, 0x1c(%rbp)
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rax
movq (%rbp,%rax), %rcx
movq (%rcx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rcx)
testq %rdx, %rdx
jne 0x64bb
movq %rbp, %rsi
callq 0x1070f
movq 0x30(%r15), %rdi
movq 0x20(%rdi), %rax
movq (%r13,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x6553
decq %rcx
movq %rcx, (%rax)
jne 0x64dc
movq %r13, %rsi
callq 0x107ea
movq $-0x1, 0x38(%r13)
movq %r15, %rdi
movq %r13, %rsi
callq 0x8d62
jmp 0x6511
callq 0x20a0
movl $0xc, (%rax)
jmp 0x6511
callq 0x20a0
movl $0xc, (%rax)
movq %r12, %rdi
callq 0x2040
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe586(%rip), %rdi      # 0x14ac1
leaq 0xe4e3(%rip), %rsi      # 0x14a25
leaq 0xe58b(%rip), %rcx      # 0x14ad4
movl $0xbe, %edx
callq 0x21c0
leaq 0xe0f6(%rip), %rdi      # 0x14650
leaq 0xe115(%rip), %rsi      # 0x14676
leaq 0xe127(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xe591(%rip), %rdi      # 0x14b0a
leaq 0xe4a5(%rip), %rsi      # 0x14a25
leaq 0xe54d(%rip), %rcx      # 0x14ad4
movl $0xd7, %edx
callq 0x21c0