// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x238(%rbp)
movl -0x238(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x23c(%rbp)
cmpl $0xff, -0x1c(%rbp)
jbe 0xf60e
movq $-0x6, -0x8(%rbp)
jmp 0xf8e8
cmpl $0xc, -0x20(%rbp)
jbe 0xf621
movq $-0x5, -0x8(%rbp)
jmp 0xf8e8
movl -0x20(%rbp), %eax
movw %ax, -0x240(%rbp)
movw $0x1, -0x23e(%rbp)
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl $0x1, %eax
shll %cl, %eax
movw %ax, -0x242(%rbp)
movl $0x0, -0x248(%rbp)
movl -0x248(%rbp), %eax
cmpl -0x234(%rbp), %eax
jae 0xf700
movq -0x18(%rbp), %rax
movl -0x248(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
cmpl $-0x1, %eax
jne 0xf6ac
movl -0x248(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x23c(%rbp), %ecx
movl %ecx, %esi
addl $-0x1, %esi
movl %esi, -0x23c(%rbp)
movl %ecx, %ecx
movb %dl, 0x2(%rax,%rcx,4)
movl -0x248(%rbp), %eax
movw $0x1, -0x230(%rbp,%rax,2)
jmp 0xf6ea
movq -0x18(%rbp), %rax
movl -0x248(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
movswl -0x242(%rbp), %ecx
cmpl %ecx, %eax
jl 0xf6ce
movw $0x0, -0x23e(%rbp)
movq -0x18(%rbp), %rax
movl -0x248(%rbp), %ecx
movw (%rax,%rcx,2), %cx
movl -0x248(%rbp), %eax
movw %cx, -0x230(%rbp,%rax,2)
jmp 0xf6ec
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0xf652
movq -0x10(%rbp), %rax
movl -0x240(%rbp), %ecx
movl %ecx, (%rax)
movl -0x238(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24c(%rbp)
movl -0x238(%rbp), %eax
shrl %eax
movl -0x238(%rbp), %ecx
shrl $0x3, %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, -0x250(%rbp)
movl $0x0, -0x258(%rbp)
movl $0x0, -0x254(%rbp)
movl -0x254(%rbp), %eax
cmpl -0x234(%rbp), %eax
jae 0xf801
movl $0x0, -0x25c(%rbp)
movl -0x25c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x254(%rbp), %edx
movswl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jge 0xf7eb
movl -0x254(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x258(%rbp), %ecx
movb %dl, 0x2(%rax,%rcx,4)
movl -0x258(%rbp), %eax
addl -0x250(%rbp), %eax
andl -0x24c(%rbp), %eax
movl %eax, -0x258(%rbp)
movl -0x258(%rbp), %eax
cmpl -0x23c(%rbp), %eax
jbe 0xf7d5
movl -0x258(%rbp), %eax
addl -0x250(%rbp), %eax
andl -0x24c(%rbp), %eax
movl %eax, -0x258(%rbp)
jmp 0xf7ad
jmp 0xf7d7
movl -0x25c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x25c(%rbp)
jmp 0xf767
jmp 0xf7ed
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0xf74b
cmpl $0x0, -0x258(%rbp)
je 0xf817
movq $-0x1, -0x8(%rbp)
jmp 0xf8e8
movl $0x0, -0x260(%rbp)
movl -0x260(%rbp), %eax
cmpl -0x238(%rbp), %eax
jae 0xf8e0
movq -0x30(%rbp), %rax
movl -0x260(%rbp), %ecx
movb 0x2(%rax,%rcx,4), %al
movb %al, -0x261(%rbp)
movzbl -0x261(%rbp), %eax
movl %eax, %ecx
movw -0x230(%rbp,%rcx,2), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, -0x230(%rbp,%rcx,2)
movzwl %ax, %eax
movl %eax, -0x268(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x26c(%rbp)
movl -0x268(%rbp), %edi
callq 0xf900
movl %eax, %ecx
movl -0x26c(%rbp), %eax
subl %ecx, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x260(%rbp), %ecx
movb %dl, 0x3(%rax,%rcx,4)
movl -0x268(%rbp), %eax
movq -0x30(%rbp), %rcx
movl -0x260(%rbp), %edx
movzbl 0x3(%rcx,%rdx,4), %ecx
shll %cl, %eax
subl -0x238(%rbp), %eax
movw %ax, %dx
movq -0x30(%rbp), %rax
movl -0x260(%rbp), %ecx
movw %dx, (%rax,%rcx,4)
movl -0x260(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x260(%rbp)
jmp 0xf821
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw %cs:(%rax,%rax)