// File: /workspace/github_c_makefile_star2_O3/Cyan4973[P]FiniteStateEntropy/programs/../lib/bitstream.h
// Function: HUF_decompress1X2_usingDTable_internal_bmi2
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
{
    if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }

    bitD->start = (const char*)srcBuffer;
    bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);

    if (srcSize >=  sizeof(bitD->bitContainer)) {  /* normal case */
        bitD->ptr   = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
        bitD->bitContainer = MEM_readLEST(bitD->ptr);
        { BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
          bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;  /* ensures bitsConsumed is always set */
          if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
    } else {
        bitD->ptr   = bitD->start;
        bitD->bitContainer = *(const BYTE*)(bitD->start);
        switch(srcSize)
        {
        case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
                /* fall-through */

        case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
                /* fall-through */

        case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
                /* fall-through */

        case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
                /* fall-through */

        case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
                /* fall-through */

        case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) <<  8;
                /* fall-through */

        default: break;
        }
        {   BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
            bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
            if (lastByte == 0) return ERROR(corruption_detected);  /* endMark not present */
        }
        bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
    }

    return srcSize;
}

// Assembly:
testq %rcx, %rcx
je 0x1135d
movq %rcx, %rax
cmpq $0x8, %rcx
jb 0x11365
movzbl -0x1(%rdx,%rax), %r9d
testl %r9d, %r9d
je 0x1151e
cmpq $-0x9, %rax
ja 0x1165e
movq -0x8(%rdx,%rax), %rcx
addq $-0x8, %rax
bsrl %r9d, %r11d
notl %r11d
addl $0x9, %r11d
jmp 0x113ee
movq $-0x3, %rax
retq
movzbl (%rdx), %ecx
leaq -0x2(%rax), %r9
cmpq $0x5, %r9
ja 0x113cb
leaq 0x3f7f(%rip), %r10      # 0x152f8
movslq (%r10,%r9,4), %r9
addq %r10, %r9
jmpq *%r9
movzbl 0x6(%rdx), %r9d
shlq $0x30, %r9
orq %r9, %rcx
movzbl 0x5(%rdx), %r9d
shlq $0x28, %r9
addq %r9, %rcx
movzbl 0x4(%rdx), %r9d
shlq $0x20, %r9
addq %r9, %rcx
movzbl 0x3(%rdx), %r9d
shll $0x18, %r9d
addq %r9, %rcx
movzbl 0x2(%rdx), %r9d
shll $0x10, %r9d
addq %r9, %rcx
movzbl 0x1(%rdx), %r9d
shll $0x8, %r9d
addq %r9, %rcx
movzbl -0x1(%rdx,%rax), %r9d
testl %r9d, %r9d
je 0x11526
bsrl %r9d, %r11d
xorl $0x1f, %r11d
shll $0x3, %eax
subl %eax, %r11d
addl $0x29, %r11d
xorl %eax, %eax
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq (%rdi,%rsi), %r10
movzwl 0x2(%r8), %r9d
negl %r9d
andl $0x3f, %r9d
cmpl $0x40, %r11d
ja 0x11530
leaq (%rdi,%rsi), %rbx
addq $-0x7, %rbx
cmpq $0x8, %rax
jge 0x1144d
testq %rax, %rax
je 0x1152e
leaq (%rdx,%rax), %r14
movl %r11d, %ecx
shrl $0x3, %ecx
subq %rcx, %r14
cmpq %rdx, %r14
setae %bpl
cmovbl %eax, %ecx
leal (,%rcx,8), %r14d
subl %r14d, %r11d
jmp 0x1145a
movl %r11d, %ecx
shrl $0x3, %ecx
andl $0x7, %r11d
movb $0x1, %bpl
movl %ecx, %ecx
subq %rcx, %rax
movq (%rdx,%rax), %rcx
cmpq %rbx, %rdi
jae 0x11530
testb %bpl, %bpl
je 0x11530
shlxq %r11, %rcx, %r14
shrxq %r9, %r14, %r14
movzwl 0x4(%r8,%r14,4), %ebp
movw %bp, (%rdi)
movzbl 0x6(%r8,%r14,4), %r15d
addl %r11d, %r15d
movzbl 0x7(%r8,%r14,4), %r11d
leaq (%rdi,%r11), %r14
shlxq %r15, %rcx, %r12
shrxq %r9, %r12, %r12
movzwl 0x4(%r8,%r12,4), %ebp
movw %bp, (%rdi,%r11)
movzbl 0x6(%r8,%r12,4), %edi
addl %r15d, %edi
movzbl 0x7(%r8,%r12,4), %r11d
leaq (%r14,%r11), %r15
shlxq %rdi, %rcx, %r12
shrxq %r9, %r12, %r12
movzwl 0x4(%r8,%r12,4), %ebp
movw %bp, (%r11,%r14)
movzbl 0x6(%r8,%r12,4), %r14d
addl %edi, %r14d
movzbl 0x7(%r8,%r12,4), %edi
leaq (%r15,%rdi), %r12
shlxq %r14, %rcx, %r11
shrxq %r9, %r11, %r13
movzwl 0x4(%r8,%r13,4), %r11d
movw %r11w, (%rdi,%r15)
movzbl 0x6(%r8,%r13,4), %r11d
addl %r14d, %r11d
movzbl 0x7(%r8,%r13,4), %edi
addq %r12, %rdi
cmpl $0x40, %r11d
jbe 0x1141a
jmp 0x11530
movq $-0x1, %rax
retq
movq $-0x4, %rax
retq
xorl %eax, %eax
leaq -0x2(%r10), %rbx
cmpl $0x40, %r11d
ja 0x115c2
cmpq $0x8, %rax
jge 0x1156d
testq %rax, %rax
je 0x115c0
leaq (%rdx,%rax), %r14
movl %r11d, %ecx
shrl $0x3, %ecx
subq %rcx, %r14
cmpq %rdx, %r14
cmovbl %eax, %ecx
setae %bpl
leal (,%rcx,8), %r14d
subl %r14d, %r11d
jmp 0x1157a
movl %r11d, %ecx
shrl $0x3, %ecx
andl $0x7, %r11d
movb $0x1, %bpl
movl %r11d, %r14d
movl %ecx, %ecx
subq %rcx, %rax
movq (%rdx,%rax), %rcx
cmpq %rbx, %rdi
ja 0x115bb
testb %bpl, %bpl
je 0x115bb
shlxq %r14, %rcx, %r11
shrxq %r9, %r11, %r15
movzwl 0x4(%r8,%r15,4), %r11d
movw %r11w, (%rdi)
movzbl 0x6(%r8,%r15,4), %r11d
addl %r14d, %r11d
movzbl 0x7(%r8,%r15,4), %r14d
addq %r14, %rdi
jmp 0x11534
movl %r14d, %r11d
jmp 0x115c2
xorl %eax, %eax
cmpq %rbx, %rdi
jbe 0x115cc
movl %r11d, %edx
jmp 0x115f9
shlxq %r11, %rcx, %rdx
shrxq %r9, %rdx, %r14
movzwl 0x4(%r8,%r14,4), %edx
movw %dx, (%rdi)
movzbl 0x6(%r8,%r14,4), %edx
addl %r11d, %edx
movzbl 0x7(%r8,%r14,4), %r11d
addq %r11, %rdi
movl %edx, %r11d
cmpq %rbx, %rdi
jbe 0x115cc
cmpq %r10, %rdi
jae 0x1163c
shlxq %rdx, %rcx, %rcx
shrxq %r9, %rcx, %rcx
movb 0x4(%r8,%rcx,4), %r9b
movb %r9b, (%rdi)
cmpb $0x1, 0x7(%r8,%rcx,4)
jne 0x11622
movzbl 0x6(%r8,%rcx,4), %ecx
addl %ecx, %edx
jmp 0x1163c
cmpl $0x3f, %edx
ja 0x1163c
movzbl 0x6(%r8,%rcx,4), %ecx
addl %ecx, %edx
cmpl $0x40, %edx
movl $0x40, %ecx
cmovbl %edx, %ecx
movl %ecx, %edx
cmpl $0x40, %edx
movq $-0x4, %rcx
cmovneq %rcx, %rsi
testq %rax, %rax
cmovneq %rcx, %rsi
movq %rsi, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq