// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/decoder/set.c
// Function: x264_sps_read(bs_s*, x264_sps_t*)
int x264_sps_read(bs_t *s, x264_sps_t sps_array[32]) {LOG_CALL;
    x264_sps_t *sps;

    int i_profile_idc;
    int i_level_idc;

    int b_constraint_set0;
    int b_constraint_set1;
    int b_constraint_set2;

    int id;

    i_profile_idc = bs_read(s, 8, "i_profile_idc");
    b_constraint_set0 = bs_read1(s, "b_constraint_set0");
    b_constraint_set1 = bs_read1(s, "b_constraint_set1");
    b_constraint_set2 = bs_read1(s, "b_constraint_set2");

    bs_skip(s, 5); /* reserved */
    i_level_idc = bs_read(s, 8,"i_level_idc");


    id = bs_read_ue(s,"id");
    if (bs_eof(s) || id >= 32)
    {
        /* the sps is invalid, no need to corrupt sps_array[0] */
        return -1;
    }

    sps = &sps_array[id];
    sps->i_id = id;

    /* put pack parsed value */
    sps->i_profile_idc = i_profile_idc;
    sps->i_level_idc = i_level_idc;
    sps->b_constraint_set0 = b_constraint_set0;
    sps->b_constraint_set1 = b_constraint_set1;
    sps->b_constraint_set2 = b_constraint_set2;

    sps->i_log2_max_frame_num = bs_read_ue(s,"i_log2_max_frame_num") + 4;

    sps->i_poc_type = bs_read_ue(s,"i_poc_type");
    if (sps->i_poc_type == 0)
    {
        sps->i_log2_max_poc_lsb = bs_read_ue(s,"i_log2_max_poc_lsb") + 4;
    } else if (sps->i_poc_type == 1)
    {
        int i;
        sps->b_delta_pic_order_always_zero = bs_read1(s, "b_delta_pic_order_always_zero");
        sps->i_offset_for_non_ref_pic = bs_read_se(s,"i_offset_for_non_ref_pic");
        sps->i_offset_for_top_to_bottom_field = bs_read_se(s,"i_offset_for_top_to_bottom_field");
        sps->i_num_ref_frames_in_poc_cycle = bs_read_ue(s,"i_num_ref_frames_in_poc_cycle");
        if (sps->i_num_ref_frames_in_poc_cycle > 256)
        {
            /* FIXME what to do */
            sps->i_num_ref_frames_in_poc_cycle = 256;
        }
        for (i = 0; i < sps->i_num_ref_frames_in_poc_cycle; i++)
        {
            sps->i_offset_for_ref_frame[i] = bs_read_se(s,"i_offset_for_ref_frame");
        }
    } else if (sps->i_poc_type > 2)
    {
        goto error;
    }

    sps->i_num_ref_frames = bs_read_ue(s,"i_num_ref_frames");
    sps->b_gaps_in_frame_num_value_allowed = bs_read1(s, "b_gaps_in_frame_num_value_allowed");
    sps->i_mb_width = bs_read_ue(s,"i_mb_width") + 1;
    sps->i_mb_height = bs_read_ue(s,"i_mb_height") + 1;
    sps->b_frame_mbs_only = bs_read1(s, "b_frame_mbs_only");
    if (!sps->b_frame_mbs_only)
    {
        sps->b_mb_adaptive_frame_field = bs_read1(s, "b_mb_adaptive_frame_field");
    } else
    {
        sps->b_mb_adaptive_frame_field = 0;
    }
    sps->b_direct8x8_inference = bs_read1(s, "b_direct8x8_inference");

    sps->b_crop = bs_read1(s, "b_crop");
    if (sps->b_crop)
    {
        sps->crop.i_left = bs_read_ue(s,"crop.i_left");
        sps->crop.i_right = bs_read_ue(s,"crop.rigth");
        sps->crop.i_top = bs_read_ue(s,"crop.top");
        sps->crop.i_bottom = bs_read_ue(s,"crop.i_bottom");
    } else
    {
        sps->crop.i_left = 0;
        sps->crop.i_right = 0;
        sps->crop.i_top = 0;
        sps->crop.i_bottom = 0;
    }

    sps->b_vui = bs_read1(s, "b_vui");
    if (sps->b_vui)
    {
        /* FIXME */
    } else
    {

    }

    if (bs_eof(s))
    {
        /* no rbsp trailing */
        fprintf(stderr, "incomplete SPS\n");
        goto error;
    }

    fprintf(stderr, "x264_sps_read: sps:0x%x profile:%d/%d poc:%d ref:%d %xx%d crop:%d-%d-%d-%d\n",
            sps->i_id,
            sps->i_profile_idc, sps->i_level_idc,
            sps->i_poc_type,
            sps->i_num_ref_frames,
            sps->i_mb_width, sps->i_mb_height,
            sps->crop.i_left, sps->crop.i_right,
            sps->crop.i_top, sps->crop.i_bottom);

    return id;

error:
    /* invalidate this sps */
    sps->i_id = -1;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
leaq 0x14e7f(%rip), %rdi     # 0x28eb0
leaq 0x17ec9(%rip), %rsi     # 0x2bf01
leaq 0x17ed0(%rip), %rdx     # 0x2bf0f
movb $0x0, %al
callq 0x4d20
movq -0x30(%rbp), %rdi
movl $0x8, %esi
leaq 0x17ec7(%rip), %rdx     # 0x2bf1d
callq 0x14560
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x17ec2(%rip), %rsi     # 0x2bf2b
callq 0x146b0
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x17ec1(%rip), %rsi     # 0x2bf3d
callq 0x146b0
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x17ec0(%rip), %rsi     # 0x2bf4f
callq 0x146b0
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rdi
movl $0x5, %esi
callq 0x14760
movq -0x30(%rbp), %rdi
movl $0x8, %esi
leaq 0x17eac(%rip), %rdx     # 0x2bf61
callq 0x14560
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x17446(%rip), %rsi     # 0x2b50e
callq 0x147c0
movl %eax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x14870
cmpl $0x0, %eax
jne 0x140e4
cmpl $0x20, -0x58(%rbp)
jl 0x140f0
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
jmp 0x14547
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
imulq $0x470, %rcx, %rcx      # imm = 0x470
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movl -0x44(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x48(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x50(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x54(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17388(%rip), %rsi     # 0x2b4d4
callq 0x147c0
movl %eax, %ecx
addl $0x4, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17e05(%rip), %rsi     # 0x2bf6d
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x141a1
movq -0x30(%rbp), %rdi
leaq 0x17386(%rip), %rsi     # 0x2b511
callq 0x147c0
movl %eax, %ecx
addl $0x4, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0x1427c
movq -0x40(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x14269
movq -0x30(%rbp), %rdi
leaq 0x17dbe(%rip), %rsi     # 0x2bf78
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17dc3(%rip), %rsi     # 0x2bf96
callq 0x148c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17dc3(%rip), %rsi     # 0x2bfaf
callq 0x148c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17dcb(%rip), %rsi     # 0x2bfd0
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x40(%rbp), %rax
cmpl $0x100, 0x30(%rax)      # imm = 0x100
jle 0x1422b
movq -0x40(%rbp), %rax
movl $0x100, 0x30(%rax)      # imm = 0x100
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x14267
movq -0x30(%rbp), %rdi
leaq 0x17da5(%rip), %rsi     # 0x2bfee
callq 0x148c0
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movl %edx, 0x34(%rax,%rcx,4)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x14232
jmp 0x1427a
movq -0x40(%rbp), %rax
cmpl $0x2, 0x1c(%rax)
jle 0x14278
jmp 0x14536
jmp 0x1427a
jmp 0x1427c
movq -0x30(%rbp), %rdi
leaq 0x17d7e(%rip), %rsi     # 0x2c005
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x434(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d73(%rip), %rsi     # 0x2c016
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x438(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d79(%rip), %rsi     # 0x2c038
callq 0x147c0
movl %eax, %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x43c(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d65(%rip), %rsi     # 0x2c043
callq 0x147c0
movl %eax, %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x440(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d52(%rip), %rsi     # 0x2c04f
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x444(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x444(%rax)
jne 0x14339
movq -0x30(%rbp), %rdi
leaq 0x17d3a(%rip), %rsi     # 0x2c060
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x448(%rax)
jmp 0x14347
movq -0x40(%rbp), %rax
movl $0x0, 0x448(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d28(%rip), %rsi     # 0x2c07a
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x44c(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17d22(%rip), %rsi     # 0x2c090
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x450(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x450(%rax)
je 0x143fe
movq -0x30(%rbp), %rdi
leaq 0x17d00(%rip), %rsi     # 0x2c097
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x454(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17cf0(%rip), %rsi     # 0x2c0a3
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x458(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17cdf(%rip), %rsi     # 0x2c0ae
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x45c(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17ccc(%rip), %rsi     # 0x2c0b7
callq 0x147c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x460(%rax)
jmp 0x14436
movq -0x40(%rbp), %rax
movl $0x0, 0x454(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x458(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x45c(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0x460(%rax)
movq -0x30(%rbp), %rdi
leaq 0x17c84(%rip), %rsi     # 0x2c0c5
callq 0x146b0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x464(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x464(%rax)
je 0x14461
jmp 0x14463
jmp 0x14463
movq -0x30(%rbp), %rdi
callq 0x14870
cmpl $0x0, %eax
je 0x1448e
movq 0x21b58(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
leaq 0x17c49(%rip), %rsi     # 0x2c0cb
movb $0x0, %al
callq 0x2160
jmp 0x14536
movq 0x21b3b(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %edx
movq -0x40(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x40(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0x40(%rbp), %rax
movl 0x1c(%rax), %r9d
movq -0x40(%rbp), %rax
movl 0x434(%rax), %r12d
movq -0x40(%rbp), %rax
movl 0x43c(%rax), %r15d
movq -0x40(%rbp), %rax
movl 0x440(%rax), %r14d
movq -0x40(%rbp), %rax
movl 0x454(%rax), %ebx
movq -0x40(%rbp), %rax
movl 0x458(%rax), %r11d
movq -0x40(%rbp), %rax
movl 0x45c(%rax), %r10d
movq -0x40(%rbp), %rax
movl 0x460(%rax), %eax
leaq 0x17bd4(%rip), %rsi     # 0x2c0db
movl %r12d, (%rsp)
movl %r15d, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl %eax, 0x30(%rsp)
movb $0x0, %al
callq 0x2160
movl -0x58(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x14547
movq -0x40(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl -0x24(%rbp), %eax
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)