// File: /workspace/github_c_makefile_star2_O1/akumrao[P]videoAnalyzer/encoder/encoder.c
// Function: x264_encoder_open(x264_param_t*)
x264_t *x264_encoder_open(x264_param_t *param) {LOG_CALL;
    x264_t *h = (x264_t *)x264_aligned_alloc(sizeof ( x264_t));
    int i;
    x264_me_t me[2];

    if (param->i_width <= 0 || param->i_height <= 0)
    {
        fprintf(stderr, "invalid width x height (%dx%d)\n",
                param->i_width, param->i_height);
        free(h);
        return NULL;
    }

    if (param->i_width % 16 != 0 || param->i_height % 16 != 0)
    {
        fprintf(stderr, "width %% 16 != 0 pr height %% 16 != 0 (%dx%d)\n",
                param->i_width, param->i_height);
        free(h);
        return NULL;
    }

    memcpy(&h->param, param, sizeof ( x264_param_t));
    if (h->param.i_frame_reference <= 0)
    {
        h->param.i_frame_reference = 1;
    } else if (h->param.i_frame_reference > 15)
    {
        h->param.i_frame_reference = 15;
    }
    if (h->param.i_idrframe <= 0)
    {
        h->param.i_idrframe = 1;
    }
    if (h->param.i_iframe <= 0)
    {
        h->param.i_iframe = 1;
    }
    if (h->param.i_bframe < 0)
    {
        h->param.i_bframe = 0;
    } else if (h->param.i_bframe > X264_BFRAME_MAX)
    {
        h->param.i_bframe = X264_BFRAME_MAX;
    }
    /* XXX for now we use fixed patern IB...BPB...BPB...BP */
    if (h->param.i_bframe > 0)
    {
        h->param.i_iframe = ((h->param.i_iframe - 1) / (h->param.i_bframe + 1))*(h->param.i_bframe + 1) + 1;

        if (h->param.b_cabac)
        {
            fprintf(stderr, "cabac not supported with B frame (cabac disabled)\n");
            h->param.b_cabac = 0;
        }
    }
    if (h->param.i_cabac_init_idc < -1)
    {
        h->param.i_cabac_init_idc = -1;
    } else if (h->param.i_cabac_init_idc > 2)
    {
        h->param.i_cabac_init_idc = 2;
    }

    h->cpu = param->cpu;

    h->i_nal = 0;
    h->i_bitstream = 1000000; /* FIXME calculate max size from width/height */
    h->p_bitstream = (uint8_t*)x264_aligned_alloc(h->i_bitstream);

    h->i_frame = 0;
    h->i_frame_num = 0;
    h->i_poc = 0;
    h->i_idr_pic_id = 0;

    h->sps = &h->sps_array[0];
    x264_sps_init(h->sps, 0, &h->param);

    h->pps = &h->pps_array[0];
    x264_pps_init(h->pps, 0, &h->param, h->sps);

    /* init picture and bframe context */
    h->picture = NULL;
    for (i = 0; i < X264_BFRAME_MAX; i++)
    {
        h->bframe_current[i] = NULL;
        h->frame_next[i] = NULL;
        h->frame_unused[i] = NULL;
    }
    h->frame_next[X264_BFRAME_MAX] = NULL;
    h->frame_unused[X264_BFRAME_MAX] = NULL;
    for (i = 0; i < h->param.i_bframe + 1; i++)
    {
        h->frame_unused[i] = x264_frame_new(h);
    }

    h->mb = x264_macroblocks_new(h->sps->i_mb_width, h->sps->i_mb_height);

    /* reference frame (2 for B frame) and current one */
    for (i = 0; i < h->param.i_frame_reference + 2; i++)
    {
        h->freference[i] = x264_frame_new(h);
    }
    h->fdec = h->freference[0];
    h->i_ref0 = 0;
    h->i_ref1 = 0;

    /* init cabac adaptive model */
    x264_cabac_model_init(&h->cabac);

    /* init predict_XxX */
    x264_predict_16x16_init(h->cpu, h->predict_16x16);
    x264_predict_8x8_init(h->cpu, h->predict_8x8);
    x264_predict_4x4_init(h->cpu, h->predict_4x4);

    x264_pixel_init(h->cpu, &h->pixf);
    x264_dct_init(h->cpu, &h->dctf);

    x264_mc_init(h->cpu, h->mc);

    x264_me_init(h->cpu, me);
    h->me = me[h->param.i_me];

    /* rate control */
    h->rc = x264_ratecontrol_new(&h->param);

    return h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
leaq 0x10991(%rip), %rdi     # 0x251b4
leaq 0x148fe(%rip), %rsi     # 0x29128
leaq 0x14909(%rip), %rdx     # 0x2913a
xorl %eax, %eax
callq 0x4c22
movl $0x10f4c0, %edi         # imm = 0x10F4C0
callq 0x47e2
movq %rax, %rbx
movl 0x4(%r15), %edx
testl %edx, %edx
jle 0x14b51
movl 0x8(%r15), %ecx
testl %ecx, %ecx
jle 0x14b51
movl %ecx, %eax
orl %edx, %eax
testb $0xf, %al
jne 0x14b68
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups 0x30(%r15), %xmm3
movups %xmm1, 0x90(%rbx)
movups %xmm3, 0xb0(%rbx)
movups %xmm2, 0xa0(%rbx)
movups %xmm0, 0x80(%rbx)
movl 0x98(%rbx), %ecx
testl %ecx, %ecx
jle 0x148ae
movl $0xf, %eax
cmpl $0x10, %ecx
jge 0x148b3
jmp 0x148b9
movl $0x1, %eax
movl %eax, 0x98(%rbx)
cmpl $0x0, 0x9c(%rbx)
jg 0x148cc
movl $0x1, 0x9c(%rbx)
cmpl $0x0, 0xa0(%rbx)
jg 0x148df
movl $0x1, 0xa0(%rbx)
movl 0xa4(%rbx), %ecx
testl %ecx, %ecx
js 0x148f5
movl $0x10, %eax
cmpl $0x11, %ecx
jge 0x148f7
jmp 0x148fd
xorl %eax, %eax
movl %eax, 0xa4(%rbx)
movl 0xa4(%rbx), %ecx
testl %ecx, %ecx
jle 0x1492a
movl 0xa0(%rbx), %esi
leal -0x1(%rsi), %eax
incl %ecx
cltd
idivl %ecx
subl %edx, %esi
movl %esi, 0xa0(%rbx)
cmpl $0x0, 0xac(%rbx)
jne 0x14b8c
leaq 0x80(%rbx), %r14
movl 0xb0(%rbx), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
jl 0x1494b
movl $0x2, %eax
cmpl $0x3, %ecx
jl 0x14951
movl %eax, 0xb0(%rbx)
movl (%r15), %eax
movl %eax, (%rbx)
xorl %r15d, %r15d
movl %r15d, 0x4(%rbx)
movl $0xf4240, 0x50(%rbx)    # imm = 0xF4240
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x47e2
movq %rax, 0x58(%rbx)
movq %r15, 0xc0(%rbx)
movl %r15d, 0xcc(%rbx)
movl %r15d, 0x10dae8(%rbx)
leaq 0xd8(%rbx), %rdi
movq %rdi, 0x8ed8(%rbx)
xorl %esi, %esi
movq %r14, %rdx
callq 0x1e9e8
leaq 0x8ee0(%rbx), %rdi
movq %rdi, 0x10dae0(%rbx)
movq 0x8ed8(%rbx), %rcx
xorl %esi, %esi
movq %r14, %rdx
callq 0x1fa3d
leaq 0x10ee48(%rbx), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x10efc8(%rbx)
movups %xmm0, 0x10efb8(%rbx)
movups %xmm0, 0x10efa8(%rbx)
movups %xmm0, 0x10ef98(%rbx)
movups %xmm0, 0x10ef88(%rbx)
movups %xmm0, 0x10ef78(%rbx)
movups %xmm0, 0x10ef68(%rbx)
movups %xmm0, 0x10ef58(%rbx)
movl $0x108, %edx            # imm = 0x108
xorl %esi, %esi
callq 0x2070
movq %r15, 0x10ef50(%rbx)
movq %r15, 0x10efd8(%rbx)
cmpl %r15d, 0xa4(%rbx)
js 0x14a49
movq $-0x1, %r15
movq %rbx, %rdi
callq 0x5068
movq %rax, 0x10ef60(%rbx,%r15,8)
movslq 0xa4(%rbx), %rax
incq %r15
cmpq %rax, %r15
jl 0x14a2a
movq 0x8ed8(%rbx), %rax
movl 0x43c(%rax), %edi
movl 0x440(%rax), %esi
callq 0x6684
movq %rax, 0x10efe8(%rbx)
cmpl $-0x1, 0x98(%rbx)
jl 0x14a97
movq $-0x1, %r15
movq %rbx, %rdi
callq 0x5068
movq %rax, 0x10eff8(%rbx,%r15,8)
movslq 0x98(%rbx), %rax
incq %r15
cmpq %rax, %r15
jle 0x14a78
movq 0x10eff0(%rbx), %rax
movq %rax, 0x10efe0(%rbx)
xorl %eax, %eax
movl %eax, 0x10f078(%rbx)
movl %eax, 0x10f100(%rbx)
leaq 0x10db60(%rbx), %rdi
callq 0x3f26
movl (%rbx), %edi
leaq 0x10f1d8(%rbx), %rsi
callq 0xaa94
movl (%rbx), %edi
leaq 0x10f210(%rbx), %rsi
callq 0xad61
movl (%rbx), %edi
leaq 0x10f248(%rbx), %rsi
callq 0xb0c0
movl (%rbx), %edi
leaq 0x10f2a8(%rbx), %rsi
callq 0x9f14
movl (%rbx), %edi
leaq 0x10f398(%rbx), %rsi
callq 0x4874
movl (%rbx), %edi
movq %rbx, %rsi
addq $0x10f380, %rsi         # imm = 0x10F380
callq 0x8778
movl (%rbx), %edi
leaq -0x30(%rbp), %rsi
callq 0x1b6fc
movslq 0xbc(%rbx), %rax
movq -0x30(%rbp,%rax,8), %rax
movq %rax, 0x10f390(%rbx)
movq %r14, %rdi
callq 0x1e948
movq %rax, 0x10f188(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x1d478(%rip), %rax     # 0x31fd0
movq (%rax), %rdi
movl 0x8(%r15), %ecx
leaq 0x145e6(%rip), %rsi     # 0x2914c
jmp 0x14b79
movq 0x1d461(%rip), %rax     # 0x31fd0
movq (%rax), %rdi
leaq 0x145f3(%rip), %rsi     # 0x2916c
xorl %eax, %eax
callq 0x2180
movq %rbx, %rdi
callq 0x2110
xorl %ebx, %ebx
jmp 0x14b43
leaq 0xac(%rbx), %rdi
callq 0x2dac
jmp 0x1492a