// File: /workspace/github_c_makefile_star2_O3/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 $0xf8, %rsp
movq $-0x5, %r12
cmpq $0x5dc, %r8             # imm = 0x5DC
jb 0xe0a3
movq %rcx, %r14
movq %rdi, %rbx
movl (%rdi), %eax
movzbl %al, %ebp
leaq 0x270(%rcx), %r15
pxor %xmm0, %xmm0
movdqu %xmm0, 0x5c(%r15)
movdqu %xmm0, 0x50(%r15)
movdqu %xmm0, 0x40(%r15)
movdqu %xmm0, 0x30(%r15)
movdqu %xmm0, 0x20(%r15)
movdqu %xmm0, 0x10(%r15)
movdqu %xmm0, (%r15)
cmpl $0xc, %ebp
ja 0xe0a3
movq %rsi, %r9
movl %eax, 0x1c(%rsp)
leaq 0x4dc(%r14), %rdi
movq %rdx, (%rsp)
leaq 0x38(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdx
callq 0x7a21
cmpq $-0x9, %rax
ja 0xe0a0
movl 0x3c(%rsp), %edx
movl %ebp, %esi
subl %edx, %esi
jb 0xe0a3
movq %rax, 0x58(%rsp)
movl 0x1c(%rsp), %eax
shrl $0x18, %eax
movl %eax, 0x2c(%rsp)
leaq 0x4(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x2dc(%r14), %rax
movq %rax, 0x50(%rsp)
leal 0x1(%rdx), %eax
movl %eax, 0x18(%rsp)
xorl %r10d, %r10d
movl %edx, %eax
movl %eax, %ecx
decl %eax
incl %r10d
cmpl $0x0, (%r15,%rcx,4)
je 0xdb4c
movq %rbx, 0x40(%rsp)
subl %r10d, %edx
addl $0x2, %edx
xorl %r9d, %r9d
cmpl $-0x3, %eax
ja 0xdb95
movl %edx, %ecx
decq %rcx
xorl %edi, %edi
xorl %r8d, %r8d
movl 0x274(%r14,%rdi,4), %r9d
addl %r8d, %r9d
movl %r8d, 0x2ac(%r14,%rdi,4)
incq %rdi
movl %r9d, %r8d
cmpq %rdi, %rcx
jne 0xdb77
movl %ebp, %edi
subl %r10d, %edi
movl %r9d, 0x14(%rsp)
movl %r9d, 0x2a8(%r14)
movl 0x38(%rsp), %ecx
testq %rcx, %rcx
je 0xdbe7
xorl %r8d, %r8d
movzbl 0x4dc(%r14,%r8), %r9d
movl 0x2a8(%r14,%r9,4), %r11d
leal 0x1(%r11), %ebx
movl %ebx, 0x2a8(%r14,%r9,4)
movb %r8b, 0x2dc(%r14,%r11,2)
movb %r9b, 0x2dd(%r14,%r11,2)
incq %r8
cmpq %r8, %rcx
jne 0xdbb2
incl %edi
movl $0x0, 0x2a8(%r14)
cmpl $-0x3, %eax
ja 0xdc26
movl %edx, %r8d
decq %r8
xorl %r9d, %r9d
xorl %ebx, %ebx
movl 0x274(%r14,%r9,4), %r11d
leal (%rsi,%r9), %ecx
shll %cl, %r11d
addl %ebx, %r11d
movl %ebx, 0x4(%r14,%r9,4)
incq %r9
movl %r11d, %ebx
cmpq %r9, %r8
jne 0xdc04
cmpl %edi, %r10d
jae 0xdc64
movl %r10d, %ecx
leaq 0x4(%r14), %rsi
imulq $0x34, %rcx, %r8
movl %edx, %edx
decq %rdx
cmpl $-0x3, %eax
ja 0xdc59
movq %rdx, %r9
movq %rsi, %rbx
movl (%rbx), %r11d
shrl %cl, %r11d
movl %r11d, (%rbx,%r8)
addq $0x4, %rbx
decq %r9
jne 0xdc46
incq %rcx
addq $0x34, %r8
cmpl %ecx, %edi
jne 0xdc3b
movl 0x30(%r14), %eax
movl %eax, 0xf0(%rsp)
movdqu (%r14), %xmm0
movdqu 0x10(%r14), %xmm1
movdqu 0x20(%r14), %xmm2
movdqa %xmm2, 0xe0(%rsp)
movdqa %xmm1, 0xd0(%rsp)
movdqa %xmm0, 0xc0(%rsp)
movl 0x14(%rsp), %r11d
testl %r11d, %r11d
je 0xe080
movl 0x18(%rsp), %eax
subl %ebp, %eax
movq %rax, 0x70(%rsp)
movl %r11d, %r9d
movq 0x40(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x48(%rsp)
xorl %edi, %edi
movdqa 0x5401(%rip), %xmm0     # 0x130d0
movdqa 0x5409(%rip), %xmm1     # 0x130e0
movdqa 0x5411(%rip), %xmm2     # 0x130f0
pcmpeqd %xmm3, %xmm3
movdqa 0x6205(%rip), %xmm4     # 0x13ef0
movl %ebp, 0x34(%rsp)
movl %r10d, 0x30(%rsp)
movq %r9, 0x68(%rsp)
movq 0x50(%rsp), %rax
movzbl (%rax,%rdi,2), %r15d
movzbl 0x1(%rax,%rdi,2), %r12d
movl 0x18(%rsp), %eax
movl %eax, %ebx
subl %r12d, %ebx
movl 0xc0(%rsp,%r12,4), %r8d
movl %ebp, %edx
subl %ebx, %edx
movl $0x1, %eax
movl %edx, %ecx
shll %cl, %eax
cmpl %r10d, %edx
jae 0xde31
addl %r8d, %eax
cmpl %eax, %r8d
jae 0xe06c
movzbl %bl, %ecx
shll $0x10, %ecx
addl %r15d, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
movl %eax, %esi
subq %r8, %rsi
leaq 0x3(%rsi), %rdx
andq $-0x4, %rdx
decq %rsi
movq %rsi, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movq 0x48(%rsp), %rsi
leaq (%rsi,%r8,4), %r8
pxor %xmm2, %xmm5
xorl %ebx, %ebx
movq %rbx, %xmm6
pshufd $0x44, %xmm6, %xmm6     # xmm6 = xmm6[0,1,0,1]
movdqa %xmm6, %xmm7
por %xmm1, %xmm7
pxor %xmm2, %xmm7
movdqa %xmm7, %xmm8
pcmpgtd %xmm5, %xmm8
pcmpeqd %xmm5, %xmm7
pshufd $0xf5, %xmm7, %xmm9     # xmm9 = xmm7[1,1,3,3]
pand %xmm8, %xmm9
pshufd $0xf5, %xmm8, %xmm7     # xmm7 = xmm8[1,1,3,3]
por %xmm9, %xmm7
movd %xmm7, %esi
notl %esi
testb $0x1, %sil
je 0xddbf
movl %ecx, -0xc(%r8,%rbx,4)
pxor %xmm3, %xmm7
pextrw $0x4, %xmm7, %esi
testb $0x1, %sil
je 0xddd3
movl %ecx, -0x8(%r8,%rbx,4)
por %xmm0, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm5, %xmm7
pcmpeqd %xmm5, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm3, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0xde10
movl %ecx, -0x4(%r8,%rbx,4)
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xde1f
movl %ecx, (%r8,%rbx,4)
addq $0x4, %rbx
cmpq %rbx, %rdx
jne 0xdd74
jmp 0xe06c
movq %r8, 0x20(%rsp)
movq %r12, 0x78(%rsp)
movq 0x70(%rsp), %rcx
leal (%rbx,%rcx), %esi
cmpl $0x2, %esi
movl $0x1, %ecx
cmovgel %esi, %ecx
movl 0x2a4(%r14,%rcx,4), %r11d
movl %ebx, %r8d
imulq $0x34, %r8, %r8
movl 0x30(%r14,%r8), %r9d
movl %r9d, 0xb0(%rsp)
movdqu (%r14,%r8), %xmm5
movdqu 0x10(%r14,%r8), %xmm6
movdqu 0x20(%r14,%r8), %xmm7
movdqa %xmm7, 0xa0(%rsp)
movdqa %xmm6, 0x90(%rsp)
movdqa %xmm5, 0x80(%rsp)
cmpl $0x2, %esi
jl 0xdfc1
movl 0x80(%rsp,%rcx,4), %ecx
testq %rcx, %rcx
je 0xdfc1
movzbl %bl, %esi
shll $0x10, %esi
leal (%rsi,%r15), %r12d
addl $0x1000000, %r12d       # imm = 0x1000000
leaq -0x1(%rcx), %rsi
movq %rsi, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movq 0x48(%rsp), %rsi
movq 0x20(%rsp), %r8
leaq (%rsi,%r8,4), %r13
leaq 0xc(,%rcx,4), %r8
andq $-0x10, %r8
xorl %ecx, %ecx
movdqa %xmm1, %xmm6
movdqa %xmm0, %xmm7
movdqa %xmm5, %xmm8
pxor %xmm2, %xmm8
movdqa %xmm6, %xmm9
pxor %xmm2, %xmm9
movdqa %xmm9, %xmm10
pcmpgtd %xmm8, %xmm10
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm11    # xmm11 = xmm9[1,1,3,3]
pand %xmm10, %xmm11
pshufd $0xf5, %xmm10, %xmm9    # xmm9 = xmm10[1,1,3,3]
por %xmm11, %xmm9
movd %xmm9, %esi
notl %esi
testb $0x1, %sil
je 0xdf40
movl %r12d, -0xc(%r13,%rcx)
pxor %xmm3, %xmm9
pextrw $0x4, %xmm9, %esi
testb $0x1, %sil
je 0xdf56
movl %r12d, -0x8(%r13,%rcx)
movdqa %xmm7, %xmm9
pxor %xmm2, %xmm9
movdqa %xmm9, %xmm10
pcmpgtd %xmm8, %xmm10
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
pand %xmm10, %xmm9
pshufd $0xf5, %xmm10, %xmm8    # xmm8 = xmm10[1,1,3,3]
por %xmm9, %xmm8
pxor %xmm3, %xmm8
pextrw $0x0, %xmm8, %esi
testb $0x1, %sil
je 0xdf9b
movl %r12d, -0x4(%r13,%rcx)
pextrw $0x4, %xmm8, %esi
testb $0x1, %sil
je 0xdfac
movl %r12d, (%r13,%rcx)
paddq %xmm4, %xmm6
paddq %xmm4, %xmm7
addq $0x10, %rcx
cmpq %rcx, %r8
jne 0xdef5
cmpl %r11d, 0x14(%rsp)
je 0xe055
movl 0x14(%rsp), %ecx
subl %r11d, %ecx
movq 0x60(%rsp), %rsi
movq 0x20(%rsp), %r8
leaq (%rsi,%r8,4), %r8
movq 0x50(%rsp), %rsi
leaq (%rsi,%r11,2), %r12
movl %ecx, %r13d
xorl %esi, %esi
movzbl (%r12,%rsi,2), %r11d
movzbl 0x1(%r12,%rsi,2), %ebp
movl 0x18(%rsp), %r10d
subl %ebp, %r10d
movl %edx, %ecx
subl %r10d, %ecx
movl $0x1, %r9d
shll %cl, %r9d
movl 0x80(%rsp,%rbp,4), %ecx
addl %ecx, %r9d
shll $0x8, %r11d
addl %ebx, %r10d
movzbl %r10b, %r10d
shll $0x10, %r10d
orl %r11d, %r10d
leal (%r15,%r10), %r11d
addl $0x2000000, %r11d       # imm = 0x2000000
movl %ecx, %r10d
incl %ecx
movl %r11d, (%r8,%r10,4)
cmpl %r9d, %ecx
jb 0xe037
movl %r9d, 0x80(%rsp,%rbp,4)
incq %rsi
cmpq %r13, %rsi
jne 0xdfef
addl 0x20(%rsp), %eax
movl 0x34(%rsp), %ebp
movl 0x30(%rsp), %r10d
movq 0x68(%rsp), %r9
movq 0x78(%rsp), %r12
movl %eax, 0xc0(%rsp,%r12,4)
incq %rdi
cmpq %r9, %rdi
jne 0xdcf9
movq 0x40(%rsp), %rax
movl 0x1c(%rsp), %ecx
movb %cl, (%rax)
movb $0x1, 0x1(%rax)
movb %cl, 0x2(%rax)
movl 0x2c(%rsp), %ecx
movb %cl, 0x3(%rax)
movq 0x58(%rsp), %r12
jmp 0xe0a3
movq %rax, %r12
movq %r12, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq