// File: /workspace/github_c_makefile_star2_O2/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
movq %r8, -0x70(%rbp)
movq %rsi, -0x60(%rbp)
movq %rsp, -0x58(%rbp)
movl 0x18(%rbp), %esi
leaq -0x2c(%rbp), %rax
movb $0x1, (%rax)
xorl %r15d, %r15d
leaq -0x2b(%rbp), %rax
movb %r15b, (%rax)
leal 0x1(%r9), %eax
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movl %r9d, %ebx
movb %r15b, (%rbx,%r12)
movl %edi, -0x30(%rbp)
movl %edi, %eax
movq %rax, -0x50(%rbp)
movslq %edx, %rax
movq %rax, -0x38(%rbp)
addl %esi, %r9d
movq %r9, -0x78(%rbp)
movq %rcx, -0x40(%rbp)
cmpq -0x40(%rbp), %r15
jae 0x3d69a
cmpq -0x50(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movl %ecx, %eax
cmoval -0x30(%rbp), %eax
movw %ax, -0x2a(%rbp)
movq 0x20(%rbp), %r14
movq %r14, %rdi
leaq -0x2c(%rbp), %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
callq 0x1ed3f
movq %r14, %rdi
leaq -0x2b(%rbp), %rsi
movq %r13, %rdx
callq 0x1ed3f
movq %r14, %rdi
leaq -0x2a(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x1ed3f
movq -0x38(%rbp), %r14
movq %r15, -0x48(%rbp)
imulq %r15, %r14
addq -0x60(%rbp), %r14
xorl %r15d, %r15d
movzwl -0x2a(%rbp), %r13d
cmpq %r13, %r15
jae 0x3d67d
movq -0x48(%rbp), %rax
addq %r15, %rax
cmpq -0x40(%rbp), %rax
jae 0x3d6ad
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x63b0
movq %r14, %rdi
movq %r12, %rsi
callq *-0x70(%rbp)
movq 0x20(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1ed3f
movq %r14, %rdi
callq *0x10(%rbp)
movq %r13, %rdi
movq %rax, %rsi
movl 0x18(%rbp), %edx
callq 0x1ed3f
incq %r15
addq -0x38(%rbp), %r14
jmp 0x3d60b
movq 0x20(%rbp), %rdi
xorl %esi, %esi
movq -0x78(%rbp), %rdx
callq 0x1e8b6
incq %r13
cmpq -0x50(%rbp), %r13
jb 0x3d66b
movzwl -0x2a(%rbp), %eax
movq -0x68(%rbp), %rcx
subq %rax, %rcx
movq -0x48(%rbp), %r15
addq %rax, %r15
jmp 0x3d5a7
movq -0x58(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x47019(%rip), %rdi     # 0x846cd
leaq 0x46e8a(%rip), %rsi     # 0x84545
leaq 0x4701b(%rip), %rcx     # 0x846dd
movl $0x211, %edx            # imm = 0x211
callq 0x6460