// File: /workspace/github_c_makefile_star2_O1/haxlang[P]hax/haxHash.c
// Function: RebuildTable
static void
RebuildTable(
    Hax_Interp *interp,
    Hax_HashTable *tablePtr	/* Table to enlarge. */)
{
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    int oldSize, count, index;
    Hax_HashEntry **oldBuckets;
    Hax_HashEntry **oldChainPtr, **newChainPtr;
    Hax_HashEntry *hPtr;

    oldSize = tablePtr->numBuckets;
    oldBuckets = tablePtr->buckets;

    /*
     * Allocate and initialize the new bucket array, and set up
     * hashing constants for new array size.
     */

    tablePtr->numBuckets *= 4;
    tablePtr->buckets = (Hax_HashEntry **) ckalloc(memoryp, (unsigned)
	    (tablePtr->numBuckets * sizeof(Hax_HashEntry *)));
    for (count = tablePtr->numBuckets, newChainPtr = tablePtr->buckets;
	    count > 0; count--, newChainPtr++) {
	*newChainPtr = NULL;
    }
    tablePtr->rebuildSize *= 4;
    tablePtr->downShift -= 2;
    tablePtr->mask = (tablePtr->mask << 2) + 3;

    /*
     * Rehash all of the existing entries into the new bucket array.
     */

    for (oldChainPtr = oldBuckets; oldSize > 0; oldSize--, oldChainPtr++) {
	for (hPtr = *oldChainPtr; hPtr != NULL; hPtr = *oldChainPtr) {
	    *oldChainPtr = hPtr->nextPtr;
	    if (tablePtr->keyType == HAX_STRING_KEYS) {
		index = HashString(hPtr->key.string) & tablePtr->mask;
	    } else if (tablePtr->keyType == HAX_ONE_WORD_KEYS) {
		index = RANDOM_INDEX(tablePtr, hPtr->key.oneWordValue);
	    } else {
		int *iPtr;
		int count;

		for (index = 0, count = tablePtr->keyType,
			iPtr = hPtr->key.words; count > 0; count--, iPtr++) {
		    index += *iPtr;
		}
		index = RANDOM_INDEX(tablePtr, index);
	    }
	    hPtr->bucketPtr = &(tablePtr->buckets[index]);
	    hPtr->nextPtr = *hPtr->bucketPtr;
	    *hPtr->bucketPtr = hPtr;
	}
    }

    /*
     * Free up the old bucket array, if it was dynamically allocated.
     */

    if (oldBuckets != tablePtr->staticBuckets) {
	ckfree(memoryp, (char *) oldBuckets);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %r15
movq 0x280(%rdi), %rbx
movl 0x28(%rsi), %r12d
movq (%rsi), %r14
leal (,%r12,4), %eax
movl %eax, 0x28(%rsi)
movl %r12d, %esi
shll $0x5, %esi
leaq 0x74fa(%rip), %rdx      # 0x1545e
movq %rbx, %rdi
movl $0x38f, %ecx            # imm = 0x38F
callq 0x44c0
movq %rax, (%r15)
movslq 0x28(%r15), %rdx
testq %rdx, %rdx
jle 0xdf8b
shlq $0x3, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x42b0
shll $0x2, 0x30(%r15)
movl 0x34(%r15), %ecx
movl 0x38(%r15), %eax
addl $-0x2, %ecx
movl %ecx, 0x34(%r15)
leal 0x3(,%rax,4), %eax
movl %eax, 0x38(%r15)
testl %r12d, %r12d
jle 0xe07f
movl %ecx, %ecx
movq %r14, %rdx
movq (%rdx), %rsi
testq %rsi, %rsi
je 0xe069
movl 0x3c(%r15), %edi
leal 0x1(%rdi), %r8d
movq (%rsi), %r9
movq %r9, (%rdx)
cmpl $0x1, %edi
je 0xe003
testl %edi, %edi
jne 0xe00d
movb 0x20(%rsi), %r11b
testb %r11b, %r11b
je 0xe038
leaq 0x21(%rsi), %r10
xorl %r9d, %r9d
movsbl %r11b, %r11d
leal (%r9,%r9,8), %r9d
addl %r11d, %r9d
movb (%r10), %r11b
incq %r10
testb %r11b, %r11b
jne 0xdfeb
jmp 0xe043
imulq $0x41c64e6d, 0x20(%rsi), %r9 # imm = 0x41C64E6D
jmp 0xe040
jle 0xe03d
leaq 0x20(%rsi), %r10
xorl %r9d, %r9d
movl %r8d, %r11d
movslq (%r10), %r13
movslq %r9d, %r9
addq %r13, %r9
addq $0x4, %r10
decl %r11d
cmpl $0x1, %r11d
jg 0xe019
imulq $0x41c64e6d, %r9, %r9   # imm = 0x41C64E6D
jmp 0xe040
xorl %r9d, %r9d
jmp 0xe043
xorl %r9d, %r9d
sarq %cl, %r9
andl %eax, %r9d
movq (%r15), %r10
movslq %r9d, %r9
leaq (%r10,%r9,8), %r9
movq %r9, 0x10(%rsi)
movq (%r9), %r10
movq %r10, (%rsi)
movq %rsi, (%r9)
movq (%rdx), %rsi
testq %rsi, %rsi
jne 0xdfcc
leal -0x1(%r12), %esi
addq $0x8, %rdx
cmpl $0x1, %r12d
movl %esi, %r12d
jg 0xdfb8
addq $0x8, %r15
cmpq %r15, %r14
je 0xe0a8
leaq 0x73cf(%rip), %rdx      # 0x1545e
movq %rbx, %rdi
movq %r14, %rsi
movl $0x3b8, %ecx            # imm = 0x3B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4280
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop