// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x114ed(%rip), %rdi     # 0x28eb0
leaq 0x150ca(%rip), %rsi     # 0x2ca94
leaq 0x150d5(%rip), %rdx     # 0x2caa6
movb $0x0, %al
callq 0x4d20
movl $0x10f4c0, %edi         # imm = 0x10F4C0
callq 0x4160
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x179fa
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jg 0x17a36
movq 0x1e5cf(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x1509f(%rip), %rsi     # 0x2cab8
movb $0x0, %al
callq 0x2160
movq -0x18(%rbp), %rdi
callq 0x2100
movq $0x0, -0x8(%rbp)
jmp 0x17f47
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x17a5e
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x17a9a
movq 0x1e56b(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x1505b(%rip), %rsi     # 0x2cad8
movb $0x0, %al
callq 0x2160
movq -0x18(%rbp), %rdi
callq 0x2100
movq $0x0, -0x8(%rbp)
jmp 0x17f47
movq -0x18(%rbp), %rdi
addq $0x80, %rdi
movq -0x10(%rbp), %rsi
movl $0x40, %edx
callq 0x20a0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jg 0x17ad0
movq -0x18(%rbp), %rax
movl $0x1, 0x98(%rax)
jmp 0x17aed
movq -0x18(%rbp), %rax
cmpl $0xf, 0x98(%rax)
jle 0x17aeb
movq -0x18(%rbp), %rax
movl $0xf, 0x98(%rax)
jmp 0x17aed
movq -0x18(%rbp), %rax
cmpl $0x0, 0x9c(%rax)
jg 0x17b08
movq -0x18(%rbp), %rax
movl $0x1, 0x9c(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa0(%rax)
jg 0x17b23
movq -0x18(%rbp), %rax
movl $0x1, 0xa0(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
jge 0x17b40
movq -0x18(%rbp), %rax
movl $0x0, 0xa4(%rax)
jmp 0x17b5d
movq -0x18(%rbp), %rax
cmpl $0x10, 0xa4(%rax)
jle 0x17b5b
movq -0x18(%rbp), %rax
movl $0x10, 0xa4(%rax)
jmp 0x17b5d
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa4(%rax)
jle 0x17bdb
movq -0x18(%rbp), %rax
movl 0xa0(%rax), %eax
subl $0x1, %eax
movq -0x18(%rbp), %rcx
movl 0xa4(%rcx), %ecx
addl $0x1, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl 0xa4(%rax), %eax
addl $0x1, %eax
imull %eax, %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xa0(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xac(%rax)
je 0x17bd9
movq 0x1e416(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
leaq 0x14f43(%rip), %rsi     # 0x2cb07
movb $0x0, %al
callq 0x2160
movq -0x18(%rbp), %rax
movl $0x0, 0xac(%rax)
jmp 0x17bdb
movq -0x18(%rbp), %rax
cmpl $-0x1, 0xb0(%rax)
jge 0x17bf8
movq -0x18(%rbp), %rax
movl $0xffffffff, 0xb0(%rax) # imm = 0xFFFFFFFF
jmp 0x17c15
movq -0x18(%rbp), %rax
cmpl $0x2, 0xb0(%rax)
jle 0x17c13
movq -0x18(%rbp), %rax
movl $0x2, 0xb0(%rax)
jmp 0x17c15
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0xf4240, 0x50(%rax)    # imm = 0xF4240
movq -0x18(%rbp), %rax
movl 0x50(%rax), %edi
callq 0x4160
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xc0(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xcc(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xc4(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10dae8(%rax)
movq -0x18(%rbp), %rcx
addq $0xd8, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8ed8(%rax)
movq -0x18(%rbp), %rax
movq 0x8ed8(%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x80, %rdx
xorl %esi, %esi
callq 0x22fd0
movq -0x18(%rbp), %rcx
addq $0x8ee0, %rcx           # imm = 0x8EE0
movq -0x18(%rbp), %rax
movq %rcx, 0x10dae0(%rax)
movq -0x18(%rbp), %rax
movq 0x10dae0(%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x80, %rdx
movq -0x18(%rbp), %rax
movq 0x8ed8(%rax), %rcx
xorl %esi, %esi
callq 0x23c70
movq -0x18(%rbp), %rax
movq $0x0, 0x10ee48(%rax)
movl $0x0, -0x1c(%rbp)
cmpl $0x10, -0x1c(%rbp)
jge 0x17d5a
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq $0x0, 0x10ee50(%rax,%rcx,8)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq $0x0, 0x10eed0(%rax,%rcx,8)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq $0x0, 0x10ef58(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17d0d
movq -0x18(%rbp), %rax
movq $0x0, 0x10ef50(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x10efd8(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0xa4(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x17dba
movq -0x18(%rbp), %rdi
callq 0x52c0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, 0x10ef58(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17d7f
movq -0x18(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x43c(%rax), %edi
movq -0x18(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x440(%rax), %esi
callq 0x7280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10efe8(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x98(%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x17e31
movq -0x18(%rbp), %rdi
callq 0x52c0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, 0x10eff0(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17df6
movq -0x18(%rbp), %rax
movq 0x10eff0(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10efe0(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10f078(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x10f100(%rax)
movq -0x18(%rbp), %rdi
addq $0x10db60, %rdi         # imm = 0x10DB60
callq 0x3670
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f1d8, %rsi         # imm = 0x10F1D8
callq 0xcab0
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f210, %rsi         # imm = 0x10F210
callq 0xd040
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f248, %rsi         # imm = 0x10F248
callq 0xd730
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f2a8, %rsi         # imm = 0x10F2A8
callq 0xb9a0
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f398, %rsi         # imm = 0x10F398
callq 0x4430
movq -0x18(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
addq $0x10f380, %rsi         # imm = 0x10F380
callq 0xab00
movq -0x18(%rbp), %rax
movl (%rax), %edi
leaq -0x30(%rbp), %rsi
callq 0x21000
movq -0x18(%rbp), %rax
movslq 0xbc(%rax), %rax
movq -0x30(%rbp,%rax,8), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10f390(%rax)
movq -0x18(%rbp), %rdi
addq $0x80, %rdi
callq 0x22e40
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10f188(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)