// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
cmpl $0x2, -0xc(%rbp)
jne 0x36fd
jmp 0x38f8
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl $0xffffffff, 0x4(%rax,%rcx,8) # imm = 0xFFFFFFFF
movl $0x0, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
jge 0x38f8
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x18f, -0x18(%rbp)     # imm = 0x18F
jge 0x38ab
movq -0x8(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shll $0x8, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0x100, %eax            # imm = 0x100
cmpl %ecx, %eax
jge 0x376f
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0x3793
movq -0x8(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shll $0x8, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x20(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x22b9c(%rip), %rax     # 0x26340
imulq $0xc78, %rcx, %rcx      # imm = 0xC78
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,8), %edi
imull -0x10(%rbp), %edi
sarl $0x4, %edi
movslq -0x14(%rbp), %rcx
leaq 0x22b79(%rip), %rax     # 0x26340
imulq $0xc78, %rcx, %rcx      # imm = 0xC78
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
addl 0x4(%rax,%rcx,8), %edi
xorl %esi, %esi
movl $0x7f, %edx
callq 0x3220
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
je 0x381e
movq -0x8(%rbp), %rax
addq $0x18, %rax
movslq -0x18(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl $0x40, %eax
movl %eax, -0x30(%rbp)
jmp 0x383b
movq -0x8(%rbp), %rcx
addq $0x18, %rcx
movslq -0x18(%rbp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rcx
movl $0x3f, %eax
subl (%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movslq -0x28(%rbp), %rdx
leaq 0x32a51(%rip), %rcx     # 0x362a0
movl (%rcx,%rdx,4), %ecx
movslq -0x24(%rbp), %rsi
leaq 0x32c43(%rip), %rdx     # 0x364a0
imull (%rdx,%rsi,4), %ecx
movl $0x7f, %edx
subl -0x28(%rbp), %edx
movslq %edx, %rsi
leaq 0x32a2d(%rip), %rdx     # 0x362a0
movl (%rdx,%rsi,4), %edx
movl $0x7f, %esi
subl -0x24(%rbp), %esi
movslq %esi, %rdi
leaq 0x32c18(%rip), %rsi     # 0x364a0
imull (%rsi,%rdi,4), %edx
addl %edx, %ecx
sarl $0x8, %ecx
imull %ecx, %eax
sarl $0x8, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x372c
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpl $-0x1, 0x4(%rax,%rcx,8)
je 0x38cb
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
cmpl -0x1c(%rbp), %eax
jle 0x38e8
movl -0x14(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0x1c(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
jmp 0x38ea
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3714
addq $0x30, %rsp
popq %rbp
retq
nop