// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/decoder/decoder.c
// Function: x264_slice_header_ref_pic_reordering(x264_t*, bs_s*)
static int x264_slice_header_ref_pic_reordering(x264_t *h, bs_t *s) {LOG_CALL;
    int b_ok;
    int i;

    /* use the no more use frame */
    h->fdec = h->freference[0];
    h->fdec->i_poc = h->i_poc;

    /* build ref list 0/1 */
    h->i_ref0 = 0;
    h->i_ref1 = 0;
    for (i = 1; i < h->sps->i_num_ref_frames + 1; i++)
    {
        if (h->freference[i]->i_poc >= 0)
        {
            if (h->freference[i]->i_poc < h->fdec->i_poc)
            {
                h->fref0[h->i_ref0++] = h->freference[i];
            } else if (h->freference[i]->i_poc > h->fdec->i_poc)
            {
                h->fref1[h->i_ref1++] = h->freference[i];
            }
        }
    }

    /* Order ref0 from higher to lower poc */
    do
    {
        b_ok = 1;
        for (i = 0; i < h->i_ref0 - 1; i++)
        {
            if (h->fref0[i]->i_poc < h->fref0[i + 1]->i_poc)
            {
                x264_frame_t *tmp = h->fref0[i + 1];

                h->fref0[i + 1] = h->fref0[i];
                h->fref0[i] = tmp;
                b_ok = 0;
                break;
            }
        }
    } while (!b_ok);
    /* Order ref1 from lower to higher poc (bubble sort) for B-frame */
    do
    {
        b_ok = 1;
        for (i = 0; i < h->i_ref1 - 1; i++)
        {
            if (h->fref1[i]->i_poc > h->fref1[i + 1]->i_poc)
            {
                x264_frame_t *tmp = h->fref1[i + 1];

                h->fref1[i + 1] = h->fref1[i];
                h->fref1[i] = tmp;
                b_ok = 0;
                break;
            }
        }
    } while (!b_ok);

    if (h->i_ref0 > h->pps->i_num_ref_idx_l0_active)
    {
        h->i_ref0 = h->pps->i_num_ref_idx_l0_active;
    }
    if (h->i_ref1 > h->pps->i_num_ref_idx_l1_active)
    {
        h->i_ref1 = h->pps->i_num_ref_idx_l1_active;
    }

    //fprintf( stderr,"POC:%d ref0=%d POC0=%d\n", h->fdec->i_poc, h->i_ref0, h->i_ref0 > 0 ? h->fref0[0]->i_poc : -1 );


    /* Now parse the stream and change the default order */
    if (h->sh.i_type != SLICE_TYPE_I && h->sh.i_type != SLICE_TYPE_SI)
    {
        int b_reorder = bs_read1(s,"b_reorder");

        if (b_reorder)
        {
            /* FIXME */
            return -1;
        }
    }
    if (h->sh.i_type == SLICE_TYPE_B)
    {
        int b_reorder = bs_read1(s,"b_reorder");
        if (b_reorder)
        {
            /* FIXME */
            return -1;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x18b49(%rip), %rdi     # 0x28eb0
leaq 0x1af4a(%rip), %rsi     # 0x2b2b8
leaq 0x1b2aa(%rip), %rdx     # 0x2b61f
movb $0x0, %al
callq 0x4d20
movq -0x10(%rbp), %rax
movq 0x10eff0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10efe0(%rax)
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x10efe0(%rax), %rax
movl %ecx, 0x68(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10f078(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10f100(%rax)
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x434(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x104ca
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rax
cmpl $0x0, 0x68(%rax)
jl 0x104ba
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rax
movl 0x68(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x10efe0(%rcx), %rcx
cmpl 0x68(%rcx), %eax
jge 0x1045f
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0x10f078(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x10f078(%rsi)
movslq %ecx, %rcx
movq %rdx, 0x10f080(%rax,%rcx,8)
jmp 0x104b8
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rax
movl 0x68(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x10efe0(%rcx), %rcx
cmpl 0x68(%rcx), %eax
jle 0x104b6
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0x10f100(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x10f100(%rsi)
movslq %ecx, %rcx
movq %rdx, 0x10f108(%rax,%rcx,8)
jmp 0x104b8
jmp 0x104ba
jmp 0x104bc
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x103cd
jmp 0x104cc
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x10f078(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1058a
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10f080(%rax,%rcx,8), %rax
movl 0x68(%rax), %eax
movq -0x10(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq 0x10f080(%rcx,%rdx,8), %rcx
cmpl 0x68(%rcx), %eax
jge 0x1057a
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x10f080(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10f080(%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x10f080(%rax,%rcx,8)
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq %rdx, 0x10f080(%rax,%rcx,8)
movl $0x0, -0x1c(%rbp)
jmp 0x1058a
jmp 0x1057c
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x104da
jmp 0x1058c
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x104cc
jmp 0x1059f
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x10f100(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1065d
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10f108(%rax,%rcx,8), %rax
movl 0x68(%rax), %eax
movq -0x10(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq 0x10f108(%rcx,%rdx,8), %rcx
cmpl 0x68(%rcx), %eax
jle 0x1064d
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq 0x10f108(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x10f108(%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, 0x10f108(%rax,%rcx,8)
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq %rdx, 0x10f108(%rax,%rcx,8)
movl $0x0, -0x1c(%rbp)
jmp 0x1065d
jmp 0x1064f
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x105ad
jmp 0x1065f
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1059f
movq -0x10(%rbp), %rax
movl 0x10f078(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x10dae0(%rcx), %rcx
cmpl 0x1024(%rcx), %eax
jle 0x106a8
movq -0x10(%rbp), %rax
movq 0x10dae0(%rax), %rax
movl 0x1024(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10f078(%rax)
movq -0x10(%rbp), %rax
movl 0x10f100(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x10dae0(%rcx), %rcx
cmpl 0x1028(%rcx), %eax
jle 0x106e0
movq -0x10(%rbp), %rax
movq 0x10dae0(%rax), %rax
movl 0x1028(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10f100(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10db00(%rax)
je 0x1071e
movq -0x10(%rbp), %rax
cmpl $0x4, 0x10db00(%rax)
je 0x1071e
movq -0x18(%rbp), %rdi
leaq 0x1af3f(%rip), %rsi     # 0x2b644
callq 0x10c40
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x1071c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10756
jmp 0x1071e
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10db00(%rax)
jne 0x1074f
movq -0x18(%rbp), %rdi
leaq 0x1af0e(%rip), %rsi     # 0x2b644
callq 0x10c40
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x1074d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10756
jmp 0x1074f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop