// File: /workspace/github_c_makefile_star2_O1/akumrao[P]videoAnalyzer/core/macroblock.c
// Function: x264_macroblock_context_load(x264_t*, x264_macroblock_t*, x264_mb_context_t*)
void x264_macroblock_context_load(x264_t *h, x264_macroblock_t *mb, x264_mb_context_t *context) {LOG_CALL;
    int ch;
    int i, j;

    x264_macroblock_t *a = NULL;
    x264_macroblock_t *b = NULL;

    mb->context = context;

    if (mb->i_neighbour & MB_LEFT)
    {
        a = mb - 1;
    }
    context->mba = a;

    if (mb->i_neighbour & MB_TOP)
    {
        b = mb - h->sps->i_mb_width;
    }
    context->mbb = b;

    context->mbc = NULL;
    if (mb->i_neighbour & MB_TOPRIGHT)
    {
        context->mbc = b + 1;
    }

#define LOAD_PTR( dst, src ) \
    context->p_##dst[0] = (src)->plane[0] + 16 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[0] ); \
    context->p_##dst[1] = (src)->plane[1] +  8 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[1] ); \
    context->p_##dst[2] = (src)->plane[2] +  8 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[2] ); \
    context->i_##dst[0] = (src)->i_stride[0]; \
    context->i_##dst[1] = (src)->i_stride[1]; \
    context->i_##dst[2] = (src)->i_stride[2]

    LOAD_PTR(img, h->picture);
    LOAD_PTR(fdec, h->fdec);  //     /* frame being reconstructed */  x264_frame_t      *fdec;
    
    for (i = 0; i < h->i_ref0; i++)
    {
        LOAD_PTR(fref0[i], h->fref0[i]);
    }
    
    for (i = 0; i < h->i_ref1; i++)
    {
        LOAD_PTR(fref1[i], h->fref1[i]);
    }
    
#undef LOAD_PTR

    for (i = 0; i < 4; i++)
    {
        /* left */
        context->block[block_idx_xy[0][i]].mba = a;
        context->block[block_idx_xy[0][i]].bka = a ? &a->block[block_idx_xy[3][i]] : NULL;
        
        myPrintf("A context->block (%d%d -> %d%d), left src= %d , dest=%d \n", 3,i,0,i, block_idx_xy[3][i], block_idx_xy[0][i]  );

        /* up */
        context->block[block_idx_xy[i][0]].mbb = b;
        context->block[block_idx_xy[i][0]].bkb = b ? &b->block[block_idx_xy[i][3]] : NULL;
        
        myPrintf("B context->block (%d%d -> %d%d), up src= %d , dest=%d \n",i,3,i,0, block_idx_xy[i][3], block_idx_xy[i][0]  );

        /* rest */
        for (j = 1; j < 4; j++)
        {
            context->block[block_idx_xy[j][i]].mba = mb;
            context->block[block_idx_xy[j][i]].bka = &mb->block[block_idx_xy[j - 1][i]];
            
            myPrintf("A context->block (%d%d -> %d%d), rest src= %d , dest=%d \n",j-1,i,j,i, block_idx_xy[j - 1][i], block_idx_xy[j][i]  );

            context->block[block_idx_xy[i][j]].mbb = mb;
            context->block[block_idx_xy[i][j]].bkb = &mb->block[block_idx_xy[i][j - 1]];
            
            myPrintf("B context->block (%d%d -> %d%d), rest src= %d , dest=%d \n", i,j-1, j,i, block_idx_xy[i][j - 1], block_idx_xy[j][i]  );
        }
    }

    myPrintf("context->block uv  \n" );
    
    for (ch = 0; ch < 2; ch++)
    {
        if(! ch)
        myPrintf("context->block u \n" );
        else
        myPrintf("context->block v \n" );
            
        for (i = 0; i < 2; i++)
        {
            /* left */
            context->block[16 + 4 * ch + block_idx_xy[0][i]].mba = a;
            context->block[16 + 4 * ch + block_idx_xy[0][i]].bka = a ? &a->block[16 + 4 * ch + block_idx_xy[1][i]] : NULL;
            myPrintf("A context->block (%d%d -> %d%d), left src= %d , dest=%d \n", 1,i,0,i,  16 + 4 * ch + block_idx_xy[1][i], 16 + 4 * ch + block_idx_xy[0][i]  );
            /* up */
            context->block[16 + 4 * ch + block_idx_xy[i][0]].mbb = b;
            context->block[16 + 4 * ch + block_idx_xy[i][0]].bkb = b ? &b->block[16 + 4 * ch + block_idx_xy[i][1]] : NULL;
            myPrintf("B context->block (%d%d -> %d%d), up src= %d , dest=%d \n", i,1,i,0, 16 + 4 * ch + block_idx_xy[i][1], 16 + 4 * ch + block_idx_xy[i][0] );
            /* rest */
            context->block[16 + 4 * ch + block_idx_xy[1][i]].mba = mb;
            context->block[16 + 4 * ch + block_idx_xy[1][i]].bka = &mb->block[16 + 4 * ch + block_idx_xy[0][i]];
            myPrintf("A context->block (%d%d -> %d%d), rest src= %d , dest=%d \n", 0,i,1,i, 16 + 4 * ch + block_idx_xy[0][i], 16 + 4 * ch + block_idx_xy[1][i] );
            context->block[16 + 4 * ch + block_idx_xy[i][1]].mbb = mb;
            context->block[16 + 4 * ch + block_idx_xy[i][1]].bkb = &mb->block[16 + 4 * ch + block_idx_xy[i][0]];
            myPrintf("B context->block (%d%d -> %d%d), rest src= %d , dest=%d \n", i,0,i,1, 16 + 4 * ch + block_idx_xy[i][0], 16 + 4 * ch + block_idx_xy[i][1]  );
        }
        
        
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x1d136(%rip), %rdi     # 0x251b4
leaq 0x1d7ab(%rip), %rsi     # 0x25830
leaq 0x1d8c9(%rip), %rdx     # 0x25955
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x4c22
movq %rbx, 0x10(%r12)
movl 0x8(%r12), %eax
leaq -0xf88(%r12), %rcx
testb $0x1, %al
cmoveq %r14, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, (%rbx)
movl %eax, -0x34(%rbp)
testb $0x2, %al
je 0x80d7
movq 0x8ed8(%r15), %rax
movslq 0x43c(%rax), %rax
negq %rax
imulq $0xf88, %rax, %r14      # imm = 0xF88
addq %r12, %r14
movq %r14, 0x8(%rbx)
leaq 0xf88(%r14), %rax
xorl %ecx, %ecx
testb $0x4, -0x34(%rbp)
cmovneq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq 0x10ee48(%r15), %rdx
movl (%r12), %ecx
movl 0x4(%r12), %eax
movl 0xc(%rdx), %esi
imull %eax, %esi
addl %ecx, %esi
shll $0x4, %esi
movslq %esi, %rsi
addq 0x20(%rdx), %rsi
movq %rsi, 0x18(%rbx)
movq 0x10ee48(%r15), %rdx
movl 0x10(%rdx), %esi
imull %eax, %esi
addl %ecx, %esi
shll $0x3, %esi
movslq %esi, %rsi
addq 0x28(%rdx), %rsi
movq %rsi, 0x20(%rbx)
movq 0x10ee48(%r15), %rdx
imull 0x14(%rdx), %eax
addl %ecx, %eax
shll $0x3, %eax
cltq
addq 0x30(%rdx), %rax
movq %rax, 0x28(%rbx)
movq 0x10ee48(%r15), %rax
movl 0xc(%rax), %ecx
movl %ecx, 0x30(%rbx)
movl 0x10(%rax), %ecx
movl %ecx, 0x34(%rbx)
movl 0x14(%rax), %eax
movl %eax, 0x38(%rbx)
movq 0x10efe0(%r15), %rdx
movl (%r12), %ecx
movl 0x4(%r12), %eax
movl 0x24(%rdx), %esi
imull %eax, %esi
addl %ecx, %esi
shll $0x4, %esi
movslq %esi, %rsi
addq 0x48(%rdx), %rsi
movq %rsi, 0x40(%rbx)
movq 0x10efe0(%r15), %rdx
movl 0x28(%rdx), %esi
imull %eax, %esi
addl %ecx, %esi
shll $0x3, %esi
movslq %esi, %rsi
addq 0x50(%rdx), %rsi
movq %rsi, 0x48(%rbx)
movq 0x10efe0(%r15), %rdx
imull 0x2c(%rdx), %eax
addl %ecx, %eax
shll $0x3, %eax
cltq
addq 0x58(%rdx), %rax
movq %rax, 0x50(%rbx)
movq 0x10efe0(%r15), %rax
movl 0x24(%rax), %ecx
movl %ecx, 0x58(%rbx)
movl 0x28(%rax), %ecx
movl %ecx, 0x5c(%rbx)
movl 0x2c(%rax), %eax
movl %eax, 0x60(%rbx)
cmpl $0x0, 0x10f078(%r15)
jle 0x8297
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10f080(%r15,%rcx,8), %rdi
movl (%r12), %esi
movl 0x4(%r12), %edx
movl 0x24(%rdi), %r8d
imull %edx, %r8d
addl %esi, %r8d
shll $0x4, %r8d
movslq %r8d, %r8
addq 0x48(%rdi), %r8
movq %r8, 0x68(%rbx,%rax,2)
movq 0x10f080(%r15,%rcx,8), %rdi
movl 0x28(%rdi), %r8d
imull %edx, %r8d
addl %esi, %r8d
shll $0x3, %r8d
movslq %r8d, %r8
addq 0x50(%rdi), %r8
movq %r8, 0x70(%rbx,%rax,2)
movq 0x10f080(%r15,%rcx,8), %rdi
imull 0x2c(%rdi), %edx
addl %esi, %edx
shll $0x3, %edx
movslq %edx, %rdx
addq 0x58(%rdi), %rdx
movq %rdx, 0x78(%rbx,%rax,2)
movq 0x10f080(%r15,%rcx,8), %rdx
movl 0x24(%rdx), %esi
movl %esi, 0x1e8(%rbx,%rax)
movl 0x28(%rdx), %esi
movl %esi, 0x1ec(%rbx,%rax)
movl 0x2c(%rdx), %edx
movl %edx, 0x1f0(%rbx,%rax)
incq %rcx
movslq 0x10f078(%r15), %rdx
addq $0xc, %rax
cmpq %rdx, %rcx
jl 0x81ee
cmpl $0x0, 0x10f100(%r15)
jle 0x835b
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10f108(%r15,%rcx,8), %rdi
movl (%r12), %esi
movl 0x4(%r12), %edx
movl 0x24(%rdi), %r8d
imull %edx, %r8d
addl %esi, %r8d
shll $0x4, %r8d
movslq %r8d, %r8
addq 0x48(%rdi), %r8
movq %r8, 0x2a8(%rbx,%rax,2)
movq 0x10f108(%r15,%rcx,8), %rdi
movl 0x28(%rdi), %r8d
imull %edx, %r8d
addl %esi, %r8d
shll $0x3, %r8d
movslq %r8d, %r8
addq 0x50(%rdi), %r8
movq %r8, 0x2b0(%rbx,%rax,2)
movq 0x10f108(%r15,%rcx,8), %rdi
imull 0x2c(%rdi), %edx
addl %esi, %edx
shll $0x3, %edx
movslq %edx, %rdx
addq 0x58(%rdi), %rdx
movq %rdx, 0x2b8(%rbx,%rax,2)
movq 0x10f108(%r15,%rcx,8), %rdx
movl 0x24(%rdx), %esi
movl %esi, 0x428(%rbx,%rax)
movl 0x28(%rdx), %esi
movl %esi, 0x42c(%rbx,%rax)
movl 0x2c(%rdx), %edx
movl %edx, 0x430(%rbx,%rax)
incq %rcx
movslq 0x10f100(%r15), %rdx
addq $0xc, %rax
cmpq %rdx, %rcx
jl 0x82a9
addq $0x4e8, %rbx            # imm = 0x4E8
movl $0x324, %ecx            # imm = 0x324
movq -0x40(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x68(%rbp)
leaq (%r14,%rcx), %rax
movq %rax, -0x70(%rbp)
movq %r12, -0x78(%rbp)
addq %r12, %rcx
movq %rcx, -0x60(%rbp)
leaq 0x1cf78(%rip), %r15     # 0x25304
leaq 0x1cf6e(%rip), %rax     # 0x25301
leaq 0x1cf66(%rip), %rsi     # 0x25300
xorl %r13d, %r13d
movq %r14, -0x80(%rbp)
movq %rbx, -0x30(%rbp)
movq -0x78(%rbp), %r12
movq %rax, -0x58(%rbp)
movzbl (%r13,%rsi), %eax
movl %eax, %ecx
shll $0x5, %ecx
movq -0x40(%rbp), %rdx
movq %rdx, (%rbx,%rcx)
testb $0x1, -0x34(%rbp)
jne 0x83ca
xorl %ecx, %ecx
jmp 0x83dd
movzbl 0xc(%r13,%rsi), %ecx
movl %ecx, %edx
shll $0x7, %edx
leaq (%rdx,%rcx,4), %rcx
addq -0x68(%rbp), %rcx
movl %eax, %edx
shll $0x5, %edx
movq %rcx, 0x10(%rbx,%rdx)
movzbl 0xc(%r13,%rsi), %r9d
movl %eax, (%rsp)
leaq 0x1d57b(%rip), %rdi     # 0x25972
movl $0x3, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x4c22
leaq 0x1ceee(%rip), %rsi     # 0x25300
movzbl (%rsi,%r13,4), %eax
movl %eax, %ecx
shll $0x5, %ecx
movq %r14, 0x8(%rbx,%rcx)
testq %r14, %r14
je 0x843b
movzbl 0x3(%rsi,%r13,4), %ecx
movl %ecx, %edx
shll $0x7, %edx
leaq (%rdx,%rcx,4), %rcx
addq -0x70(%rbp), %rcx
jmp 0x843d
xorl %ecx, %ecx
movl %eax, %edx
shll $0x5, %edx
movq %rcx, 0x18(%rbx,%rdx)
movzbl 0x3(%rsi,%r13,4), %r9d
movl %eax, (%rsp)
leaq 0x1d555(%rip), %rdi     # 0x259ac
movl %r13d, %esi
movl $0x3, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4c22
movq %r13, -0x48(%rbp)
xorl %r14d, %r14d
movq %r15, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movzbl (%rcx,%r14,4), %r15d
movl %r15d, %eax
shll $0x5, %eax
movq %r12, (%rbx,%rax)
movzbl -0x4(%rcx,%r14,4), %r9d
movl %r9d, %ecx
shll $0x7, %ecx
leaq (%rcx,%r9,4), %rcx
addq -0x60(%rbp), %rcx
movq %rcx, 0x10(%rbx,%rax)
leaq 0x1(%r14), %rbx
movl %r15d, (%rsp)
leaq 0x1d532(%rip), %rdi     # 0x259e4
movl %r14d, %esi
movq -0x48(%rbp), %r13
movl %r13d, %edx
movl %ebx, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x4c22
movq -0x58(%rbp), %rdx
movzbl (%rdx,%r14), %eax
shll $0x5, %eax
movq -0x30(%rbp), %rcx
movq %r12, 0x8(%rcx,%rax)
movzbl -0x1(%rdx,%r14), %r9d
movl %r9d, %ecx
shll $0x7, %ecx
leaq (%rcx,%r9,4), %rcx
addq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x18(%rdx,%rax)
movl %r15d, (%rsp)
leaq 0x1d519(%rip), %rdi     # 0x25a1e
movl %r13d, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x4c22
movq %rbx, %r14
cmpq $0x3, %rbx
movq -0x30(%rbp), %rbx
jne 0x8477
movq -0x48(%rbp), %r13
incq %r13
movq -0x50(%rbp), %r15
incq %r15
movq -0x58(%rbp), %rax
addq $0x4, %rax
cmpq $0x4, %r13
movq -0x80(%rbp), %r14
leaq 0x1cdb3(%rip), %rsi     # 0x25300
jne 0x83a9
leaq 0x1d4fe(%rip), %rdi     # 0x25a58
xorl %eax, %eax
callq 0x4c22
movl $0x324, %ecx            # imm = 0x324
movq -0x40(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x68(%rbp)
leaq (%r14,%rcx), %rax
movq %rax, -0x70(%rbp)
addq -0x78(%rbp), %rcx
movq %rcx, -0x48(%rbp)
xorl %r15d, %r15d
testl %r15d, %r15d
leaq 0x1d4f2(%rip), %rdi     # 0x25a80
leaq 0x1d4d8(%rip), %rax     # 0x25a6d
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x4c22
movq %r15, -0x88(%rbp)
leal 0x10(,%r15,4), %r13d
xorl %r12d, %r12d
leaq 0x1cd47(%rip), %rsi     # 0x25300
movl %r13d, -0x50(%rbp)
movzbl (%r12,%rsi), %edi
addl %r13d, %edi
movq %rdi, %rax
shlq $0x5, %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rbx,%rax)
testb $0x1, -0x34(%rbp)
jne 0x85de
xorl %ecx, %ecx
jmp 0x85f6
movzbl 0x4(%r12,%rsi), %ecx
addl %r13d, %ecx
movq %rcx, %rdx
shlq $0x7, %rdx
leaq (%rdx,%rcx,4), %rcx
addq -0x68(%rbp), %rcx
movq %rcx, 0x10(%rbx,%rax)
movzbl 0x4(%r12,%rsi), %r9d
addl %r13d, %r9d
movq %rdi, -0x60(%rbp)
movl %edi, (%rsp)
leaq 0x1d360(%rip), %rdi     # 0x25972
movl $0x1, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
movl %r9d, -0x58(%rbp)
xorl %eax, %eax
callq 0x4c22
leaq 0x1cccf(%rip), %rsi     # 0x25300
movzbl (%rsi,%r12,4), %r15d
addl %r13d, %r15d
movq %r15, %rax
shlq $0x5, %rax
movq %r14, 0x8(%rbx,%rax)
testq %r14, %r14
je 0x8664
movzbl 0x1(%rsi,%r12,4), %ecx
addl %r13d, %ecx
movq %rcx, %rdx
shlq $0x7, %rdx
leaq (%rdx,%rcx,4), %rcx
addq -0x70(%rbp), %rcx
jmp 0x8666
xorl %ecx, %ecx
movq %rcx, 0x18(%rbx,%rax)
movzbl 0x1(%rsi,%r12,4), %ebx
addl %r13d, %ebx
movl %r15d, (%rsp)
leaq 0x1d32d(%rip), %rdi     # 0x259ac
movl %r12d, %esi
movl $0x1, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x4c22
movl -0x58(%rbp), %esi
movl %esi, %eax
shlq $0x5, %rax
movq -0x30(%rbp), %rcx
movq -0x78(%rbp), %r13
movq %r13, (%rcx,%rax)
movq -0x60(%rbp), %r9
movq %r9, %rcx
shlq $0x7, %rcx
leaq (%rcx,%r9,4), %rcx
movq -0x48(%rbp), %r14
addq %r14, %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x10(%rdx,%rax)
movl %esi, (%rsp)
leaq 0x1d30f(%rip), %rdi     # 0x259e4
xorl %esi, %esi
movl %r12d, %edx
movl $0x1, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x4c22
movq %rbx, %rax
shlq $0x5, %rax
movq -0x30(%rbp), %rcx
movq %r13, 0x8(%rcx,%rax)
movl -0x50(%rbp), %r13d
movq %r15, %rcx
shlq $0x7, %rcx
leaq (%rcx,%r15,4), %rcx
addq %r14, %rcx
movq -0x30(%rbp), %rdx
movq %rcx, 0x18(%rdx,%rax)
movl %ebx, (%rsp)
movq -0x30(%rbp), %rbx
leaq 0x1d2fc(%rip), %rdi     # 0x25a1e
movl %r12d, %esi
xorl %edx, %edx
movl %r12d, %ecx
movl $0x1, %r8d
movl %r15d, %r9d
xorl %eax, %eax
callq 0x4c22
leaq 0x1cbbf(%rip), %rsi     # 0x25300
incq %r12
cmpq $0x1, %r12
movq -0x80(%rbp), %r14
je 0x85bd
movq -0x88(%rbp), %rcx
leal 0x1(%rcx), %eax
testl %ecx, %ecx
movl %eax, %r15d
je 0x8584
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop