// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x1, -0x20(%rbp)
jae 0x10588
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x10c0
movq $-0x3, -0x8(%rbp)
jmp 0x10788
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x8, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpq $0x8, -0x20(%rbp)
jb 0x1063c
movq -0x18(%rbp), %rcx
addq -0x20(%rbp), %rcx
addq $-0x8, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x109f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
je 0x10610
movzbl -0x21(%rbp), %edi
callq 0xf900
movl %eax, %ecx
movl $0x8, %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x10617
xorl %eax, %eax
movl %eax, -0x28(%rbp)
jmp 0x10617
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x10637
movq $-0x1, -0x8(%rbp)
jmp 0x10788
jmp 0x10780
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movzbl (%rcx), %ecx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
addq $-0x2, %rax
movq %rax, -0x30(%rbp)
subq $0x5, %rax
ja 0x10710
movq -0x30(%rbp), %rax
leaq 0x16919(%rip), %rcx     # 0x26f90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movzbl 0x6(%rax), %eax
movl %eax, %ecx
shlq $0x30, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, %ecx
shlq $0x28, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
movl %eax, %ecx
shlq $0x20, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x3(%rax), %eax
movl %eax, %ecx
shlq $0x18, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, %ecx
shlq $0x10, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, %ecx
shlq $0x8, %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x10712
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movb (%rax,%rcx), %al
movb %al, -0x22(%rbp)
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
je 0x10744
movzbl -0x22(%rbp), %edi
callq 0xf900
movl %eax, %ecx
movl $0x8, %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
jmp 0x1074b
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0x1074b
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
jne 0x10768
movq $-0x4, -0x8(%rbp)
jmp 0x10788
movl $0x8, %eax
subq -0x20(%rbp), %rax
movl %eax, %ecx
shll $0x3, %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)