// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/decoder/macroblock.c
// Function: x264_mb_pred_mode4x4_valid(x264_macroblock_t*, int, int, int*)
static int x264_mb_pred_mode4x4_valid(x264_macroblock_t *mb, int idx, int i_mode, int *pb_emu) {LOG_CALL;
    int b_a, b_b, b_c;
    static const int needmb[16] ={
        MB_LEFT | MB_TOP, MB_TOP,
        MB_LEFT, MB_PRIVATE,
        MB_TOP, MB_TOP | MB_TOPRIGHT,
        0, MB_PRIVATE,
        MB_LEFT, 0,
        MB_LEFT, MB_PRIVATE,
        0, MB_PRIVATE,
        0, MB_PRIVATE
    };
    int b_emu = 0;

    *pb_emu = 0;

    b_a = (needmb[idx] & mb->i_neighbour & MB_LEFT) == (needmb[idx] & MB_LEFT);
    b_b = (needmb[idx] & mb->i_neighbour & MB_TOP) == (needmb[idx] & MB_TOP);
    b_c = (needmb[idx] & mb->i_neighbour & (MB_TOPRIGHT | MB_PRIVATE)) == (needmb[idx]&(MB_TOPRIGHT | MB_PRIVATE));

    if (b_c == 0 && b_b)
    {
        b_emu = 1;
        b_c = 1;
    }

    /* handle I_PRED_4x4_DC */
    if (i_mode == I_PRED_4x4_DC)
    {
        if (b_a && b_b)
        {
            return I_PRED_4x4_DC;
        } else if (b_a)
        {
            return I_PRED_4x4_DC_LEFT;
        } else if (b_b)
        {
            return I_PRED_4x4_DC_TOP;
        }
        return I_PRED_4x4_DC_128;
    }

    /* handle 1 dir needed only */
    if ((b_a && i_mode == I_PRED_4x4_H) ||
            (b_b && i_mode == I_PRED_4x4_V))
    {
        return i_mode;
    }

    /* handle b_c case (b_b always true) */
    if (b_c && (i_mode == I_PRED_4x4_DDL || i_mode == I_PRED_4x4_VL))
    {
        *pb_emu = b_emu;
        return i_mode;
    }

    if (b_a && b_b)
    {
        /* I_PRED_4x4_DDR, I_PRED_4x4_VR, I_PRED_4x4_HD, I_PRED_4x4_HU */
        return i_mode;
    }

    fprintf(stderr, "invalid 4x4 predict mode(%d, mb:%x-%x idx:%d\n", i_mode, mb->i_mb_x, mb->i_mb_y, idx);
    return I_PRED_CHROMA_DC_128; /* unefficient */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0x158b3(%rip), %rdi     # 0x28eb0
leaq 0x185cc(%rip), %rsi     # 0x2bbd0
leaq 0x18865(%rip), %rdx     # 0x2be70
movb $0x0, %al
callq 0x4d20
movl $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movslq -0x14(%rbp), %rcx
leaq 0x18562(%rip), %rax     # 0x2bb90
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
andl 0x8(%rcx), %eax
andl $0x1, %eax
movslq -0x14(%rbp), %rdx
leaq 0x1854a(%rip), %rcx     # 0x2bb90
movl (%rcx,%rdx,4), %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x1852c(%rip), %rax     # 0x2bb90
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
andl 0x8(%rcx), %eax
andl $0x2, %eax
movslq -0x14(%rbp), %rdx
leaq 0x18514(%rip), %rcx     # 0x2bb90
movl (%rcx,%rdx,4), %ecx
andl $0x2, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x184f6(%rip), %rax     # 0x2bb90
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
andl 0x8(%rcx), %eax
andl $0x14, %eax
movslq -0x14(%rbp), %rdx
leaq 0x184de(%rip), %rcx     # 0x2bb90
movl (%rcx,%rdx,4), %ecx
andl $0x14, %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x136df
cmpl $0x0, -0x28(%rbp)
je 0x136df
movl $0x1, -0x30(%rbp)
movl $0x1, -0x2c(%rbp)
cmpl $0x2, -0x18(%rbp)
jne 0x13731
cmpl $0x0, -0x24(%rbp)
je 0x136fd
cmpl $0x0, -0x28(%rbp)
je 0x136fd
movl $0x2, -0x4(%rbp)
jmp 0x137bc
cmpl $0x0, -0x24(%rbp)
je 0x1370f
movl $0x9, -0x4(%rbp)
jmp 0x137bc
cmpl $0x0, -0x28(%rbp)
je 0x13721
movl $0xa, -0x4(%rbp)
jmp 0x137bc
jmp 0x13723
jmp 0x13725
movl $0xb, -0x4(%rbp)
jmp 0x137bc
cmpl $0x0, -0x24(%rbp)
je 0x1373d
cmpl $0x1, -0x18(%rbp)
je 0x13749
cmpl $0x0, -0x28(%rbp)
je 0x13751
cmpl $0x0, -0x18(%rbp)
jne 0x13751
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x137bc
cmpl $0x0, -0x2c(%rbp)
je 0x13774
cmpl $0x3, -0x18(%rbp)
je 0x13763
cmpl $0x7, -0x18(%rbp)
jne 0x13774
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x137bc
cmpl $0x0, -0x24(%rbp)
je 0x13788
cmpl $0x0, -0x28(%rbp)
je 0x13788
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x137bc
movq 0x22841(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %r8d
movl -0x14(%rbp), %r9d
leaq 0x186dd(%rip), %rsi     # 0x2be8b
movb $0x0, %al
callq 0x2160
movl $0x6, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)