// File: /workspace/github_c_makefile_star2_O1/akumrao[P]videoAnalyzer/decoder/macroblock.c
// Function: bs_read_vlc(bs_s*, x264_vlc_table_t*)
static int bs_read_vlc(bs_t *s, x264_vlc_table_t *table) {LOG_CALL;
    int i_nb_bits;
    int i_value = 0;
    int i_bits;
    int i_index;
    int i_level = 0;

    i_index = bs_show(s, table->i_lookup_bits);
    if (i_index >= table->i_lookup)
    {
        return ( -1);
    }
    i_value = table->lookup[i_index].i_value;
    i_bits = table->lookup[i_index].i_size;

    myPrintf( "bits=%d, value=%d", i_bits, i_value);
    
    while (i_bits < 0)
    {
        myPrintf( "bits=%d, value=%d", i_bits, i_value);
        
        i_level++;
        if (i_level > 5)
        {
            return ( -1); // FIXME what to do ?
        }
        bs_skip(s, table->i_lookup_bits);
        i_nb_bits = -i_bits;

        i_index = bs_show(s, i_nb_bits) + i_value;
        if (i_index >= table->i_lookup)
        {
            return ( -1);
        }
        i_value = table->lookup[i_index].i_value;
        i_bits = table->lookup[i_index].i_size;
    }
    bs_skip(s, i_bits);

    return ( i_value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x14ce9(%rip), %r12     # 0x251b4
leaq 0x17d8a(%rip), %rsi     # 0x2825c
leaq 0x17f78(%rip), %rdx     # 0x28451
xorl %r13d, %r13d
movq %r12, %rdi
xorl %eax, %eax
callq 0x4c22
movq %r14, -0x30(%rbp)
movl (%r14), %r15d
leaq 0x173c4(%rip), %rsi     # 0x278b8
leaq 0x17f74(%rip), %rdx     # 0x2846f
movq %r12, %rdi
xorl %eax, %eax
callq 0x4c22
testl %r15d, %r15d
jle 0x1052b
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x1052b
movl (%rax), %r13d
bswapl %r13d
movb $0x8, %cl
subb 0x18(%rbx), %cl
shll %cl, %r13d
negb %r15b
movl %r15d, %ecx
shrl %cl, %r13d
movq -0x30(%rbp), %rax
cmpl 0x4(%rax), %r13d
jge 0x10695
movq 0x8(%rax), %rax
movslq %r13d, %rcx
movl (%rax,%rcx,8), %r15d
movl 0x4(%rax,%rcx,8), %r12d
leaq 0x17f0d(%rip), %rdi     # 0x2845d
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4c22
testl %r12d, %r12d
js 0x105b8
movl 0x18(%rbx), %ecx
movl %ecx, %eax
subl %r12d, %eax
jg 0x1059d
cmpl $-0x6, %eax
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
cmovgel %eax, %edx
movl %r12d, %esi
subl %ecx, %esi
leal (%rsi,%rdx), %ecx
addl $0x7, %ecx
movl %ecx, %edx
andl $-0x8, %edx
shrl $0x3, %ecx
movq 0x8(%rbx), %rsi
addq %rsi, %rcx
incq %rcx
addl %edx, %eax
addl $0x8, %eax
movq %rcx, 0x8(%rbx)
movl %eax, 0x18(%rbx)
leaq 0x17ed0(%rip), %rdi     # 0x28477
movl %r12d, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4c22
jmp 0x1069b
movl $0x6, %r13d
leaq 0x17e98(%rip), %rdi     # 0x2845d
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4c22
decl %r13d
je 0x10695
movq -0x30(%rbp), %rax
movl (%rax), %esi
movl 0x18(%rbx), %ecx
movl %ecx, %eax
subl %esi, %eax
jg 0x1061a
cmpl $-0x6, %eax
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
cmovgel %eax, %edx
movl %esi, %edi
subl %ecx, %edi
leal (%rdi,%rdx), %ecx
addl $0x7, %ecx
movl %ecx, %edx
andl $-0x8, %edx
shrl $0x3, %ecx
movq 0x8(%rbx), %rdi
addq %rdi, %rcx
incq %rcx
addl %edx, %eax
addl $0x8, %eax
movq %rcx, 0x8(%rbx)
movl %eax, 0x18(%rbx)
xorl %r14d, %r14d
leaq 0x17e50(%rip), %rdi     # 0x28477
xorl %edx, %edx
xorl %eax, %eax
callq 0x4c22
leaq 0x14b7d(%rip), %rdi     # 0x251b4
leaq 0x1727a(%rip), %rsi     # 0x278b8
leaq 0x17e2a(%rip), %rdx     # 0x2846f
xorl %eax, %eax
callq 0x4c22
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x1066a
movl (%rax), %r14d
bswapl %r14d
movb $0x8, %cl
subb 0x18(%rbx), %cl
shll %cl, %r14d
movl %r12d, %ecx
shrl %cl, %r14d
addl %r15d, %r14d
movq -0x30(%rbp), %rax
cmpl 0x4(%rax), %r14d
jge 0x10695
movq 0x8(%rax), %rax
movslq %r14d, %rcx
movl (%rax,%rcx,8), %r15d
movl 0x4(%rax,%rcx,8), %r12d
testl %r12d, %r12d
js 0x105be
jmp 0x10562
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)