// File: /workspace/github_c_makefile_star2_O2/akumrao[P]videoAnalyzer/decoder/set.c
// Function: x264_pps_read(bs_s*, x264_pps_t*)
int x264_pps_read(bs_t *s, x264_pps_t pps_array[256]) {LOG_CALL;
    x264_pps_t *pps;
    int id;
    int i;

    id = bs_read_ue(s,"id");
    if (bs_eof(s) || id >= 256)
    {
        fprintf(stderr, "id invalid\n");
        return -1;
    }
    pps = &pps_array[id];
    pps->i_id = id;
    pps->i_sps_id = bs_read_ue(s,"i_sps_id");
    if (pps->i_sps_id >= 32)
    {
        goto error;
    }
    pps->b_cabac = bs_read1(s, "b_cabac");
    pps->b_pic_order = bs_read1(s, "b_pic_order");
    pps->i_num_slice_groups = bs_read_ue(s,"i_num_slice_groups") + 1;
    if (pps->i_num_slice_groups > 1)
    {
        fprintf(stderr, "FMO unsupported\n ");

        pps->i_slice_group_map_type = bs_read_ue(s,"i_slice_group_map_type");
        if (pps->i_slice_group_map_type == 0)
        {
            for (i = 0; i < pps->i_num_slice_groups; i++)
            {
                pps->i_run_length[i] = bs_read_ue(s,"i_run_length");
            }
        } else if (pps->i_slice_group_map_type == 2)
        {
            for (i = 0; i < pps->i_num_slice_groups; i++)
            {
                pps->i_top_left[i] = bs_read_ue(s,"i_top_left");
                pps->i_bottom_right[i] = bs_read_ue(s,"i_bottom_right");
            }
        } else if (pps->i_slice_group_map_type == 3 ||
                pps->i_slice_group_map_type == 4 ||
                pps->i_slice_group_map_type == 5)
        {
            pps->b_slice_group_change_direction = bs_read1(s, "b_slice_group_change_direction");
            pps->i_slice_group_change_rate = bs_read_ue(s,"i_slice_group_change_rate") + 1;
        } else if (pps->i_slice_group_map_type == 6)
        {
            pps->i_pic_size_in_map_units = bs_read_ue(s,"i_pic_size_in_map_units") + 1;
            for (i = 0; i < pps->i_pic_size_in_map_units; i++)
            {
                /*  FIXME */
                /* pps->i_slice_group_id = bs_read( s, ceil( log2( pps->i_pic_size_in_map_units +1 ) ) ); */
            }
        }
    }
    pps->i_num_ref_idx_l0_active = bs_read_ue(s,"i_num_ref_idx_l0_active") + 1;
    pps->i_num_ref_idx_l1_active = bs_read_ue(s,"i_num_ref_idx_l1_active") + 1;
    pps->b_weighted_pred = bs_read1(s, "b_weighted_pred");
    pps->b_weighted_bipred = bs_read(s, 2,"b_weighted_bipred");

    pps->i_pic_init_qp = bs_read_se(s,"i_pic_init_qp") + 26;
    pps->i_pic_init_qs = bs_read_se(s,"i_pic_init_qs") + 26;

    pps->i_chroma_qp_index_offset = bs_read_se(s,"i_chroma_qp_index_offset");

    pps->b_deblocking_filter_control = bs_read1(s, "b_deblocking_filter_control");
    pps->b_constrained_intra_pred = bs_read1(s, "b_constrained_intra_pred");
    pps->b_redundant_pic_cnt = bs_read1(s, "b_redundant_pic_cnt");

    if (bs_eof(s))
    {
        /* no rbsp trailing */
        fprintf(stderr, "incomplete PPS\n");
        goto error;
    }
    fprintf(stderr, "x264_sps_read: pps:0x%x sps:0x%x %s slice_groups=%d ref0:%d ref1:%d QP:%d QS:%d QC=%d DFC:%d CIP:%d RPC:%d\n",
            pps->i_id, pps->i_sps_id,
            pps->b_cabac ? "CABAC" : "CAVLC",
            pps->i_num_slice_groups,
            pps->i_num_ref_idx_l0_active,
            pps->i_num_ref_idx_l1_active,
            pps->i_pic_init_qp, pps->i_pic_init_qs, pps->i_chroma_qp_index_offset,
            pps->b_deblocking_filter_control,
            pps->b_constrained_intra_pred,
            pps->b_redundant_pic_cnt);

    return id;
error:
    pps->i_id = -1;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %r14
leaq 0xe648(%rip), %rdi      # 0x1b1b4
leaq 0x11a11(%rip), %rsi     # 0x1e584
leaq 0x11c30(%rip), %rdx     # 0x1e7aa
xorl %eax, %eax
callq 0x39ba
leaq 0x10dc2(%rip), %rsi     # 0x1d94a
movq %r14, %rdi
callq 0xca0e
movl %eax, %r12d
movq %r14, %rdi
callq 0xca81
cmpl $0xff, %r12d
jg 0xcbea
testl %eax, %eax
jne 0xcbea
movslq %r12d, %rax
imulq $0x104c, %rax, %rbx     # imm = 0x104C
leaq (%r15,%rbx), %r13
movl %r12d, (%r15,%rbx)
leaq 0x11c03(%rip), %rsi     # 0x1e7c4
movq %r14, %rdi
callq 0xca0e
movl %eax, 0x4(%r15,%rbx)
cmpl $0x1f, %eax
jle 0xcc08
orl $-0x1, (%r13)
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1b3df(%rip), %rax     # 0x27fd0
movq (%rax), %rcx
leaq 0x11bbd(%rip), %rdi     # 0x1e7b8
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x21e0
jmp 0xcbd8
movl %r12d, -0x2c(%rbp)
leaq 0x11bba(%rip), %rsi     # 0x1e7cd
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0x8(%r13)
leaq 0x11baf(%rip), %rsi     # 0x1e7d5
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0xc(%r13)
leaq 0x11ba8(%rip), %rsi     # 0x1e7e1
movq %r14, %rdi
callq 0xca0e
leal 0x1(%rax), %ecx
movl %ecx, 0x10(%r13)
testl %eax, %eax
jle 0xccd5
movq 0x1b379(%rip), %rax     # 0x27fd0
movq (%rax), %rcx
leaq 0x11b93(%rip), %rdi     # 0x1e7f4
pushq $0x11
popq %rsi
pushq $0x1
popq %rdx
callq 0x21e0
leaq 0x11b93(%rip), %rsi     # 0x1e806
movq %r14, %rdi
callq 0xca0e
movl %eax, 0x14(%r13)
cmpl $0x6, %eax
ja 0xccd5
movl %eax, %eax
leaq 0x11853(%rip), %rcx     # 0x1e4e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x11ba7(%rip), %rsi     # 0x1e844
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0xc18(%r13)
movl $0xc1c, %ebx            # imm = 0xC1C
leaq 0x11bab(%rip), %rsi     # 0x1e863
jmp 0xccc6
movl $0xc20, %ebx            # imm = 0xC20
leaq 0x11bb7(%rip), %rsi     # 0x1e87d
movq %r14, %rdi
callq 0xca0e
incl %eax
movl %eax, (%r13,%rbx)
leaq 0x10cea(%rip), %rsi     # 0x1d9c6
movq %r14, %rdi
callq 0xca0e
incl %eax
movl %eax, 0x1024(%r13)
leaq 0x10cea(%rip), %rsi     # 0x1d9de
movq %r14, %rdi
callq 0xca0e
incl %eax
movl %eax, 0x1028(%r13)
leaq 0x11b89(%rip), %rsi     # 0x1e895
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0x102c(%r13)
leaq 0x11b83(%rip), %rdx     # 0x1e8a5
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0xc915
movl %eax, 0x1030(%r13)
leaq 0x11b7c(%rip), %rsi     # 0x1e8b7
movq %r14, %rdi
callq 0xcaba
addl $0x1a, %eax
movl %eax, 0x1034(%r13)
leaq 0x11b71(%rip), %rsi     # 0x1e8c5
movq %r14, %rdi
callq 0xcaba
addl $0x1a, %eax
movl %eax, 0x1038(%r13)
leaq 0x11b66(%rip), %rsi     # 0x1e8d3
movq %r14, %rdi
callq 0xcaba
movl %eax, 0x103c(%r13)
leaq 0x11b69(%rip), %rsi     # 0x1e8ec
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0x1040(%r13)
leaq 0x11b6f(%rip), %rsi     # 0x1e908
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0x1044(%r13)
leaq 0x11b72(%rip), %rsi     # 0x1e921
movq %r14, %rdi
callq 0xc9bb
movl %eax, 0x1048(%r13)
movq %r14, %rdi
callq 0xca81
movq 0x1b203(%rip), %rcx     # 0x27fd0
movq (%rcx), %rcx
testl %eax, %eax
jne 0xce66
movl (%r13), %edx
movl 0x4(%r13), %eax
cmpl $0x0, 0x8(%r13)
leaq 0x11bcb(%rip), %rsi     # 0x1e9b7
leaq 0x11bbe(%rip), %r8      # 0x1e9b1
cmoveq %rsi, %r8
movl 0x10(%r13), %r9d
movl 0x1024(%r13), %esi
movq %rsi, -0x38(%rbp)
movl 0x1028(%r13), %r11d
movl 0x1034(%r13), %ebx
movl 0x1038(%r13), %r14d
movl 0x103c(%r13), %r15d
movl 0x1040(%r13), %r12d
movl 0x1044(%r13), %r10d
movl 0x1048(%r13), %r13d
leaq 0x11b07(%rip), %rsi     # 0x1e945
movq %rcx, %rdi
movl %eax, %ecx
xorl %eax, %eax
pushq %r13
pushq %r10
pushq %r12
pushq %r15
pushq %r14
pushq %rbx
pushq %r11
pushq -0x38(%rbp)
callq 0x2170
addq $0x40, %rsp
movl -0x2c(%rbp), %eax
jmp 0xcbdb
leaq 0x11ac8(%rip), %rdi     # 0x1e935
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x21e0
jmp 0xcbd3
xorl %ebx, %ebx
leaq 0x11997(%rip), %r15     # 0x1e81d
movslq 0x10(%r13), %rax
cmpq %rax, %rbx
jge 0xccd5
movq %r14, %rdi
movq %r15, %rsi
callq 0xca0e
movl %eax, 0x18(%r13,%rbx,4)
incq %rbx
jmp 0xce86
xorl %ebx, %ebx
leaq 0x11979(%rip), %r15     # 0x1e82a
leaq 0x1197d(%rip), %r12     # 0x1e835
movslq 0x10(%r13), %rax
cmpq %rax, %rbx
jge 0xccd5
movq %r14, %rdi
movq %r15, %rsi
callq 0xca0e
movl %eax, 0x418(%r13,%rbx,4)
movq %r14, %rdi
movq %r12, %rsi
callq 0xca0e
movl %eax, 0x818(%r13,%rbx,4)
incq %rbx
jmp 0xceb8