// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq $-0x5, %r12
cmpq $0x5dc, %r8             # imm = 0x5DC
jb 0xd13d
movq %rcx, %r13
movq %rdi, %rbx
movl (%rdi), %ebp
movzbl %bpl, %eax
leaq 0x270(%rcx), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x5c(%r15)
movups %xmm0, 0x50(%r15)
movups %xmm0, 0x40(%r15)
movups %xmm0, 0x30(%r15)
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
cmpl $0xc, %eax
ja 0xd13d
movq %rsi, %r9
movl %eax, 0x14(%rsp)
leaq 0x4dc(%r13), %rdi
movq %rdx, (%rsp)
leaq 0x20(%rsp), %rcx
leaq 0x24(%rsp), %r8
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdx
callq 0x740e
cmpq $-0x9, %rax
ja 0xd13a
movl 0x24(%rsp), %esi
movl 0x14(%rsp), %r10d
movl %r10d, %edx
subl %esi, %edx
jb 0xd13d
movq %rax, 0x30(%rsp)
movl %ebp, %eax
shrl $0x18, %eax
movl %eax, 0x18(%rsp)
leaq 0x4(%rbx), %r12
leaq 0x2dc(%r13), %rax
movq %rax, 0x28(%rsp)
xorl %r8d, %r8d
movl %esi, %eax
movl %eax, %ecx
decl %eax
incl %r8d
cmpl $0x0, (%r15,%rcx,4)
je 0xcde9
movl %esi, %r14d
movl %esi, %eax
subl %r8d, %eax
addl $0x2, %eax
xorl %r15d, %r15d
cmpl $0x2, %eax
jb 0xce31
movl %eax, %ecx
decq %rcx
xorl %esi, %esi
xorl %edi, %edi
movl 0x274(%r13,%rsi,4), %r15d
addl %edi, %r15d
movl %edi, 0x2ac(%r13,%rsi,4)
incq %rsi
movl %r15d, %edi
cmpq %rsi, %rcx
jne 0xce13
movl %r10d, %edi
movl %r8d, 0xc(%rsp)
subl %r8d, %edi
movl %r15d, 0x2a8(%r13)
movl 0x20(%rsp), %ecx
testq %rcx, %rcx
je 0xce83
xorl %esi, %esi
movzbl 0x4dc(%r13,%rsi), %r8d
movl 0x2a8(%r13,%r8,4), %r9d
leal 0x1(%r9), %r11d
movl %r11d, 0x2a8(%r13,%r8,4)
movb %sil, 0x2dc(%r13,%r9,2)
movb %r8b, 0x2dd(%r13,%r9,2)
incq %rsi
cmpq %rsi, %rcx
jne 0xce4e
movq %rbx, 0x38(%rsp)
incl %edi
movl $0x0, 0x2a8(%r13)
cmpl $0x2, %eax
jb 0xcec6
movl %eax, %r8d
decq %r8
xorl %esi, %esi
xorl %r9d, %r9d
movl 0x274(%r13,%rsi,4), %r11d
leal (%rdx,%rsi), %ecx
shll %cl, %r11d
addl %r9d, %r11d
movl %r9d, 0x4(%r13,%rsi,4)
incq %rsi
movl %r11d, %r9d
cmpq %rsi, %r8
jne 0xcea5
cmpl %edi, 0xc(%rsp)
jae 0xcf06
movl 0xc(%rsp), %ecx
leaq 0x4(%r13), %rdx
imulq $0x34, %rcx, %r9
movl %eax, %ebx
decq %rbx
cmpl $0x2, %eax
jb 0xcefb
movq %rbx, %rsi
movq %rdx, %r8
movl (%r8), %r11d
shrl %cl, %r11d
movl %r11d, (%r8,%r9)
addq $0x4, %r8
decq %rsi
jne 0xcee8
incq %rcx
addq $0x34, %r9
cmpl %ecx, %edi
jne 0xcedd
movl %ebp, 0x1c(%rsp)
movl 0x30(%r13), %eax
movl %eax, 0xe0(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movq %r13, 0x58(%rsp)
movups 0x20(%r13), %xmm2
movaps %xmm2, 0xd0(%rsp)
movaps %xmm1, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
testl %r15d, %r15d
movl 0xc(%rsp), %r8d
je 0xd11a
incl %r14d
movl %r14d, %eax
subl %r10d, %eax
movq %rax, 0x48(%rsp)
movl %r15d, %r9d
xorl %edi, %edi
movq %r12, 0x50(%rsp)
movl %r15d, 0x10(%rsp)
movq %r9, 0x40(%rsp)
movq 0x28(%rsp), %rax
movzbl (%rax,%rdi,2), %ebx
movzbl 0x1(%rax,%rdi,2), %r11d
movl %r14d, %r13d
subl %r11d, %r13d
movl 0xb0(%rsp,%r11,4), %ebp
movl %r10d, %edx
subl %r13d, %edx
movl $0x1, %eax
movl %edx, %ecx
shll %cl, %eax
cmpl %r8d, %edx
jae 0xcfd2
leal (%rax,%rbp), %edx
cmpl %edx, %ebp
jae 0xd104
movzbl %r13b, %ecx
shll $0x10, %ecx
addl %ebx, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
movl %edx, %edx
movq %rbp, %rsi
movl %ecx, (%r12,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0xcfc1
jmp 0xd104
movq %r11, 0x68(%rsp)
movq 0x48(%rsp), %rcx
leal (%rcx,%r13), %r8d
cmpl $0x2, %r8d
movl $0x1, %esi
cmovgel %r8d, %esi
movq 0x58(%rsp), %r10
movl 0x2a4(%r10,%rsi,4), %ecx
movl %r13d, %r9d
imulq $0x34, %r9, %r9
movl 0x30(%r10,%r9), %r11d
movl %r11d, 0xa0(%rsp)
movq %rbp, 0x60(%rsp)
leaq (%r12,%rbp,4), %r12
movups (%r10,%r9), %xmm0
movups 0x10(%r10,%r9), %xmm1
movups 0x20(%r10,%r9), %xmm2
movaps %xmm2, 0x90(%rsp)
movaps %xmm1, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
cmpl $0x2, %r8d
jl 0xd06d
movl 0x70(%rsp,%rsi,4), %esi
testq %rsi, %rsi
je 0xd06d
movzbl %r13b, %r8d
shll $0x10, %r8d
addl %ebx, %r8d
addl $0x1000000, %r8d        # imm = 0x1000000
xorl %r9d, %r9d
movl %r8d, (%r12,%r9,4)
incq %r9
cmpq %r9, %rsi
jne 0xd061
cmpl %ecx, %r15d
je 0xd0e1
movl 0x10(%rsp), %esi
subl %ecx, %esi
movq 0x28(%rsp), %r8
leaq (%r8,%rcx,2), %r9
movl %esi, %r15d
xorl %ebp, %ebp
movzbl (%r9,%rbp,2), %r11d
movzbl 0x1(%r9,%rbp,2), %r8d
movl %r14d, %r10d
subl %r8d, %r10d
movl %edx, %ecx
subl %r10d, %ecx
movl $0x1, %esi
shll %cl, %esi
movl 0x70(%rsp,%r8,4), %ecx
addl %ecx, %esi
shll $0x8, %r11d
addl %r13d, %r10d
movzbl %r10b, %r10d
shll $0x10, %r10d
orl %r11d, %r10d
leal (%rbx,%r10), %r11d
addl $0x2000000, %r11d       # imm = 0x2000000
movl %ecx, %r10d
incl %ecx
movl %r11d, (%r12,%r10,4)
cmpl %esi, %ecx
jb 0xd0c7
movl %esi, 0x70(%rsp,%r8,4)
incq %rbp
cmpq %r15, %rbp
jne 0xd086
movl 0x14(%rsp), %r10d
movq 0x50(%rsp), %r12
movl 0xc(%rsp), %r8d
movl 0x10(%rsp), %r15d
movq 0x40(%rsp), %r9
movq 0x68(%rsp), %r11
movq 0x60(%rsp), %rbp
addl %ebp, %eax
movl %eax, 0xb0(%rsp,%r11,4)
incq %rdi
cmpq %r9, %rdi
jne 0xcf71
movq 0x38(%rsp), %rax
movl 0x1c(%rsp), %ecx
movb %cl, (%rax)
movb $0x1, 0x1(%rax)
movb %cl, 0x2(%rax)
movl 0x18(%rsp), %ecx
movb %cl, 0x3(%rax)
movq 0x30(%rsp), %r12
jmp 0xd13d
movq %rax, %r12
movq %r12, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq