// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rcx, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
movq %rdi, %r15
movq 0x10(%rdi), %rdi
callq 0x41ab5
movq 0x10(%r15), %rdi
leaq -0x29(%rbp), %rsi
movl $0x1, %edx
callq 0x3fef4
movq 0x10(%r15), %rdi
leaq -0x2a(%rbp), %rsi
movl $0x1, %edx
callq 0x3fef4
movl 0x30(%r15), %r13d
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x41783
movl %eax, %r12d
movq %rsp, -0x60(%rbp)
movl 0x1c(%r15), %eax
movslq %eax, %rcx
movq %rsp, %rbx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %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 %rcx, -0x58(%rbp)
je 0x439cd
testw %r12w, %r12w
je 0x43ab7
movq -0x58(%rbp), %r13
movq 0x10(%r15), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x3fef4
movq 0x10(%r15), %rdi
movl 0x20(%r15), %edx
movq %r14, %rsi
callq 0x3fef4
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6710
testl %eax, %eax
jne 0x439c2
movl 0x20(%r15), %esi
movq %r14, %rdi
callq 0x1f980
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x20b0c
decw %r12w
jne 0x43978
jmp 0x43ab7
movq 0x10(%r15), %rdi
movq %rbx, %rsi
movq %rcx, %r14
movq %rcx, %rdx
callq 0x3fef4
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x4171e
cmpw $0x2, %r12w
jb 0x43aa4
movq %rax, -0x50(%rbp)
movl %r13d, -0x44(%rbp)
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x62e0
testl %eax, %eax
setns %r13b
decl %r12d
movq 0x10(%r15), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3fef4
movq 0x10(%r15), %rdi
movl -0x44(%rbp), %esi
callq 0x4171e
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x62e0
movl %eax, %r14d
testl %eax, %eax
setle %al
andb %r13b, %al
cmpb $0x1, %al
movq -0x40(%rbp), %r13
jne 0x43a84
movq 0x10(%r15), %rdi
callq 0x41ade
movq %rax, -0x68(%rbp)
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq %r13, %rcx
callq 0x438d0
movq 0x10(%r15), %rdi
movq -0x68(%rbp), %rsi
callq 0x41ab5
testl %r14d, %r14d
movq -0x70(%rbp), %rsi
js 0x43ab7
movb $0x1, %r13b
movq %rsi, -0x50(%rbp)
decw %r12w
movq -0x58(%rbp), %r14
jne 0x43a16
jmp 0x43aa7
movq %rax, %rsi
movq %r15, %rdi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x438d0
movq -0x60(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq