// File: /workspace/github_c_makefile_star2_O2/akumrao[P]videoAnalyzer/core/cabac.c
// Function: x264_cabac_model_update(x264_cabac_t*, int, int)
void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp )
{
    int i;

    if( i_slice_type == SLICE_TYPE_I )
    {
        return;
    }
    cb->slice[i_slice_type].i_cost = -1;

    for( i = 0; i < 3; i++ )
    {
        int i_ctx;
        int i_cost;

        i_cost = 0; /* fix8 */

        for( i_ctx = 0; i_ctx < 399; i_ctx++ )
        {
            int i_weight;
            int i_model_state;
            int i_ctx_state;

            i_weight = X264_MIN( (1<<8), (cb->ctxstate[i_ctx].i_count<<8) / 32 );
            i_model_state = x264_clip3( ((x264_cabac_context_init_PB[i][i_ctx][0] * i_qp)>>4) +
                                          x264_cabac_context_init_PB[i][i_ctx][1], 0, 127 );
            i_ctx_state   = cb->ctxstate[i_ctx].i_mps ? 64 + cb->ctxstate[i_ctx].i_state : 63 - cb->ctxstate[i_ctx].i_state;

            i_cost += (i_weight * (( x264_cabac_probability[      i_ctx_state] * x264_cabac_entropy[      i_model_state] +
                                     x264_cabac_probability[127 - i_ctx_state] * x264_cabac_entropy[127 - i_model_state] ) >> 8))>>8;
        }

        if( cb->slice[i_slice_type].i_cost == -1 || cb->slice[i_slice_type].i_cost > i_cost )
        {
            cb->slice[i_slice_type].i_model= i;
            cb->slice[i_slice_type].i_cost = i_cost;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, -0x38(%rbp)
cmpl $0x2, %esi
jne 0x2f6f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %esi, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x48(%rbp)
orl $-0x1, 0x4(%rax,%rcx,8)
addq $0x20, %rax
movq %rax, -0x50(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x2c(%rbp)
leaq 0x1522e(%rip), %rsi     # 0x181c4
movl $0x100, %r9d            # imm = 0x100
movl $0x7f, %r8d
leaq 0x17d87(%rip), %r14     # 0x1ad30
leaq 0x17f80(%rip), %r15     # 0x1af30
xorl %eax, %eax
cmpq $0x3, %rax
je 0x2f64
movq %rax, -0x40(%rbp)
xorl %ecx, %ecx
movq -0x50(%rbp), %rax
xorl %r13d, %r13d
cmpq $0x18f, %rcx            # imm = 0x18F
je 0x3059
movl (%rax), %r10d
shll $0x8, %r10d
sarl $0x5, %r10d
cmpl %r9d, %r10d
cmovgel %r9d, %r10d
movl -0x4(%rsi,%rcx,8), %edi
imull %edx, %edi
sarl $0x4, %edi
addl (%rsi,%rcx,8), %edi
cmpl $0x7f, %edi
cmovgel %r8d, %edi
testl %edi, %edi
movl $0x0, %r11d
cmovlel %r11d, %edi
movl -0x8(%rax), %r12d
movl $0x3f, %ebx
subl %r12d, %ebx
addl $0x40, %r12d
cmpl $0x0, -0x4(%rax)
cmovel %ebx, %r12d
movslq %r12d, %rbx
movl (%r15,%rdi,4), %r12d
imull (%r14,%rbx,4), %r12d
movl %r8d, %r11d
subl %ebx, %r11d
movslq %r11d, %r11
xorl $0x7f, %edi
movl (%r15,%rdi,4), %edi
imull (%r14,%r11,4), %edi
addl %r12d, %edi
sarl $0x8, %edi
imull %r10d, %edi
sarl $0x8, %edi
addl %edi, %r13d
incq %rcx
addq $0xc, %rax
jmp 0x2fc5
movl -0x2c(%rbp), %ecx
cmpl $-0x1, %ecx
sete %al
cmpl %r13d, %ecx
setg %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x3087
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rdi
movl %edi, (%rax,%rcx,8)
movl %r13d, 0x4(%rax,%rcx,8)
movl %r13d, -0x2c(%rbp)
movq -0x40(%rbp), %rax
incq %rax
addq $0xc78, %rsi            # imm = 0xC78
jmp 0x2fb2