// File: /workspace/github_cpp_makefile_star2_O1/lukasz-wiecaszek[P]h264iframedecoder/./istream.hpp
// Function: ymn::istream<0>::read_bits(unsigned int, unsigned int&)
bool read_bits(uint32_t number_of_bits, uint32_t& value)
    {
        assert(number_of_bits <= 32);

        /* verify whether we don't go beyond size of the stream */
        if ((m_position.to_bits() + number_of_bits) <= (m_size * BITS_PER_BYTE)) {

            uint32_t v = 0;
            uint32_t bits_remaining = number_of_bits;
            uint32_t bits_to_read;

            while (bits_remaining > 0) {
                /* there is more bits to be read than bits left in current byte */
                if ((m_position.m_bit_position + bits_remaining) >= BITS_PER_BYTE ) {
                    /* number of bits left in current byte */
                    bits_to_read = BITS_PER_BYTE - m_position.m_bit_position;

                    /* shift the result by number of bits to be read
                    to make room for new data */
                    v <<= bits_to_read;
                    /* add to the result value */
                    v |= m_buffer[m_position.m_byte_position] & ((1U << bits_to_read) - 1);

                    /* move to the next byte in the stream */
                    m_position.m_byte_position++;
                    /* and reset bit position to the begining of a byte */
                    m_position.m_bit_position = 0;
                }
                else {
                    /* there remains less than 8 bits to be read */
                    bits_to_read = bits_remaining;

                    /* shift the result by number of bits to be read
                    to make room for new data */
                    v <<= bits_to_read;

                    /* advance bit position */
                    m_position.m_bit_position += bits_to_read;

                    /* add to the result value */
                    v |= (m_buffer[m_position.m_byte_position] >> (BITS_PER_BYTE - m_position.m_bit_position)) & ((1U << bits_to_read) - 1);
                }

                /* decrease number of remaining bits by number of bits read in this iteration */
                bits_remaining -= bits_to_read;
          }

          value = v;
          return true;
       }
       else {
            m_status |= ISTREAM_STATUS_EOS_REACHED;
            if (m_error_function)
                m_error_function(m_position, m_position + number_of_bits);
            return false;
       }
    }

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
cmpl $0x21, %esi
jae 0x71a8
movq %rdi, %rax
movq 0x8(%rdi), %rbx
movl %esi, %ecx
addq 0x18(%rdi), %rcx
movq 0x10(%rdi), %r8
leaq (%rcx,%r8,8), %r14
shlq $0x3, %rbx
cmpq %rbx, %r14
ja 0x7159
testl %esi, %esi
je 0x7195
movq (%rax), %r8
movq 0x10(%rax), %r9
movq 0x18(%rax), %r11
xorl %edi, %edi
movl %esi, %r10d
addq %r11, %r10
cmpq $0x8, %r10
jb 0x7129
movl $0x8, %ecx
subl %r11d, %ecx
shll %cl, %edi
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
movzbl (%r8,%r9), %r11d
notl %r10d
andl %r11d, %r10d
orl %r10d, %edi
incq %r9
movq %r9, 0x10(%rax)
movq $0x0, 0x18(%rax)
xorl %r10d, %r10d
jmp 0x7150
movl %esi, %ecx
shll %cl, %edi
movq %r10, 0x18(%rax)
movzbl (%r8,%r9), %r11d
movb $0x8, %cl
subb %r10b, %cl
shrl %cl, %r11d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %ebp
notl %ebp
andl %r11d, %ebp
orl %ebp, %edi
movl %esi, %ecx
movq %r10, %r11
subl %ecx, %esi
jne 0x70e8
jmp 0x7197
orb $0x1, 0x20(%rax)
cmpq $0x0, 0x38(%rax)
je 0x7199
leaq 0x10(%rax), %rsi
leaq 0x28(%rax), %rdi
movq %rcx, %rdx
shrq $0x3, %rdx
addq %r8, %rdx
movabsq $0x1fffffffffffffff, %r8 # imm = 0x1FFFFFFFFFFFFFFF
andq %rdx, %r8
andl $0x7, %ecx
movq %rsp, %rdx
movq %r8, (%rdx)
movq %rcx, 0x8(%rdx)
callq *0x40(%rax)
jmp 0x7199
xorl %edi, %edi
movl %edi, (%rdx)
cmpq %rbx, %r14
setbe %al
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x12bc2(%rip), %rdi     # 0x19d71
leaq 0x12bd0(%rip), %rsi     # 0x19d86
leaq 0x12c24(%rip), %rcx     # 0x19de1
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x20f0