// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/bPlusTree.c
// Function: writeLeafLevel
static void writeLeafLevel(bits16 blockSize, void *itemArray, int itemSize, bits64 itemCount, 
	void (*fetchKey)(const void *va, char *keyBuf), bits32 keySize,
	void* (*fetchVal)(const void *va), bits32 valSize,
	FILE *f)
/* Write out leaf level blocks. */
{
char *items = itemArray;
bits64 i,j;
UBYTE isLeaf = TRUE;
UBYTE reserved = 0;
bits16 countOne;
bits64 countLeft = itemCount;
char keyBuf[keySize+1];
keyBuf[keySize] = 0;
for (i=0; i<itemCount; i += countOne)
    {
    /* Write block header */
    if (countLeft > blockSize)
        countOne = blockSize;
    else
        countOne = countLeft;
    writeOne(f, isLeaf);
    writeOne(f, reserved);
    writeOne(f, countOne);

    /* Write out position in genome and in file for each item. */
    for (j=0; j<countOne; ++j)
        {
	assert(i+j < itemCount);
	void *item = items + (i+j)*itemSize;
	memset(keyBuf, 0, keySize);
	(*fetchKey)(item, keyBuf);
	mustWrite(f, keyBuf, keySize);
	mustWrite(f, (*fetchVal)(item), valSize);
	}
    
    /* Pad out any unused bits of last block with zeroes. */
    int slotSize = keySize + valSize;
    for (j=countOne; j<blockSize; ++j)
	repeatCharOut(f, 0, slotSize);

    countLeft -= countOne;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %r15d
movq %r8, -0x80(%rbp)
movq %rsi, -0x60(%rbp)
movq %rsp, -0x58(%rbp)
movb $0x1, -0x2c(%rbp)
xorl %eax, %eax
movb %al, -0x2b(%rbp)
leal 0x1(%r15), %esi
movq %rsp, %r13
addq $0xf, %rsi
andq $-0x10, %rsi
subq %rsi, %r13
movq %r13, %rsp
movl %r9d, %r12d
movb %al, (%r12,%r13)
movq %rcx, -0x48(%rbp)
testq %rcx, %rcx
je 0x4377b
movq 0x20(%rbp), %rbx
movl 0x18(%rbp), %eax
movzwl %di, %ecx
movq %rcx, -0x40(%rbp)
movslq %edx, %rcx
movq %rcx, -0x50(%rbp)
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
addl %eax, %r15d
movq $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rdx
movq %r15, -0x68(%rbp)
movq -0x40(%rbp), %rcx
cmpq %rcx, %rdx
movq %rdx, -0x70(%rbp)
movl %edx, %eax
cmoval %ecx, %eax
movw %ax, -0x2a(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x22e1e
movl $0x1, %edx
movq %rbx, %rdi
leaq -0x2b(%rbp), %rsi
callq 0x22e1e
movl $0x2, %edx
movq %rbx, %rdi
leaq -0x2a(%rbp), %rsi
callq 0x22e1e
movzwl -0x2a(%rbp), %eax
testq %rax, %rax
je 0x43739
movq -0x50(%rbp), %r15
imulq -0x38(%rbp), %r15
addq -0x60(%rbp), %r15
xorl %r14d, %r14d
movq -0x38(%rbp), %rax
addq %r14, %rax
cmpq -0x48(%rbp), %rax
jae 0x4378e
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x63b0
movq %r15, %rdi
movq %r13, %rsi
callq *-0x80(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x22e1e
movq %r15, %rdi
callq *0x10(%rbp)
movq %rbx, %rdi
movq %rax, %rsi
movq -0x78(%rbp), %rdx
callq 0x22e1e
incq %r14
movzwl -0x2a(%rbp), %eax
addq -0x50(%rbp), %r15
cmpq %rax, %r14
jb 0x436df
cmpl %eax, -0x40(%rbp)
movq -0x68(%rbp), %r15
jbe 0x4375b
movq -0x40(%rbp), %r14
subq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x22766
decq %r14
jne 0x43749
movzwl -0x2a(%rbp), %eax
movq -0x70(%rbp), %rdx
subq %rax, %rdx
movq -0x38(%rbp), %rcx
addq %rax, %rcx
movq %rcx, -0x38(%rbp)
cmpq -0x48(%rbp), %rcx
jb 0x4367f
movq -0x58(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x51f58(%rip), %rdi     # 0x956ed
leaq 0x51dc9(%rip), %rsi     # 0x95565
leaq 0x51f5a(%rip), %rcx     # 0x956fd
movl $0x211, %edx            # imm = 0x211
callq 0x6460