// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/lib/bPlusTree.c
// Function: rFindMulti
static void rFindMulti(struct bptFile *bpt, bits64 blockStart, void *key, struct slRef **pList)
/* Find values corresponding to key and add them to pList.  You'll need to 
 * Do a slRefFreeListAndVals() on the list when done. */
{
/* Seek to start of block. */
udcSeek(bpt->udc, blockStart);

/* Read block header. */
UBYTE isLeaf;
UBYTE reserved;
bits16 i, childCount;
udcMustReadOne(bpt->udc, isLeaf);
udcMustReadOne(bpt->udc, reserved);
boolean isSwapped = bpt->isSwapped;
childCount = udcReadBits16(bpt->udc, isSwapped);

int keySize = bpt->keySize;
UBYTE keyBuf[keySize];   /* Place to put a key, buffered on stack. */
UBYTE valBuf[bpt->valSize];   /* Place to put a value, buffered on stack. */

if (isLeaf)
    {
    for (i=0; i<childCount; ++i)
        {
	udcMustRead(bpt->udc, keyBuf, keySize);
	udcMustRead(bpt->udc, valBuf, bpt->valSize);
	if (memcmp(key, keyBuf, keySize) == 0)
	    {
	    void *val = cloneMem(valBuf, bpt->valSize);
	    refAdd(pList, val);
	    }
	}
    }
else
    {
    /* Read first key and first file offset. */
    udcMustRead(bpt->udc, keyBuf, keySize);
    bits64 lastFileOffset = udcReadBits64(bpt->udc, isSwapped);
    bits64 fileOffset = lastFileOffset;
    int lastCmp = memcmp(key, keyBuf, keySize);

    /* Loop through remainder. */
    for (i=1; i<childCount; ++i)
	{
	udcMustRead(bpt->udc, keyBuf, keySize);
	fileOffset = udcReadBits64(bpt->udc, isSwapped);
	int cmp = memcmp(key, keyBuf, keySize);
	if (lastCmp >= 0 && cmp <= 0)
	    {
	    bits64 curPos = udcTell(bpt->udc);
	    rFindMulti(bpt, lastFileOffset, key, pList);
	    udcSeek(bpt->udc, curPos);
	    }
	if (cmp < 0)
	    return;
	lastCmp = cmp;
	lastFileOffset = fileOffset;
	}
    /* If made it all the way to end, do last one too. */
    rFindMulti(bpt, fileOffset, key, pList);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x58(%rbp)
movq %rdx, -0x40(%rbp)
movq %rdi, %r15
movq 0x10(%rdi), %rdi
callq 0x3bb5a
movq 0x10(%r15), %rdi
leaq -0x29(%rbp), %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x3a0ac
movq 0x10(%r15), %rdi
leaq -0x2a(%rbp), %rsi
movq %rbx, %rdx
callq 0x3a0ac
movl 0x30(%r15), %r13d
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x3b899
movl %eax, %r12d
movq %rsp, -0x70(%rbp)
movl 0x1c(%r15), %eax
movslq %eax, %rbx
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
movl 0x20(%r15), %eax
movq %rsp, %r14
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
leaq -0x29(%rbp), %rax
cmpb $0x0, (%rax)
movq %rbx, -0x60(%rbp)
movq %r15, -0x48(%rbp)
je 0x3d8e9
movq -0x38(%rbp), %r13
movq -0x48(%rbp), %r15
movq -0x60(%rbp), %rbx
subw $0x1, %r12w
jb 0x3d9e0
movq 0x10(%r15), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3a0ac
movq 0x10(%r15), %rdi
movl 0x20(%r15), %edx
movq %r14, %rsi
callq 0x3a0ac
movq -0x40(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x6710
testl %eax, %eax
jne 0x3d892
movl 0x20(%r15), %esi
movq %r14, %rdi
callq 0x1c27c
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x1d218
jmp 0x3d892
movq 0x10(%r15), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x3a0ac
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x3b842
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x62e0
movq -0x38(%rbp), %r15
testl %eax, %eax
setns %bl
xorl %eax, %eax
movl %r13d, %r14d
incl %eax
cmpw %r12w, %ax
jae 0x3d9cb
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %r13
movq 0x10(%r13), %rdi
movq %r15, %rsi
movq -0x60(%rbp), %rdx
callq 0x3a0ac
movq 0x10(%r13), %rdi
movl %r14d, %r13d
movl %r14d, %esi
callq 0x3b842
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rdi
movq %r15, %rsi
movq -0x60(%rbp), %rdx
callq 0x62e0
movl %eax, %r14d
testl %eax, %eax
setle %al
andb %al, %bl
cmpb $0x1, %bl
jne 0x3d9ac
movq -0x48(%rbp), %rbx
movq 0x10(%rbx), %rdi
callq 0x3bb84
movq %rax, %r15
movq %rbx, %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x3d7e5
movq 0x10(%rbx), %rdi
movq %r15, %rsi
callq 0x3bb5a
movb $0x1, %bl
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
testl %r14d, %r14d
movq -0x38(%rbp), %r15
movl %r13d, %r14d
movl -0x64(%rbp), %eax
jns 0x3d927
jmp 0x3d9e0
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x3d7e5
movq -0x70(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq