// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_decompress.c
// Function: HUF_readDTableX1_wksp
size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize)
{
    U32 tableLog = 0;
    U32 nbSymbols = 0;
    size_t iSize;
    void* const dtPtr = DTable + 1;
    HUF_DEltX1* const dt = (HUF_DEltX1*)dtPtr;

    U32* rankVal;
    BYTE* huffWeight;
    size_t spaceUsed32 = 0;

    rankVal = (U32 *)workSpace + spaceUsed32;
    spaceUsed32 += HUF_TABLELOG_ABSOLUTEMAX + 1;
    huffWeight = (BYTE *)((U32 *)workSpace + spaceUsed32);
    spaceUsed32 += HUF_ALIGN(HUF_SYMBOLVALUE_MAX + 1, sizeof(U32)) >> 2;

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

    DEBUG_STATIC_ASSERT(sizeof(DTableDesc) == sizeof(HUF_DTable));
    /* memset(huffWeight, 0, sizeof(huffWeight)); */   /* is not necessary, even though some analyzer complain ... */

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

    /* Table header */
    {   DTableDesc dtd = HUF_getDTableDesc(DTable);
        if (tableLog > (U32)(dtd.maxTableLog+1)) return ERROR(tableLog_tooLarge);   /* DTable too small, Huffman tree cannot fit in */
        dtd.tableType = 0;
        dtd.tableLog = (BYTE)tableLog;
        memcpy(DTable, &dtd, sizeof(dtd));
    }

    /* Calculate starting value for each rank */
    {   U32 n, nextRankStart = 0;
        for (n=1; n<tableLog+1; n++) {
            U32 const current = nextRankStart;
            nextRankStart += (rankVal[n] << (n-1));
            rankVal[n] = current;
    }   }

    /* fill DTable */
    {   U32 n;
        size_t const nEnd = nbSymbols;
        for (n=0; n<nEnd; n++) {
            size_t const w = huffWeight[n];
            size_t const length = (1 << w) >> 1;
            size_t const uStart = rankVal[w];
            size_t const uEnd = uStart + length;
            size_t u;
            HUF_DEltX1 D;
            D.byte = (BYTE)n;
            D.nbBits = (BYTE)(tableLog + 1 - w);
            rankVal[w] = (U32)uEnd;
            if (length < 4) {
                /* Use length in the loop bound so the compiler knows it is short. */
                for (u = 0; u < length; ++u)
                    dt[uStart + u] = D;
            } else {
                /* Unroll the loop 4 times, we know it is a power of 2. */
                for (u = uStart; u < uEnd; u += 4) {
                    dt[u + 0] = D;
                    dt[u + 1] = D;
                    dt[u + 2] = D;
                    dt[u + 3] = D;
    }   }   }   }
    return iSize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shlq $0x2, %rax
cmpq -0x30(%rbp), %rax
jbe 0x179e2
movq $-0x5, -0x8(%rbp)
jmp 0x17c61
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %r9
movq -0x20(%rbp), %rax
movl $0x100, %esi            # imm = 0x100
leaq -0x38(%rbp), %rcx
leaq -0x34(%rbp), %r8
movq %rax, (%rsp)
callq 0xe940
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x17c70
cmpl $0x0, %eax
je 0x17a27
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x17c61
movq -0x10(%rbp), %rdi
callq 0x17c90
movl %eax, -0x6c(%rbp)
movl -0x34(%rbp), %eax
movzbl -0x6c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jbe 0x17a4e
movq $-0x5, -0x8(%rbp)
jmp 0x17c61
movb $0x0, -0x6b(%rbp)
movl -0x34(%rbp), %eax
movb %al, -0x6a(%rbp)
movq -0x10(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, (%rax)
movl $0x0, -0x74(%rbp)
movl $0x1, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x17ab2
movl -0x74(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movl -0x70(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl -0x70(%rbp), %ecx
subl $0x1, %ecx
shll %cl, %eax
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x78(%rbp), %edx
movq -0x58(%rbp), %rax
movl -0x70(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x17a6f
movl -0x38(%rbp), %eax
movq %rax, -0x88(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpq -0x88(%rbp), %rax
jae 0x17c59
movq -0x60(%rbp), %rax
movl -0x7c(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
sarl %eax
cltq
movq %rax, -0x98(%rbp)
movq -0x58(%rbp), %rax
movq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
addq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x7c(%rbp), %eax
movb %al, -0xb2(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
subq -0x90(%rbp), %rax
movb %al, -0xb1(%rbp)
movq -0xa8(%rbp), %rax
movl %eax, %edx
movq -0x58(%rbp), %rax
movq -0x90(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpq $0x4, -0x98(%rbp)
jae 0x17bba
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x17bb5
movq -0x50(%rbp), %rax
movq -0xa0(%rbp), %rcx
addq -0xb0(%rbp), %rcx
movw -0xb2(%rbp), %dx
movw %dx, (%rax,%rcx,2)
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0x17b74
jmp 0x17c49
movq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jae 0x17c47
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
movw -0xb2(%rbp), %dx
movw %dx, (%rax,%rcx,2)
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
movw -0xb2(%rbp), %dx
movw %dx, 0x2(%rax,%rcx,2)
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
movw -0xb2(%rbp), %dx
movw %dx, 0x4(%rax,%rcx,2)
movq -0x50(%rbp), %rax
movq -0xb0(%rbp), %rcx
movw -0xb2(%rbp), %dx
movw %dx, 0x6(%rax,%rcx,2)
movq -0xb0(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xb0(%rbp)
jmp 0x17bc8
jmp 0x17c49
jmp 0x17c4b
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x17ac3
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nop