// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
cmpl $0x21, %esi
jae 0x60ea
movl %esi, %eax
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq 0x10(%rdi), %rdi
movq 0x18(%rbx), %r14
movl %esi, %esi
leaq (%r14,%rsi), %rcx
leaq (%rcx,%rdi,8), %r12
shlq $0x3, %r15
cmpq %r15, %r12
ja 0x60a0
movq (%rbx), %r8
xorl %esi, %esi
pushq $0x8
popq %r9
pushq $-0x1
popq %r10
testl %eax, %eax
je 0x60d5
movl %eax, %r11d
addq %r14, %r11
cmpq $0x8, %r11
jb 0x6072
movl %r9d, %ecx
subl %r14d, %ecx
shll %cl, %esi
movzbl (%r8,%rdi), %r11d
movl %r10d, %ebp
shll %cl, %ebp
notl %ebp
andl %r11d, %ebp
orl %ebp, %esi
incq %rdi
movq %rdi, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
xorl %r11d, %r11d
jmp 0x6099
movl %eax, %ecx
shll %cl, %esi
movq %r11, 0x18(%rbx)
movzbl (%r8,%rdi), %ebp
movb $0x8, %cl
subb %r11b, %cl
shrl %cl, %ebp
movl %r10d, %r14d
movl %eax, %ecx
shll %cl, %r14d
notl %r14d
andl %ebp, %r14d
orl %r14d, %esi
movl %eax, %ecx
subl %ecx, %eax
movq %r11, %r14
jmp 0x6034
orb $0x1, 0x20(%rbx)
cmpq $0x0, 0x38(%rbx)
je 0x60d7
leaq 0x10(%rbx), %r14
addq $0x28, %rbx
movq %r14, %rdi
callq 0x68dd
movq %rsp, %rcx
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
movq %rbx, %rdi
movq %r14, %rsi
movq %rcx, %rdx
callq 0x68ca
jmp 0x60d7
movl %esi, (%rdx)
cmpq %r15, %r12
setbe %al
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xed20(%rip), %rdi      # 0x14e11
leaq 0xed2e(%rip), %rsi      # 0x14e26
leaq 0xed82(%rip), %rcx      # 0x14e81
movl $0x1a4, %edx            # imm = 0x1A4
callq 0x20d0