// File: /workspace/github_c_makefile_star2_O1/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
je 0x409a
movslq %esi, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x40(%rbp)
movl $0xffffffff, 0x4(%rax,%rcx,8) # imm = 0xFFFFFFFF
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
leaq 0x1e230(%rip), %rsi     # 0x221c4
xorl %edi, %edi
movl $0x100, %r9d            # imm = 0x100
movl $0x7f, %r11d
leaq 0x20d87(%rip), %rbx     # 0x24d30
leaq 0x20f80(%rip), %r14     # 0x24f30
xorl %r8d, %r8d
movq %r8, -0x50(%rbp)
movq -0x48(%rbp), %r13
xorl %ecx, %ecx
xorl %r12d, %r12d
movl (%r13), %eax
shll $0x8, %eax
sarl $0x5, %eax
cmpl %r9d, %eax
cmovgel %r9d, %eax
movl -0x4(%rsi,%rcx,8), %r10d
imull %edx, %r10d
sarl $0x4, %r10d
addl (%rsi,%rcx,8), %r10d
cmpl $0x7f, %r10d
cmovgel %r11d, %r10d
testl %r10d, %r10d
cmovlel %edi, %r10d
movl -0x8(%r13), %edi
movl $0x3f, %r15d
subl %edi, %r15d
addl $0x40, %edi
cmpl $0x0, -0x4(%r13)
cmovel %r15d, %edi
movslq %edi, %rdi
movl (%r14,%r10,4), %r15d
imull (%rbx,%rdi,4), %r15d
movl $0x7f, %r8d
subl %edi, %r8d
movslq %r8d, %rdi
xorl $0x7f, %r10d
movl (%r14,%r10,4), %r8d
imull (%rbx,%rdi,4), %r8d
xorl %edi, %edi
addl %r15d, %r8d
sarl $0x8, %r8d
imull %eax, %r8d
sarl $0x8, %r8d
addl %r8d, %r12d
incq %rcx
addq $0xc, %r13
cmpq $0x18f, %rcx            # imm = 0x18F
jne 0x3fc0
movl -0x2c(%rbp), %ecx
cmpl $-0x1, %ecx
sete %al
cmpl %r12d, %ecx
setg %cl
orb %al, %cl
cmpb $0x1, %cl
movq -0x50(%rbp), %r8
jne 0x4086
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movl %r8d, (%rax,%rcx,8)
movl %r12d, 0x4(%rax,%rcx,8)
movl %r12d, -0x2c(%rbp)
incq %r8
addq $0xc78, %rsi            # imm = 0xC78
cmpq $0x3, %r8
jne 0x3fb3
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq