// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_decompress.c
// Function: HUF_readDTableX2_wksp
size_t HUF_readDTableX2_wksp(HUF_DTable* DTable,
                       const void* src, size_t srcSize,
                             void* workSpace, size_t wkspSize)
{
    U32 tableLog, maxW, sizeOfSort, nbSymbols;
    DTableDesc dtd = HUF_getDTableDesc(DTable);
    U32 const maxTableLog = dtd.maxTableLog;
    size_t iSize;
    void* dtPtr = DTable+1;   /* force compiler to avoid strict-aliasing */
    HUF_DEltX2* const dt = (HUF_DEltX2*)dtPtr;
    U32 *rankStart;

    rankValCol_t* rankVal;
    U32* rankStats;
    U32* rankStart0;
    sortedSymbol_t* sortedSymbol;
    BYTE* weightList;
    size_t spaceUsed32 = 0;

    rankVal = (rankValCol_t *)((U32 *)workSpace + spaceUsed32);
    spaceUsed32 += (sizeof(rankValCol_t) * HUF_TABLELOG_MAX) >> 2;
    rankStats = (U32 *)workSpace + spaceUsed32;
    spaceUsed32 += HUF_TABLELOG_MAX + 1;
    rankStart0 = (U32 *)workSpace + spaceUsed32;
    spaceUsed32 += HUF_TABLELOG_MAX + 2;
    sortedSymbol = (sortedSymbol_t *)workSpace + (spaceUsed32 * sizeof(U32)) / sizeof(sortedSymbol_t);
    spaceUsed32 += HUF_ALIGN(sizeof(sortedSymbol_t) * (HUF_SYMBOLVALUE_MAX + 1), sizeof(U32)) >> 2;
    weightList = (BYTE *)((U32 *)workSpace + spaceUsed32);
    spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;

    if ((spaceUsed32 << 2) > wkspSize) return ERROR(tableLog_tooLarge);

    rankStart = rankStart0 + 1;
    memset(rankStats, 0, sizeof(U32) * (2 * HUF_TABLELOG_MAX + 2 + 1));

    DEBUG_STATIC_ASSERT(sizeof(HUF_DEltX2) == sizeof(HUF_DTable));   /* if compiler fails here, assertion is wrong */
    if (maxTableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
    /* memset(weightList, 0, sizeof(weightList)); */  /* is not necessary, even though some analyzer complain ... */

    iSize = HUF_readStats(weightList, HUF_SYMBOLVALUE_MAX + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
    if (HUF_isError(iSize)) return iSize;

    /* check result */
    if (tableLog > maxTableLog) return ERROR(tableLog_tooLarge);   /* DTable can't fit code depth */

    /* find maxWeight */
    for (maxW = tableLog; rankStats[maxW]==0; maxW--) {}  /* necessarily finds a solution before 0 */

    /* Get start index of each weight */
    {   U32 w, nextRankStart = 0;
        for (w=1; w<maxW+1; w++) {
            U32 current = nextRankStart;
            nextRankStart += rankStats[w];
            rankStart[w] = current;
        }
        rankStart[0] = nextRankStart;   /* put all 0w symbols at the end of sorted list*/
        sizeOfSort = nextRankStart;
    }

    /* sort symbols by weight */
    {   U32 s;
        for (s=0; s<nbSymbols; s++) {
            U32 const w = weightList[s];
            U32 const r = rankStart[w]++;
            sortedSymbol[r].symbol = (BYTE)s;
            sortedSymbol[r].weight = (BYTE)w;
        }
        rankStart[0] = 0;   /* forget 0w symbols; this is beginning of weight(1) */
    }

    /* Build rankVal */
    {   U32* const rankVal0 = rankVal[0];
        {   int const rescale = (maxTableLog-tableLog) - 1;   /* tableLog <= maxTableLog */
            U32 nextRankVal = 0;
            U32 w;
            for (w=1; w<maxW+1; w++) {
                U32 current = nextRankVal;
                nextRankVal += rankStats[w] << (w+rescale);
                rankVal0[w] = current;
        }   }
        {   U32 const minBits = tableLog+1 - maxW;
            U32 consumed;
            for (consumed = minBits; consumed < maxTableLog - minBits + 1; consumed++) {
                U32* const rankValPtr = rankVal[consumed];
                U32 w;
                for (w = 1; w < maxW+1; w++) {
                    rankValPtr[w] = rankVal0[w] >> consumed;
    }   }   }   }

    HUF_fillDTableX2(dt, maxTableLog,
                   sortedSymbol, sizeOfSort,
                   rankStart0, rankVal, maxW,
                   tableLog+1);

    dtd.tableLog = (BYTE)maxTableLog;
    dtd.tableType = 1;
    memcpy(DTable, &dtd, sizeof(dtd));
    return iSize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x17c90
movl %eax, -0x44(%rbp)
movzbl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x98(%rbp), %rax
addq $0x9c, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x98(%rbp), %rax
addq $0xd, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rax
addq $0xe, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x2, %rcx
shrq %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x98(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq -0x98(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
shlq $0x2, %rax
cmpq -0x30(%rbp), %rax
jbe 0x18337
movq $-0x5, -0x8(%rbp)
jmp 0x18696
movq -0x80(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x6c, %edx
callq 0x10c0
cmpl $0xc, -0x48(%rbp)
jbe 0x18366
movq $-0x5, -0x8(%rbp)
jmp 0x18696
movq -0x90(%rbp), %rdi
movq -0x78(%rbp), %rdx
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0x100, %esi            # imm = 0x100
leaq -0x40(%rbp), %rcx
leaq -0x34(%rbp), %r8
movq %rax, (%rsp)
callq 0xe940
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x17c70
cmpl $0x0, %eax
je 0x183ae
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x18696
movl -0x34(%rbp), %eax
cmpl -0x48(%rbp), %eax
jbe 0x183c3
movq $-0x5, -0x8(%rbp)
jmp 0x18696
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x78(%rbp), %rax
movl -0x38(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0x183e3
jmp 0x183d8
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x183c9
movl $0x0, -0xa0(%rbp)
movl $0x1, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x18450
movl -0xa0(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x78(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
addl -0xa0(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0xa4(%rbp), %edx
movq -0x68(%rbp), %rax
movl -0x9c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x183f7
movl -0xa0(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movl -0xa0(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0x184f3
movq -0x90(%rbp), %rax
movl -0xa8(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0xac(%rbp)
movq -0x68(%rbp), %rcx
movl -0xac(%rbp), %eax
movl %eax, %edx
movl (%rcx,%rdx,4), %eax
movl %eax, %esi
addl $0x1, %esi
movl %esi, (%rcx,%rdx,4)
movl %eax, -0xb0(%rbp)
movl -0xa8(%rbp), %eax
movb %al, %dl
movq -0x88(%rbp), %rax
movl -0xb0(%rbp), %ecx
movb %dl, (%rax,%rcx,2)
movl -0xac(%rbp), %eax
movb %al, %dl
movq -0x88(%rbp), %rax
movl -0xb0(%rbp), %ecx
movb %dl, 0x1(%rax,%rcx,2)
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x1846f
movq -0x68(%rbp), %rax
movl $0x0, (%rax)
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x48(%rbp), %eax
subl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xbc(%rbp)
movl $0x0, -0xc0(%rbp)
movl $0x1, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x18595
movl -0xc0(%rbp), %eax
movl %eax, -0xc8(%rbp)
movq -0x78(%rbp), %rax
movl -0xc4(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl -0xc4(%rbp), %ecx
addl -0xbc(%rbp), %ecx
shll %cl, %eax
addl -0xc0(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0xc8(%rbp), %edx
movq -0xb8(%rbp), %rax
movl -0xc4(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x1852b
movl -0x34(%rbp), %eax
addl $0x1, %eax
subl -0x38(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl -0x48(%rbp), %ecx
subl -0xcc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x1864b
movq -0x70(%rbp), %rax
movl -0xd0(%rbp), %ecx
imulq $0x34, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movl $0x1, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x18635
movq -0xb8(%rbp), %rax
movl -0xdc(%rbp), %ecx
movl (%rax,%rcx,4), %edx
movl -0xd0(%rbp), %ecx
shrl %cl, %edx
movq -0xd8(%rbp), %rax
movl -0xdc(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x185ec
jmp 0x18637
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x185b0
movq -0x60(%rbp), %rdi
movl -0x48(%rbp), %esi
movq -0x88(%rbp), %rdx
movl -0x3c(%rbp), %ecx
movq -0x80(%rbp), %r8
movq -0x70(%rbp), %r9
movl -0x38(%rbp), %r10d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x186b0
movl -0x48(%rbp), %eax
movb %al, -0x42(%rbp)
movb $0x1, -0x43(%rbp)
movq -0x10(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)