// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/fse_compress.c
// Function: FSE_buildCTable_wksp
size_t FSE_buildCTable_wksp(FSE_CTable* ct,
                      const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog,
                            void* workSpace, size_t wkspSize)
{
    U32 const tableSize = 1 << tableLog;
    U32 const tableMask = tableSize - 1;
    void* const ptr = ct;
    U16* const tableU16 = ( (U16*) ptr) + 2;
    void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableLog ? tableSize>>1 : 1) ;
    FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
    U32 const step = FSE_TABLESTEP(tableSize);
    U32 cumul[FSE_MAX_SYMBOL_VALUE+2];

    FSE_FUNCTION_TYPE* const tableSymbol = (FSE_FUNCTION_TYPE*)workSpace;
    U32 highThreshold = tableSize-1;

    /* CTable header */
    if (((size_t)1 << tableLog) * sizeof(FSE_FUNCTION_TYPE) > wkspSize) return ERROR(tableLog_tooLarge);
    tableU16[-2] = (U16) tableLog;
    tableU16[-1] = (U16) maxSymbolValue;
    assert(tableLog < 16);   /* required for threshold strategy to work */

    /* For explanations on how to distribute symbol values over the table :
     * http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */

     #ifdef __clang_analyzer__
     memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize);   /* useless initialization, just to keep scan-build happy */
     #endif

    /* symbol start positions */
    {   U32 u;
        cumul[0] = 0;
        for (u=1; u <= maxSymbolValue+1; u++) {
            if (normalizedCounter[u-1]==-1) {  /* Low proba symbol */
                cumul[u] = cumul[u-1] + 1;
                tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1);
            } else {
                cumul[u] = cumul[u-1] + normalizedCounter[u-1];
        }   }
        cumul[maxSymbolValue+1] = tableSize+1;
    }

    /* Spread symbols */
    {   U32 position = 0;
        U32 symbol;
        for (symbol=0; symbol<=maxSymbolValue; symbol++) {
            int nbOccurrences;
            int const freq = normalizedCounter[symbol];
            for (nbOccurrences=0; nbOccurrences<freq; nbOccurrences++) {
                tableSymbol[position] = (FSE_FUNCTION_TYPE)symbol;
                position = (position + step) & tableMask;
                while (position > highThreshold)
                    position = (position + step) & tableMask;   /* Low proba area */
        }   }

        assert(position==0);  /* Must have initialized all positions */
    }

    /* Build table */
    {   U32 u; for (u=0; u<tableSize; u++) {
        FSE_FUNCTION_TYPE s = tableSymbol[u];   /* note : static analyzer may not understand tableSymbol is properly initialized */
        tableU16[cumul[s]++] = (U16) (tableSize+u);   /* TableU16 : sorted by symbol order; gives next state value */
    }   }

    /* Build Symbol Transformation Table */
    {   unsigned total = 0;
        unsigned s;
        for (s=0; s<=maxSymbolValue; s++) {
            switch (normalizedCounter[s])
            {
            case  0:
                /* filling nonetheless, for compatibility with FSE_getMaxNbBits() */
                symbolTT[s].deltaNbBits = ((tableLog+1) << 16) - (1<<tableLog);
                break;

            case -1:
            case  1:
                symbolTT[s].deltaNbBits = (tableLog << 16) - (1<<tableLog);
                symbolTT[s].deltaFindState = total - 1;
                total ++;
                break;
            default :
                {
                    U32 const maxBitsOut = tableLog - BIT_highbit32 (normalizedCounter[s]-1);
                    U32 const minStatePlus = normalizedCounter[s] << maxBitsOut;
                    symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
                    symbolTT[s].deltaFindState = total - normalizedCounter[s];
                    total +=  normalizedCounter[s];
    }   }   }   }

#if 0  /* debug : symbol costs */
    DEBUGLOG(5, "\n --- table statistics : ");
    {   U32 symbol;
        for (symbol=0; symbol<=maxSymbolValue; symbol++) {
            DEBUGLOG(5, "%3u: w=%3i,   maxBits=%u, fracBits=%.2f",
                symbol, normalizedCounter[symbol],
                FSE_getMaxNbBits(symbolTT, symbol),
                (double)FSE_bitCost(symbolTT, tableLog, symbol, 8) / 256);
        }
    }
#endif

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x4a0(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x10dad
movl -0x34(%rbp), %eax
shrl %eax
movl %eax, -0x4a4(%rbp)
jmp 0x10dba
movl $0x1, %eax
movl %eax, -0x4a4(%rbp)
jmp 0x10dba
movq -0x4a0(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %eax
shrl %eax
movl -0x34(%rbp), %ecx
shrl $0x3, %ecx
addl %ecx, %eax
addl $0x3, %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x468(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x46c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
shlq $0x0, %rax
cmpq -0x30(%rbp), %rax
jbe 0x10e2a
movq $-0x5, -0x8(%rbp)
jmp 0x111ef
movl -0x20(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, -0x4(%rax)
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x48(%rbp), %rax
movw %cx, -0x2(%rax)
movl $0x0, -0x460(%rbp)
movl $0x1, -0x470(%rbp)
movl -0x470(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
ja 0x10f1c
movq -0x18(%rbp), %rax
movl -0x470(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movswl (%rax,%rcx,2), %eax
cmpl $-0x1, %eax
jne 0x10ed2
movl -0x470(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl -0x460(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl -0x470(%rbp), %eax
movl %ecx, -0x460(%rbp,%rax,4)
movl -0x470(%rbp), %eax
subl $0x1, %eax
movb %al, %dl
movq -0x468(%rbp), %rax
movl -0x46c(%rbp), %ecx
movl %ecx, %esi
addl $-0x1, %esi
movl %esi, -0x46c(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
jmp 0x10f06
movl -0x470(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl -0x460(%rbp,%rax,4), %ecx
movq -0x18(%rbp), %rax
movl -0x470(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movswl (%rax,%rdx,2), %eax
addl %eax, %ecx
movl -0x470(%rbp), %eax
movl %ecx, -0x460(%rbp,%rax,4)
jmp 0x10f08
movl -0x470(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x470(%rbp)
jmp 0x10e5a
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %ecx, -0x460(%rbp,%rax,4)
movl $0x0, -0x474(%rbp)
movl $0x0, -0x478(%rbp)
movl -0x478(%rbp), %eax
cmpl -0x1c(%rbp), %eax
ja 0x10ff5
movq -0x18(%rbp), %rax
movl -0x478(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x480(%rbp)
movl $0x0, -0x47c(%rbp)
movl -0x47c(%rbp), %eax
cmpl -0x480(%rbp), %eax
jge 0x10fdf
movl -0x478(%rbp), %eax
movb %al, %dl
movq -0x468(%rbp), %rax
movl -0x474(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x474(%rbp), %eax
addl -0x5c(%rbp), %eax
andl -0x38(%rbp), %eax
movl %eax, -0x474(%rbp)
movl -0x474(%rbp), %eax
cmpl -0x46c(%rbp), %eax
jbe 0x10fcc
movl -0x474(%rbp), %eax
addl -0x5c(%rbp), %eax
andl -0x38(%rbp), %eax
movl %eax, -0x474(%rbp)
jmp 0x10faa
jmp 0x10fce
movl -0x47c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x47c(%rbp)
jmp 0x10f72
jmp 0x10fe1
movl -0x478(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x478(%rbp)
jmp 0x10f45
movl $0x0, -0x484(%rbp)
movl -0x484(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x11063
movq -0x468(%rbp), %rax
movl -0x484(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x485(%rbp)
movl -0x34(%rbp), %eax
addl -0x484(%rbp), %eax
movw %ax, %dx
movq -0x48(%rbp), %rax
movzbl -0x485(%rbp), %ecx
movl %ecx, %esi
movl -0x460(%rbp,%rsi,4), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, -0x460(%rbp,%rsi,4)
movl %ecx, %ecx
movw %dx, (%rax,%rcx,2)
movl -0x484(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x484(%rbp)
jmp 0x10fff
movl $0x0, -0x48c(%rbp)
movl $0x0, -0x490(%rbp)
movl -0x490(%rbp), %eax
cmpl -0x1c(%rbp), %eax
ja 0x111e7
movq -0x18(%rbp), %rax
movl -0x490(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x4a8(%rbp)
subl $-0x1, %eax
je 0x110e2
jmp 0x110a1
movl -0x4a8(%rbp), %eax
testl %eax, %eax
je 0x110ba
jmp 0x110ad
movl -0x4a8(%rbp), %eax
subl $0x1, %eax
je 0x110e2
jmp 0x1112c
movl -0x20(%rbp), %edx
addl $0x1, %edx
shll $0x10, %edx
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl %eax, %edx
movq -0x58(%rbp), %rax
movl -0x490(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
jmp 0x111d1
movl -0x20(%rbp), %edx
shll $0x10, %edx
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
subl %eax, %edx
movq -0x58(%rbp), %rax
movl -0x490(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x48c(%rbp), %edx
subl $0x1, %edx
movq -0x58(%rbp), %rax
movl -0x490(%rbp), %ecx
movl %edx, (%rax,%rcx,8)
movl -0x48c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48c(%rbp)
jmp 0x111d1
movl -0x20(%rbp), %eax
movl %eax, -0x4ac(%rbp)
movq -0x18(%rbp), %rax
movl -0x490(%rbp), %ecx
movswl (%rax,%rcx,2), %edi
subl $0x1, %edi
callq 0x11200
movl %eax, %ecx
movl -0x4ac(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x494(%rbp)
movq -0x18(%rbp), %rax
movl -0x490(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
movl -0x494(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x498(%rbp)
movl -0x494(%rbp), %edx
shll $0x10, %edx
subl -0x498(%rbp), %edx
movq -0x58(%rbp), %rax
movl -0x490(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x48c(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x490(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
subl %eax, %edx
movq -0x58(%rbp), %rax
movl -0x490(%rbp), %ecx
movl %edx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movl -0x490(%rbp), %ecx
movswl (%rax,%rcx,2), %eax
addl -0x48c(%rbp), %eax
movl %eax, -0x48c(%rbp)
jmp 0x111d3
movl -0x490(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x490(%rbp)
jmp 0x11077
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopl (%rax)