// File: /workspace/github_c_makefile_star2_O0/akumrao[P]videoAnalyzer/decoder/decoder.c
// Function: x264_slice_data_decode(x264_t*, bs_s*)
static int x264_slice_data_decode(x264_t *h, bs_t *s) {LOG_CALL;
    int mb_xy = h->sh.i_first_mb;
    int i_ret = 0;

    if (h->pps->b_cabac)
    {
        /* TODO: alignement and cabac init */
    }

    /* FIXME field decoding */
    for (;;)
    {
        myPrintf("mb_xy %d/n", mb_xy);
        
        x264_mb_context_t context;
        x264_macroblock_t *mb;

        if (mb_xy >= h->sps->i_mb_width * h->sps->i_mb_height)
        {
            break;
        }

        mb = &h->mb[mb_xy];

        /* load neighbour */
        x264_macroblock_context_load(h, mb, &context);


        if (h->pps->b_cabac)
        {
            if (h->sh.i_type != SLICE_TYPE_I && h->sh.i_type != SLICE_TYPE_SI)
            {
                /* TODO */
            }
            i_ret = x264_macroblock_read_cabac(h, s, mb);
        } else// cavlc
        {
            if (h->sh.i_type != SLICE_TYPE_I && h->sh.i_type != SLICE_TYPE_SI)
            {
                int i_skip = bs_read_ue(s,"i_skip");

                while (i_skip > 0)
                {
                    x264_macroblock_decode_skip(h, mb);

                    /* next macroblock */
                    mb_xy++;
                    if (mb_xy >= h->sps->i_mb_width * h->sps->i_mb_height)
                    {
                        break;
                    }
                    mb++;

                    /* load neighbour */
                    x264_macroblock_context_load(h, mb, &context);

                    i_skip--;
                }
                if (mb_xy >= h->sps->i_mb_width * h->sps->i_mb_height)
                {
                    break;
                }
            }
            i_ret = x264_macroblock_read_cavlc(h, s, mb);
        }

        if (i_ret < 0)
        {
            fprintf(stderr, "x264_macroblock_read failed [%d,%d]\n", mb->i_mb_x, mb->i_mb_y);
            break;
        }

        if (x264_macroblock_decode(h, mb) < 0)
        {
            fprintf(stderr, "x264_macroblock_decode failed\n");
            /* try to do some error correction ;) */
        }

        mb_xy++;
    }

    if (i_ret >= 0)
    {
        int i;

        /* expand border for frame reference TODO avoid it when using b-frame */
        x264_frame_expand_border(h->fdec);

        /* apply deblocking filter to the current decoded picture */
        if (!h->pps->b_deblocking_filter_control || h->sh.i_disable_deblocking_filter_idc != 1)
        {
            x264_frame_deblocking_filter(h, h->sh.i_type);
        }

#if 0
        /* expand border for frame reference TODO avoid it when using b-frame */
        x264_frame_expand_border(h->fdec);
#endif

        h->picture->i_plane = h->fdec->i_plane;
        for (i = 0; i < h->picture->i_plane; i++)
        {
            h->picture->i_stride[i] = h->fdec->i_stride[i];
            h->picture->plane[i] = h->fdec->plane[i];
        }

        /* move frame in the buffer FIXME won't work for B-frame */
        h->fdec = h->freference[h->sps->i_num_ref_frames];
        for (i = h->sps->i_num_ref_frames; i > 0; i--)
        {
            h->freference[i] = h->freference[i - 1];
        }
        h->freference[0] = h->fdec;
    }

    return i_ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x810, %rsp            # imm = 0x810
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x194d6(%rip), %rdi     # 0x28eb0
leaq 0x1b8d7(%rip), %rsi     # 0x2b2b8
leaq 0x1bd99(%rip), %rdx     # 0x2b781
movb $0x0, %al
callq 0x4d20
movq -0x8(%rbp), %rax
movl 0x10db04(%rax), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x10dae0(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xfa16
jmp 0xfa16
jmp 0xfa18
movl -0x14(%rbp), %esi
leaq 0x1bd76(%rip), %rdi     # 0x2b798
movb $0x0, %al
callq 0x4d20
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x43c(%rcx), %ecx
movq -0x8(%rbp), %rdx
movq 0x8ed8(%rdx), %rdx
imull 0x440(%rdx), %ecx
cmpl %ecx, %eax
jl 0xfa58
jmp 0xfc57
movq -0x8(%rbp), %rax
movq 0x10efe8(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0xf88, %rcx, %rcx      # imm = 0xF88
addq %rcx, %rax
movq %rax, -0x808(%rbp)
movq -0x8(%rbp), %rdi
movq -0x808(%rbp), %rsi
leaq -0x800(%rbp), %rdx
callq 0x9cb0
movq -0x8(%rbp), %rax
movq 0x10dae0(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xfad8
movq -0x8(%rbp), %rax
cmpl $0x2, 0x10db00(%rax)
je 0xfabc
movq -0x8(%rbp), %rax
cmpl $0x4, 0x10db00(%rax)
je 0xfabc
jmp 0xfabc
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x808(%rbp), %rdx
callq 0x114e0
movl %eax, -0x18(%rbp)
jmp 0xfbe9
movq -0x8(%rbp), %rax
cmpl $0x2, 0x10db00(%rax)
je 0xfbd2
movq -0x8(%rbp), %rax
cmpl $0x4, 0x10db00(%rax)
je 0xfbd2
movq -0x10(%rbp), %rdi
leaq 0x1bc9e(%rip), %rsi     # 0x2b7a3
callq 0x109f0
movl %eax, -0x80c(%rbp)
cmpl $0x0, -0x80c(%rbp)
jle 0xfba1
movq -0x8(%rbp), %rdi
movq -0x808(%rbp), %rsi
callq 0x13990
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x43c(%rcx), %ecx
movq -0x8(%rbp), %rdx
movq 0x8ed8(%rdx), %rdx
imull 0x440(%rdx), %ecx
cmpl %ecx, %eax
jl 0xfb62
jmp 0xfba1
movq -0x808(%rbp), %rax
addq $0xf88, %rax            # imm = 0xF88
movq %rax, -0x808(%rbp)
movq -0x8(%rbp), %rdi
movq -0x808(%rbp), %rsi
leaq -0x800(%rbp), %rdx
callq 0x9cb0
movl -0x80c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x80c(%rbp)
jmp 0xfb10
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movl 0x43c(%rcx), %ecx
movq -0x8(%rbp), %rdx
movq 0x8ed8(%rdx), %rdx
imull 0x440(%rdx), %ecx
cmpl %ecx, %eax
jl 0xfbd0
jmp 0xfc57
jmp 0xfbd2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x808(%rbp), %rdx
callq 0x11520
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0xfc1c
movq 0x263da(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
movq -0x808(%rbp), %rax
movl (%rax), %edx
movq -0x808(%rbp), %rax
movl 0x4(%rax), %ecx
leaq 0x1bb97(%rip), %rsi     # 0x2b7aa
movb $0x0, %al
callq 0x2160
jmp 0xfc57
movq -0x8(%rbp), %rdi
movq -0x808(%rbp), %rsi
callq 0x12c90
cmpl $0x0, %eax
jge 0xfc49
movq 0x26398(%rip), %rax     # 0x35fd0
movq (%rax), %rdi
leaq 0x1bb8d(%rip), %rsi     # 0x2b7cf
movb $0x0, %al
callq 0x2160
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xfa18
cmpl $0x0, -0x18(%rbp)
jl 0xfdea
movq -0x8(%rbp), %rax
movq 0x10efe0(%rax), %rdi
callq 0x5640
movq -0x8(%rbp), %rax
movq 0x10dae0(%rax), %rax
cmpl $0x0, 0x1040(%rax)
je 0xfc92
movq -0x8(%rbp), %rax
cmpl $0x1, 0x10db50(%rax)
je 0xfca5
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x10db00(%rax), %esi
callq 0x5a90
movq -0x8(%rbp), %rax
movq 0x10efe0(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movq 0x10ee48(%rax), %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x810(%rbp)
movl -0x810(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x10ee48(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xfd4f
movq -0x8(%rbp), %rax
movq 0x10efe0(%rax), %rax
movslq -0x810(%rbp), %rcx
movl 0x24(%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x10ee48(%rax), %rax
movslq -0x810(%rbp), %rcx
movl %edx, 0xc(%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x10efe0(%rax), %rax
movslq -0x810(%rbp), %rcx
movq 0x48(%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq 0x10ee48(%rax), %rax
movslq -0x810(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movl -0x810(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x810(%rbp)
jmp 0xfccb
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8ed8(%rcx), %rcx
movslq 0x434(%rcx), %rcx
movq 0x10eff0(%rax,%rcx,8), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10efe0(%rax)
movq -0x8(%rbp), %rax
movq 0x8ed8(%rax), %rax
movl 0x434(%rax), %eax
movl %eax, -0x810(%rbp)
cmpl $0x0, -0x810(%rbp)
jle 0xfdd4
movq -0x8(%rbp), %rax
movl -0x810(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x10eff0(%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movslq -0x810(%rbp), %rcx
movq %rdx, 0x10eff0(%rax,%rcx,8)
movl -0x810(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x810(%rbp)
jmp 0xfd8f
movq -0x8(%rbp), %rax
movq 0x10efe0(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10eff0(%rax)
movl -0x18(%rbp), %eax
addq $0x810, %rsp            # imm = 0x810
popq %rbp
retq
nopw %cs:(%rax,%rax)