// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/../lib/bitstream.h
// Function: BIT_initDStream
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 %rdx, %rdx
je 0x74ce
movq %rdx, %rax
movq %rsi, 0x18(%rdi)
leaq 0x8(%rsi), %rcx
movq %rcx, 0x20(%rdi)
cmpq $0x8, %rdx
jb 0x74e4
leaq (%rsi,%rax), %rcx
addq $-0x8, %rcx
movq %rcx, 0x10(%rdi)
movq (%rcx), %rdx
movq %rdx, (%rdi)
movzbl 0x7(%rcx), %ecx
testl %ecx, %ecx
je 0x7578
bsrl %ecx, %ecx
notl %ecx
addl $0x9, %ecx
jmp 0x7574
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
andq $0x0, 0x20(%rdi)
pushq $-0x3
jmp 0x7586
movq %rsi, 0x10(%rdi)
movzbl (%rsi), %ecx
movq %rcx, (%rdi)
leaq -0x2(%rax), %rdx
cmpq $0x5, %rdx
ja 0x7559
leaq 0x9a01(%rip), %r8       # 0x10f00
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
movzbl 0x6(%rsi), %edx
shlq $0x30, %rdx
orq %rdx, %rcx
movq %rcx, (%rdi)
movzbl 0x5(%rsi), %edx
shlq $0x28, %rdx
addq %rdx, %rcx
movq %rcx, (%rdi)
movzbl 0x4(%rsi), %edx
shlq $0x20, %rdx
addq %rdx, %rcx
movq %rcx, (%rdi)
movzbl 0x3(%rsi), %edx
shll $0x18, %edx
addq %rdx, %rcx
movq %rcx, (%rdi)
movzbl 0x2(%rsi), %edx
shll $0x10, %edx
addq %rdx, %rcx
movq %rcx, (%rdi)
movzbl 0x1(%rsi), %edx
shll $0x8, %edx
addq %rcx, %rdx
movq %rdx, (%rdi)
movzbl -0x1(%rsi,%rax), %ecx
testl %ecx, %ecx
je 0x7580
bsrl %ecx, %ecx
xorl $0x1f, %ecx
leal (,%rax,8), %edx
subl %edx, %ecx
addl $0x29, %ecx
movl %ecx, 0x8(%rdi)
retq
andl $0x0, 0x8(%rdi)
pushq $-0x1
jmp 0x7586
andl $0x0, 0x8(%rdi)
pushq $-0x4
popq %rax
retq