// File: /workspace/github_c_makefile_star2_O1/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, -0x48(%rbp)
movl %r8d, -0x2c(%rbp)
movl %ecx, -0x30(%rbp)
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, %r15
movl $0x1, %ebx
movl $0x1, %r14d
movl %r12d, %ecx
shll %cl, %r14d
movslq 0x4(%rdi), %rcx
movq %rcx, -0x40(%rbp)
leal (%rcx,%r14), %esi
movl %esi, 0x4(%rdi)
movq 0x8(%rdi), %rdi
shll $0x3, %esi
callq 0x4856
movq %r15, -0x58(%rbp)
movq %rax, 0x8(%r15)
movq %r14, %r15
movl %r12d, -0x34(%rbp)
cmpl $0x1f, %r12d
je 0x12e21
cmpl $0x2, %r15d
cmovgel %r15d, %ebx
movq -0x40(%rbp), %rcx
leaq (%rax,%rcx,8), %rcx
addq $0x4, %rcx
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %rsi, -0x4(%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rbx
jne 0x12e14
movq -0x40(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
cmpl $0x0, -0x30(%rbp)
movl -0x48(%rbp), %r12d
movl -0x2c(%rbp), %r14d
jle 0x12ed4
movl -0x30(%rbp), %r8d
movq -0x40(%rbp), %rcx
leaq (%rax,%rcx,8), %r9
addq $0x4, %r9
xorl %r10d, %r10d
movl $0x1, %r11d
movl 0x4(%r13,%r10,8), %esi
testl %esi, %esi
jle 0x12ecc
subl %r12d, %esi
jle 0x12ecc
movl (%r13,%r10,8), %eax
movl %eax, %edx
movl %esi, %ecx
sarl %cl, %edx
cmpl %r14d, %edx
jne 0x12ecc
movl %esi, %ecx
movl -0x34(%rbp), %edx
subl %edx, %ecx
jle 0x12e97
sarl %cl, %eax
cltd
idivl %r15d
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)
jmp 0x12ecc
movl %edx, %ecx
subl %esi, %ecx
cmpl $0x1f, %ecx
je 0x12ecc
movl $0x1, %ebx
shll %cl, %ebx
shll %cl, %eax
cltd
idivl %r15d
movslq %edx, %rax
cmpl $0x2, %ebx
cmovll %r11d, %ebx
leaq (%r9,%rax,8), %rax
xorl %ecx, %ecx
movl %r10d, -0x4(%rax,%rcx,8)
movl %esi, (%rax,%rcx,8)
incq %rcx
cmpl %ecx, %ebx
jne 0x12ebd
incq %r10
cmpq %r8, %r10
jne 0x12e54
movl -0x34(%rbp), %ecx
cmpl $0x1f, %ecx
je 0x12f5a
movl %ecx, %eax
shll %cl, -0x2c(%rbp)
negl %eax
movl %eax, -0x4c(%rbp)
addl %ecx, %r12d
cmpl $0x2, %r15d
movl $0x1, %r14d
cmovgel %r15d, %r14d
movq -0x40(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x48(%rbp)
xorl %ebx, %ebx
movq -0x58(%rbp), %r15
movl 0x4(%rdi,%rbx,8), %edx
testl %edx, %edx
jns 0x12f52
negl %edx
cmpl %ecx, %edx
jle 0x12f24
movl -0x4c(%rbp), %eax
movl %eax, 0x4(%rdi,%rbx,8)
movl %ecx, %edx
movl -0x2c(%rbp), %r8d
orl %ebx, %r8d
movq %r15, %rdi
movq %r13, %rsi
movl -0x30(%rbp), %ecx
movl %r12d, %r9d
callq 0x12d93
movq 0x8(%r15), %rcx
movq -0x40(%rbp), %rdx
leaq (%rcx,%rdx,8), %rdi
addq -0x48(%rbp), %rcx
movl %eax, (%rcx,%rbx,8)
movl -0x34(%rbp), %ecx
incq %rbx
cmpq %rbx, %r14
jne 0x12f0d
movq -0x40(%rbp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq