// File: /workspace/github_c_makefile_star2_O3/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 0x41dfc
movq 0x10(%r15), %rdi
leaq -0x29(%rbp), %rsi
movl $0x1, %edx
callq 0x40215
movq 0x10(%r15), %rdi
leaq -0x2a(%rbp), %rsi
movl $0x1, %edx
callq 0x40215
movl 0x30(%r15), %r13d
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x41b07
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 0x43d5c
testw %r12w, %r12w
je 0x43e46
movq -0x58(%rbp), %r13
movq 0x10(%r15), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x40215
movq 0x10(%r15), %rdi
movl 0x20(%r15), %edx
movq %r14, %rsi
callq 0x40215
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6710
testl %eax, %eax
jne 0x43d51
movl 0x20(%r15), %esi
movq %r14, %rdi
callq 0x1fe44
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x20f8f
decw %r12w
jne 0x43d07
jmp 0x43e46
movq 0x10(%r15), %rdi
movq %rbx, %rsi
movq %rcx, %r14
movq %rcx, %rdx
callq 0x40215
movq 0x10(%r15), %rdi
movl %r13d, %esi
callq 0x41aac
cmpw $0x2, %r12w
jb 0x43e33
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 0x40215
movq 0x10(%r15), %rdi
movl -0x44(%rbp), %esi
callq 0x41aac
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 0x43e13
movq 0x10(%r15), %rdi
callq 0x41e25
movq %rax, -0x68(%rbp)
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq %r13, %rcx
callq 0x43c5f
movq 0x10(%r15), %rdi
movq -0x68(%rbp), %rsi
callq 0x41dfc
testl %r14d, %r14d
movq -0x70(%rbp), %rsi
js 0x43e46
movb $0x1, %r13b
movq %rsi, -0x50(%rbp)
decw %r12w
movq -0x58(%rbp), %r14
jne 0x43da5
jmp 0x43e36
movq %rax, %rsi
movq %r15, %rdi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x43c5f
movq -0x60(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq