// File: /workspace/github_c_makefile_star2_O2/akumrao[P]videoAnalyzer/decoder/vlc.c
// Function: vlc_table_create_part(x264_vlc_table_t*, vlc_t const*, int, int, int, int)
static int vlc_table_create_part( x264_vlc_table_t *table, const vlc_t *vlc, int i_lookup_bits, int i_nb_vlc, int i_prefix_code, int i_prefix_length )
{
    int i;
    int i_nb_lookup;
    vlc_lookup_t *lookup;
    int i_table_index;

    i_nb_lookup = 1 << i_lookup_bits;

    i_table_index = vlc_table_realloc( table, i_nb_lookup );
    lookup = &table->lookup[i_table_index];

    for( i = 0; i < i_nb_lookup; i++ )
    {
        lookup[i].i_value  = -1;
        lookup[i].i_size = 0;
    }
            
    for( i = 0; i < i_nb_vlc; i++ )
    {
        int i_bits;
        if( vlc[i].i_size <= 0 )
        {
            continue;
        }

        i_bits = vlc[i].i_size - i_prefix_length;
        if( i_bits > 0 && ( vlc[i].i_bits >> i_bits ) == i_prefix_code )
        {
            if( i_bits <= i_lookup_bits )
            {
                int i_lookup_index;
                int nb;

                i_lookup_index = ( vlc[i].i_bits << ( i_lookup_bits - i_bits ) )%i_nb_lookup;
                nb = 1 << ( i_lookup_bits - i_bits );
                for( nb = 0; nb < (1 << ( i_lookup_bits - i_bits)); nb++ )
                {
                    lookup[i_lookup_index ].i_value = i; /* vlc[i].i_value; */
                    lookup[i_lookup_index ].i_size = i_bits;
                    
                    //printf("1i %d,  size %d , code %d \n", i_lookup_index + extIndex,  lookup[i_lookup_index + extIndex ].i_size, lookup[i_lookup_index + extIndex ].i_value);
                    
                    i_lookup_index++;
                }
            }
            else
            {
                int i_bits_max;
                int i_lookup_index;
                /* need another table */
                i_lookup_index = ( vlc[i].i_bits >> (i_bits - i_lookup_bits ) )%i_nb_lookup;

                i_bits_max =  -lookup[i_lookup_index].i_size;
                if( i_bits_max < i_bits - i_lookup_bits )
                {
                    i_bits_max = i_bits - i_lookup_bits;
                }
                lookup[i_lookup_index].i_size = -i_bits_max;
                
                //myPrintf("2i %d,  size %d , code %d \n", i_lookup_index + extIndex,  lookup[i_lookup_index + extIndex ].i_size, lookup[i_lookup_index + extIndex ].i_value);
                
            }
        }
    }

    /* create other level table */
   
    /* create other level table */  
     //return( i_table_index );
    
    for( i = 0; i < i_nb_lookup; i++ )  
    {  
        if( lookup[i].i_size < 0 )  
        {  
            //myPrintf("3i %d,  size %d , code %d \n", i,  lookup[i].i_size, lookup[i].i_value);
            int i_bits;  
            int i_index;  
            i_bits = -lookup[i].i_size;  
            if( i_bits > i_lookup_bits )  
            {  
                lookup[i].i_size = -i_lookup_bits;  
                i_bits = i_lookup_bits;  
            }  
  
            i_index = vlc_table_create_part( table, vlc, i_bits, i_nb_vlc,  
                                             (i_prefix_code << i_lookup_bits)|i,  
                                              i_lookup_bits+i_prefix_length );  
            lookup = &table->lookup[i_table_index]; // reallocated  
            lookup[i].i_value = i_index;  
        }  
    }  

    return( i_table_index );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r12d
movl %r8d, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
movl %edx, %ecx
movq %rsi, %r13
movq %rdi, %r14
pushq $0x1
popq %rax
movl %eax, %ebx
movl %edx, -0x3c(%rbp)
shll %cl, %ebx
movslq 0x4(%rdi), %r15
leal (%r15,%rbx), %esi
movl %esi, 0x4(%rdi)
movq 0x8(%rdi), %rdi
shll $0x3, %esi
callq 0x35ff
movq %r14, -0x58(%rbp)
movq %rax, 0x8(%r14)
movq %r15, -0x38(%rbp)
leaq (%rax,%r15,8), %rdi
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %r14d
movq %rbx, %r8
cmovgl %ebx, %r14d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rax, %r14
je 0xd05b
movq %rcx, (%rdi,%rax,8)
incq %rax
jmp 0xd04d
movl -0x30(%rbp), %eax
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
xorl %r10d, %r10d
movl -0x3c(%rbp), %r15d
movl -0x2c(%rbp), %ebx
cmpq %r9, %r10
je 0xd0ff
movl 0x4(%r13,%r10,8), %esi
testl %esi, %esi
jle 0xd0bb
subl %r12d, %esi
jle 0xd0bb
movl (%r13,%r10,8), %eax
movl %eax, %edx
movl %esi, %ecx
sarl %cl, %edx
cmpl %ebx, %edx
jne 0xd0bb
movl %esi, %ecx
subl %r15d, %ecx
jle 0xd0c0
sarl %cl, %eax
cltd
idivl %r8d
movslq %edx, %rax
xorl %edx, %edx
subl 0x4(%rdi,%rax,8), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
negl %edx
movl %edx, 0x4(%rdi,%rax,8)
incq %r10
jmp 0xd074
movl %r15d, %ecx
subl %esi, %ecx
shll %cl, %eax
pushq $0x1
popq %rdx
movl %edx, %r11d
shll %cl, %r11d
cltd
idivl %r8d
movslq %edx, %rax
testl %r11d, %r11d
movl $0x0, %ecx
cmovlel %ecx, %r11d
leaq (%rdi,%rax,8), %rax
addq $0x4, %rax
xorl %ecx, %ecx
cmpl %ecx, %r11d
je 0xd0bb
movl %r10d, -0x4(%rax,%rcx,8)
movl %esi, (%rax,%rcx,8)
incq %rcx
jmp 0xd0ed
movl %r15d, %eax
movl %r15d, %ecx
shll %cl, %ebx
movl %ebx, -0x2c(%rbp)
negl %eax
movl %eax, -0x40(%rbp)
addl %r15d, %r12d
movl %r12d, -0x44(%rbp)
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x50(%rbp)
xorl %r12d, %r12d
movq -0x58(%rbp), %rbx
cmpq %r12, %r14
je 0xd17f
movl 0x4(%rdi,%r12,8), %edx
testl %edx, %edx
jns 0xd17a
negl %edx
cmpl %r15d, %edx
jle 0xd14d
movl -0x40(%rbp), %eax
movl %eax, 0x4(%rdi,%r12,8)
movl %r15d, %edx
movl -0x2c(%rbp), %r8d
orl %r12d, %r8d
movq %rbx, %rdi
movq %r13, %rsi
movl -0x30(%rbp), %ecx
movl -0x44(%rbp), %r9d
callq 0xcfe3
movq 0x8(%rbx), %rcx
movq -0x38(%rbp), %rdx
leaq (%rcx,%rdx,8), %rdi
addq -0x50(%rbp), %rcx
movl %eax, (%rcx,%r12,8)
incq %r12
jmp 0xd12d
movq -0x38(%rbp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq