// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/decoder/decoder.c
// Function: x264_slice_header_decode(x264_t*, bs_s*, x264_nal_t*)
static int x264_slice_header_decode(x264_t *h, bs_t *s, x264_nal_t *nal) {LOG_CALL;
    /* read the first part of the slice */
    if (x264_slice_header_part1_read(s, &h->sh,
            h->sps_array, h->pps_array,
            nal->i_type == NAL_SLICE_IDR ? 1 : 0) < 0)
    {
        fprintf(stderr, "x264_slice_header_part1_read failed\n");
        return -1;
    }

    //h->sps = h->sh.sps; // arvind
    //h->pps = h->sh.pps;

    /* now reset h if needed for this frame */
    if (h->sps != h->sh.sps || h->pps != h->sh.pps)
    {
        int i;
        /* TODO */

        h->sps = NULL;
        h->pps = NULL;
        if (h->picture->i_width != 0 && h->picture->i_height != 0)
        {
            for (i = 0; i < h->sps->i_num_ref_frames + 1; i++)
            {
                x264_frame_delete(h->freference[i]);
            }
            free(h->mb);
        }

        h->picture->i_width = 0;
        h->picture->i_height = 0;
    }

    /* and init if needed */
    if (h->sps == NULL || h->pps == NULL)
    {
        int i;

        h->sps = h->sh.sps;
        h->pps = h->sh.pps;

        h->param.i_width = h->picture->i_width = 16 * h->sps->i_mb_width;
        h->param.i_height = h->picture->i_height = 16 * h->sps->i_mb_height;

        fprintf(stderr, "x264: %dx%d\n", h->picture->i_width, h->picture->i_height);

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

        for (i = 0; i < h->sps->i_num_ref_frames + 1; i++)
        {
            h->freference[i] = x264_frame_new(h);
            h->freference[i]->i_poc = -1;
        }
        h->fdec = h->freference[0];
        h->i_ref0 = 0;
        h->i_ref1 = 0;

        h->i_poc_msb = 0;
        h->i_poc_lsb = 0;
        h->i_frame_offset = 0;
        h->i_frame_num = 0;
    }

    /* calculate poc for current frame */
    if (h->sps->i_poc_type == 0)
    {
        int i_max_poc_lsb = 1 << h->sps->i_log2_max_poc_lsb;

        if (h->sh.i_poc_lsb < h->i_poc_lsb && h->i_poc_lsb - h->sh.i_poc_lsb >= i_max_poc_lsb / 2)
        {
            h->i_poc_msb += i_max_poc_lsb;
        } else if (h->sh.i_poc_lsb > h->i_poc_lsb && h->sh.i_poc_lsb - h->i_poc_lsb > i_max_poc_lsb / 2)
        {
            h->i_poc_msb -= i_max_poc_lsb;
        }
        h->i_poc_lsb = h->sh.i_poc_lsb;

        h->i_poc = h->i_poc_msb + h->sh.i_poc_lsb;
    } else if (h->sps->i_poc_type == 1)
    {
        /* FIXME */
        return -1;
    } else
    {
        if (nal->i_type == NAL_SLICE_IDR)
        {
            h->i_frame_offset = 0;
            h->i_poc = 0;//https://www.vcodex.com/h264avc-picture-management/
        } else
        {
            if (h->sh.i_frame_num < h->i_frame_num)
            {
                h->i_frame_offset += 1 << h->sps->i_log2_max_frame_num;
            }
            if (nal->i_ref_idc > 0)
            {
                h->i_poc = 2 * (h->i_frame_offset + h->sh.i_frame_num);
            } else
            {
                h->i_poc = 2 * (h->i_frame_offset + h->sh.i_frame_num) - 1;
            }
        }
        h->i_frame_num = h->sh.i_frame_num;
    }

    fprintf(stderr, "x264: pic type=%s poc:%d\n",
            h->sh.i_type == SLICE_TYPE_I ? "I" : (h->sh.i_type == SLICE_TYPE_P ? "P" : "B?"),
            h->i_poc);

    if (h->sh.i_type != SLICE_TYPE_I && h->sh.i_type != SLICE_TYPE_P)
    {
        fprintf(stderr, "only SLICE I/P supported\n");
        return -1;
    }

    /* read and do the ref pic reordering */
    if (x264_slice_header_ref_pic_reordering(h, s) < 0)
    {
        return -1;
    }

    if (((h->sh.i_type == SLICE_TYPE_P || h->sh.i_type == SLICE_TYPE_SP) && h->sh.pps->b_weighted_pred) ||
            (h->sh.i_type == SLICE_TYPE_B && h->sh.pps->b_weighted_bipred))
    {
        if (x264_slice_header_pred_weight_table(h, s) < 0)
        {
            return -1;
        }
    }

    if (nal->i_ref_idc != 0)
    {
        x264_slice_header_dec_ref_pic_marking(h, s, nal->i_type);
    }

    if (x264_slice_header_part2_read(s, &h->sh) < 0)
    {
        return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
leaq 0x19bb5(%rip), %rdi     # 0x28eb0
leaq 0x1bfb6(%rip), %rsi     # 0x2b2b8
leaq 0x1c0ef(%rip), %rdx     # 0x2b3f8
movb $0x0, %al
callq 0x4d20
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x10daf0, %rsi         # imm = 0x10DAF0
movq -0x10(%rbp), %rdx
addq $0xd8, %rdx
movq -0x10(%rbp), %rcx
addq $0x8ee0, %rcx           # imm = 0x8EE0
movq -0x20(%rbp), %rax
movl 0x4(%rax), %r9d
xorl %r8d, %r8d
movl $0x1, %eax
cmpl $0x5, %r9d
cmovel %eax, %r8d
callq 0xff80
cmpl $0x0, %eax
jge 0xf37b
movq 0x26c72(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
leaq 0x1c0a9(%rip), %rsi     # 0x2b411
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10daf0(%rcx), %rax
jne 0xf3af
movq -0x10(%rbp), %rax
movq 0x10dae0(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10daf8(%rcx), %rax
je 0xf463
movq -0x10(%rbp), %rax
movq $0x0, 0x8ed8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x10dae0(%rax)
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
cmpl $0x0, (%rax)
je 0xf440
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
cmpl $0x0, 0x4(%rax)
je 0xf440
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x434(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xf430
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rdi
callq 0x5440
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xf3f5
movq -0x10(%rbp), %rax
movq 0x10efe8(%rax), %rdi
callq 0x2100
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8ed8(%rax)
je 0xf483
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10dae0(%rax)
jne 0xf638
movq -0x10(%rbp), %rax
movq 0x10daf0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8ed8(%rax)
movq -0x10(%rbp), %rax
movq 0x10daf8(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10dae0(%rax)
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x43c(%rax), %ecx
shll $0x4, %ecx
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x84(%rax)
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x440(%rax), %ecx
shll $0x4, %ecx
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x88(%rax)
movq 0x26ac3(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl 0x4(%rax), %ecx
leaq 0x1bf04(%rip), %rsi     # 0x2b436
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x43c(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x440(%rax), %esi
callq 0x7280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10efe8(%rax)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x434(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xf5ce
movq -0x10(%rbp), %rdi
callq 0x52c0
movq %rax, %rdx
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq %rdx, 0x10eff0(%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq 0x10eff0(%rax,%rcx,8), %rax
movl $0xffffffff, 0x68(%rax) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf575
movq -0x10(%rbp), %rax
movq 0x10eff0(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10efe0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10f078(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10f100(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xd0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xd4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xc8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xcc(%rax)
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xf74a
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x20(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x10db1c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xd4(%rcx), %eax
jge 0xf6bb
movq -0x10(%rbp), %rax
movl 0xd4(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10db1c(%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x30(%rbp), %eax
cmpl %ecx, %eax
jl 0xf6bb
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xd0(%rax), %ecx
movl %ecx, 0xd0(%rax)
jmp 0xf713
movq -0x10(%rbp), %rax
movl 0x10db1c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xd4(%rcx), %eax
jle 0xf711
movq -0x10(%rbp), %rax
movl 0x10db1c(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xd4(%rcx), %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x34(%rbp), %eax
cmpl %ecx, %eax
jle 0xf711
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0xd0(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xd0(%rax)
jmp 0xf713
movq -0x10(%rbp), %rax
movl 0x10db1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xd4(%rax)
movq -0x10(%rbp), %rax
movl 0xd0(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x10db1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc4(%rax)
jmp 0xf835
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
cmpl $0x1, 0x1c(%rax)
jne 0xf767
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
movq -0x20(%rbp), %rax
cmpl $0x5, 0x4(%rax)
jne 0xf792
movq -0x10(%rbp), %rax
movl $0x0, 0xc8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xc4(%rax)
jmp 0xf81f
movq -0x10(%rbp), %rax
movl 0x10db0c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xcc(%rcx), %eax
jge 0xf7cf
movq -0x10(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x18(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
addl 0xc8(%rax), %ecx
movl %ecx, 0xc8(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jle 0xf7fa
movq -0x10(%rbp), %rax
movl 0xc8(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x10db0c(%rax), %ecx
shll %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc4(%rax)
jmp 0xf81d
movq -0x10(%rbp), %rax
movl 0xc8(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x10db0c(%rax), %ecx
shll %ecx
subl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc4(%rax)
jmp 0xf81f
movq -0x10(%rbp), %rax
movl 0x10db0c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xcc(%rax)
jmp 0xf835
movq 0x26794(%rip), %rax     # 0x35fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10db00(%rax)
jne 0xf85d
leaq 0x2054e(%rip), %rax     # 0x2fda5
movq %rax, -0x48(%rbp)
jmp 0xf880
movq -0x10(%rbp), %rax
movl 0x10db00(%rax), %edx
leaq 0x1bbf1(%rip), %rax     # 0x2b45f
leaq 0x1bbe8(%rip), %rcx     # 0x2b45d
cmpl $0x0, %edx
cmoveq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0xc4(%rax), %ecx
leaq 0x1bbaa(%rip), %rsi     # 0x2b443
movb $0x0, %al
callq 0x2160
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10db00(%rax)
je 0xf8de
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10db00(%rax)
je 0xf8de
movq 0x2670f(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
leaq 0x1bb97(%rip), %rsi     # 0x2b462
movb $0x0, %al
callq 0x2160
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x10350
cmpl $0x0, %eax
jge 0xf8fc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10db00(%rax)
je 0xf916
movq -0x10(%rbp), %rax
cmpl $0x3, 0x10db00(%rax)
jne 0xf92a
movq -0x10(%rbp), %rax
movq 0x10daf8(%rax), %rax
cmpl $0x0, 0x102c(%rax)
jne 0xf94b
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10db00(%rax)
jne 0xf968
movq -0x10(%rbp), %rax
movq 0x10daf8(%rax), %rax
cmpl $0x0, 0x1030(%rax)
je 0xf968
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x10760
cmpl $0x0, %eax
jge 0xf966
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
jmp 0xf968
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0xf985
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
callq 0x107a0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x10daf0, %rsi         # imm = 0x10DAF0
callq 0x10850
cmpl $0x0, %eax
jge 0xf9a7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9ae
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)