// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movw %di, %ax
movq 0x20(%rbp), %rdi
movl 0x18(%rbp), %edi
movq 0x10(%rbp), %rdi
movw %ax, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movb $0x1, -0x49(%rbp)
movb $0x0, -0x4a(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, %ecx
movq %rsp, %rax
movq %rax, -0x60(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x80(%rbp)
movq %rax, %rsp
movq %rcx, -0x68(%rbp)
movl -0x2c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x61e8d
movq -0x58(%rbp), %rax
movzwl -0x2(%rbp), %ecx
cmpq %rcx, %rax
jbe 0x61d26
movw -0x2(%rbp), %ax
movw %ax, -0x4c(%rbp)
jmp 0x61d2e
movq -0x58(%rbp), %rax
movw %ax, -0x4c(%rbp)
movq 0x20(%rbp), %rdi
leaq -0x49(%rbp), %rsi
movl $0x1, %edx
callq 0x2f8b0
movq 0x20(%rbp), %rdi
leaq -0x4a(%rbp), %rsi
movl $0x1, %edx
callq 0x2f8b0
movq 0x20(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
movl $0x2, %edx
callq 0x2f8b0
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzwl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x61e31
movq -0x40(%rbp), %rax
addq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x61d8d
jmp 0x61dac
leaq 0x7d88a(%rip), %rdi     # 0xdf61e
leaq 0x7d6fb(%rip), %rsi     # 0xdf496
movl $0x211, %edx            # imm = 0x211
leaq 0x7d887(%rip), %rcx     # 0xdf62e
callq 0x6450
movq -0x80(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
addq -0x48(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x63a0
movq -0x80(%rbp), %rsi
movq -0x28(%rbp), %rax
movq -0x70(%rbp), %rdi
callq *%rax
movq -0x80(%rbp), %rsi
movq 0x20(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, %edx
callq 0x2f8b0
movq 0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq 0x10(%rbp), %rax
movq -0x70(%rbp), %rdi
callq *%rax
movq -0x88(%rbp), %rdi
movq %rax, %rsi
movl 0x18(%rbp), %eax
movl %eax, %edx
callq 0x2f8b0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x61d6c
movl -0x2c(%rbp), %eax
addl 0x18(%rbp), %eax
movl %eax, -0x74(%rbp)
movzwl -0x4c(%rbp), %eax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzwl -0x2(%rbp), %ecx
cmpq %rcx, %rax
jae 0x61e6b
movq 0x20(%rbp), %rdi
movl -0x74(%rbp), %edx
xorl %esi, %esi
callq 0x2efd0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x61e42
movzwl -0x4c(%rbp), %eax
movl %eax, %ecx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movzwl -0x4c(%rbp), %eax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x61d01
movq -0x60(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)