// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/../lib/fse_decompress.c
// Function: FSE_buildDTable
size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
{
    void* const tdPtr = dt+1;   /* because *dt is unsigned, 32-bits aligned on 32-bits */
    FSE_DECODE_TYPE* const tableDecode = (FSE_DECODE_TYPE*) (tdPtr);
    U16 symbolNext[FSE_MAX_SYMBOL_VALUE+1];

    U32 const maxSV1 = maxSymbolValue + 1;
    U32 const tableSize = 1 << tableLog;
    U32 highThreshold = tableSize-1;

    /* Sanity Checks */
    if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge);
    if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);

    /* Init, lay down lowprob symbols */
    {   FSE_DTableHeader DTableH;
        DTableH.tableLog = (U16)tableLog;
        DTableH.fastMode = 1;
        {   S16 const largeLimit= (S16)(1 << (tableLog-1));
            U32 s;
            for (s=0; s<maxSV1; s++) {
                if (normalizedCounter[s]==-1) {
                    tableDecode[highThreshold--].symbol = (FSE_FUNCTION_TYPE)s;
                    symbolNext[s] = 1;
                } else {
                    if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
                    symbolNext[s] = normalizedCounter[s];
        }   }   }
        memcpy(dt, &DTableH, sizeof(DTableH));
    }

    /* Spread symbols */
    {   U32 const tableMask = tableSize-1;
        U32 const step = FSE_TABLESTEP(tableSize);
        U32 s, position = 0;
        for (s=0; s<maxSV1; s++) {
            int i;
            for (i=0; i<normalizedCounter[s]; i++) {
                tableDecode[position].symbol = (FSE_FUNCTION_TYPE)s;
                position = (position + step) & tableMask;
                while (position > highThreshold) position = (position + step) & tableMask;   /* lowprob area */
        }   }
        if (position!=0) return ERROR(GENERIC);   /* position must reach all cells once, otherwise normalizedCounter is incorrect */
    }

    /* Build Decoding table */
    {   U32 u;
        for (u=0; u<tableSize; u++) {
            FSE_FUNCTION_TYPE const symbol = (FSE_FUNCTION_TYPE)(tableDecode[u].symbol);
            U32 const nextState = symbolNext[symbol]++;
            tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
            tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
    }   }

    return 0;
}

// Assembly:
movl $0x1, %r9d
shll %cl, %r9d
cmpl $0xff, %edx
jbe 0x6f8f
movabsq $-0x6, %rax
retq
movl %ecx, %r8d
cmpl $0xc, %ecx
jbe 0x6fa2
movabsq $-0x5, %rax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl $0x8000, %r10d          # imm = 0x8000
movl %r8d, %ecx
shll %cl, %r10d
incl %edx
leal -0x1(%r9), %eax
shrl $0x10, %r10d
movl %edx, %ecx
movw $0x1, %r11w
xorl %ebx, %ebx
xorl %r14d, %r14d
movl %eax, %edx
cmpq %r14, %rcx
je 0x7004
movswl (%rsi,%r14,2), %ebp
cmpl $-0x1, %ebp
je 0x6feb
cmpl %ebp, %r10d
cmovlel %ebx, %r11d
jmp 0x6ff9
movl %edx, %r15d
decl %edx
movb %r14b, 0x6(%rdi,%r15,4)
movw $0x1, %bp
movw %bp, -0x80(%rsp,%r14,2)
incq %r14
jmp 0x6fd3
movw %r8w, (%rdi)
movw %r11w, 0x2(%rdi)
movl %r9d, %r10d
shrl %r10d
movl %r9d, %r11d
shrl $0x3, %r11d
addl %r11d, %r10d
addl $0x3, %r10d
xorl %r11d, %r11d
xorl %ebx, %ebx
cmpq %rcx, %r11
je 0x705d
movzwl (%rsi,%r11,2), %r14d
xorl %ebp, %ebp
testw %r14w, %r14w
cmovlel %ebp, %r14d
movzwl %r14w, %r14d
cmpl %r14d, %ebp
je 0x7058
movl %ebx, %r15d
movb %r11b, 0x6(%rdi,%r15,4)
addl %r10d, %ebx
andl %eax, %ebx
cmpl %edx, %ebx
ja 0x704b
incl %ebp
jmp 0x703e
incq %r11
jmp 0x7026
testl %ebx, %ebx
je 0x7079
movabsq $-0x1, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl %r9d, %edx
xorl %eax, %eax
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x706b
movzbl 0x6(%rdi,%rsi,4), %ecx
movzwl -0x80(%rsp,%rcx,2), %r10d
leal 0x1(%r10), %r11d
movw %r11w, -0x80(%rsp,%rcx,2)
bsrl %r10d, %r11d
movl %r8d, %ecx
subl %r11d, %ecx
shll %cl, %r10d
movb %cl, 0x7(%rdi,%rsi,4)
subl %r9d, %r10d
movw %r10w, 0x4(%rdi,%rsi,4)
incq %rsi
jmp 0x7080