// File: /workspace/github_c_makefile_star2_O3/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 0x16edb(%rip), %r12     # 0x271b4
leaq 0x19d70(%rip), %rsi     # 0x2a050
leaq 0x19f5e(%rip), %rdx     # 0x2a245
xorl %r13d, %r13d
movq %r12, %rdi
xorl %eax, %eax
callq 0x4a56
movq %r14, -0x30(%rbp)
movl (%r14), %r15d
leaq 0x194a6(%rip), %rsi     # 0x297a8
leaq 0x19f5a(%rip), %rdx     # 0x2a263
movq %r12, %rdi
xorl %eax, %eax
callq 0x4a56
testl %r15d, %r15d
jle 0x10339
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x10339
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 0x104aa
movq 0x8(%rax), %rax
movslq %r13d, %rcx
movl (%rax,%rcx,8), %r15d
movl 0x4(%rax,%rcx,8), %r12d
leaq 0x19ef3(%rip), %rdi     # 0x2a251
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4a56
testl %r12d, %r12d
js 0x103c8
movl 0x18(%rbx), %ecx
movl %ecx, %eax
subl %r12d, %eax
testl %eax, %eax
jg 0x103ad
movq 0x8(%rbx), %rdx
cmpl $-0x6, %eax
movl $0xfffffff9, %esi       # imm = 0xFFFFFFF9
cmovgel %eax, %esi
movl %r12d, %edi
subl %ecx, %edi
leal (%rdi,%rsi), %ecx
addl $0x7, %ecx
movl %ecx, %esi
shrl $0x3, %esi
andl $-0x8, %ecx
addq %rsi, %rdx
incq %rdx
addl %ecx, %eax
addl $0x8, %eax
movq %rdx, 0x8(%rbx)
movl %eax, 0x18(%rbx)
leaq 0x19eb4(%rip), %rdi     # 0x2a26b
movl %r12d, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4a56
jmp 0x104b0
movl $0x6, %r13d
leaq 0x19e7c(%rip), %rdi     # 0x2a251
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x4a56
decl %r13d
je 0x104aa
movq -0x30(%rbp), %rax
movl (%rax), %esi
movl 0x18(%rbx), %ecx
movl %ecx, %eax
subl %esi, %eax
testl %eax, %eax
jg 0x1042f
movq 0x8(%rbx), %rdx
cmpl $-0x6, %eax
movl $0xfffffff9, %edi       # imm = 0xFFFFFFF9
cmovgel %eax, %edi
movl %esi, %r8d
subl %ecx, %r8d
leal (%r8,%rdi), %ecx
addl $0x7, %ecx
movl %ecx, %edi
shrl $0x3, %edi
andl $-0x8, %ecx
addq %rdi, %rdx
incq %rdx
addl %ecx, %eax
addl $0x8, %eax
movq %rdx, 0x8(%rbx)
movl %eax, 0x18(%rbx)
xorl %r14d, %r14d
leaq 0x19e2f(%rip), %rdi     # 0x2a26b
xorl %edx, %edx
xorl %eax, %eax
callq 0x4a56
leaq 0x16d68(%rip), %rdi     # 0x271b4
leaq 0x19355(%rip), %rsi     # 0x297a8
leaq 0x19e09(%rip), %rdx     # 0x2a263
xorl %eax, %eax
callq 0x4a56
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
jae 0x1047f
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 0x104aa
movq 0x8(%rax), %rax
movslq %r14d, %rcx
movl (%rax,%rcx,8), %r15d
movl 0x4(%rax,%rcx,8), %r12d
testl %r12d, %r12d
js 0x103ce
jmp 0x10370
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop