// File: /workspace/github_c_makefile_star2_O1/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 0xf33f
movq %rdx, %rax
movq %rsi, 0x18(%rdi)
leaq 0x8(%rsi), %rcx
movq %rcx, 0x20(%rdi)
cmpq $0x8, %rdx
jb 0xf359
leaq (%rsi,%rax), %rcx
addq $-0x8, %rcx
movq %rcx, 0x10(%rdi)
movq (%rcx), %rdx
movq %rdx, (%rdi)
movzbl 0x7(%rcx), %ecx
bsrl %ecx, %edx
notl %edx
addl $0x9, %edx
testl %ecx, %ecx
cmovel %ecx, %edx
movl %edx, 0x8(%rdi)
je 0xf3e6
retq
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq $0x0, 0x20(%rdi)
movq $-0x3, %rax
retq
movq %rsi, 0x10(%rdi)
movzbl (%rsi), %ecx
movq %rcx, (%rdi)
leaq -0x2(%rax), %rdx
cmpq $0x5, %rdx
ja 0xf3bf
leaq 0x4e04(%rip), %r8       # 0x14178
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
movzbl 0x6(%rsi), %edx
shlq $0x30, %rdx
orq %rcx, %rdx
movq %rdx, (%rdi)
movzbl 0x5(%rsi), %ecx
shlq $0x28, %rcx
addq %rcx, (%rdi)
movzbl 0x4(%rsi), %ecx
shlq $0x20, %rcx
addq %rcx, (%rdi)
movzbl 0x3(%rsi), %ecx
shll $0x18, %ecx
addq %rcx, (%rdi)
movzbl 0x2(%rsi), %ecx
shll $0x10, %ecx
addq %rcx, (%rdi)
movzbl 0x1(%rsi), %ecx
shll $0x8, %ecx
addq %rcx, (%rdi)
movzbl -0x1(%rsi,%rax), %edx
bsrl %edx, %ecx
notl %ecx
addl $0x9, %ecx
testl %edx, %edx
cmovel %edx, %ecx
movl %ecx, 0x8(%rdi)
je 0xf3ee
leal (,%rax,8), %edx
subl %edx, %ecx
addl $0x40, %ecx
movl %ecx, 0x8(%rdi)
retq
movq $-0x1, %rax
retq
movq $-0x4, %rax
retq