// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %r15
leaq 0x1f2ae(%rip), %rdi     # 0x271b4
leaq 0x1f923(%rip), %rsi     # 0x27830
leaq 0x1fa41(%rip), %rdx     # 0x27955
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x4a56
movq %rbx, 0x10(%r14)
movl 0x8(%r14), %r9d
leaq -0xf88(%r14), %r10
testb $0x1, %r9b
cmoveq %r12, %r10
movq %r10, (%rbx)
testb $0x2, %r9b
je 0x7f59
movq 0x8ed8(%r15), %rax
movslq 0x43c(%rax), %rax
negq %rax
imulq $0xf88, %rax, %r12      # imm = 0xF88
addq %r14, %r12
movq %r12, 0x8(%rbx)
leaq 0xf88(%r12), %rax
xorl %ecx, %ecx
testb $0x4, %r9b
cmovneq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq 0x10ee48(%r15), %rdx
movl (%r14), %ecx
movl 0x4(%r14), %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 (%r14), %ecx
movl 0x4(%r14), %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 0x8114
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10f080(%r15,%rcx,8), %rdi
movl (%r14), %esi
movl 0x4(%r14), %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 0x806d
movl %r9d, -0x34(%rbp)
cmpl $0x0, 0x10f100(%r15)
jle 0x81da
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10f108(%r15,%rcx,8), %rdi
movl (%r14), %esi
movl 0x4(%r14), %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 0x812a
addq $0x4e8, %rbx            # imm = 0x4E8
movq %rbx, -0x60(%rbp)
leaq -0xc64(%r14), %r13
movl $0x324, %eax            # imm = 0x324
movq %r12, -0x88(%rbp)
leaq (%r12,%rax), %rcx
movq %rcx, -0x70(%rbp)
movq %r14, -0x58(%rbp)
addq %r14, %rax
movq %rax, -0x50(%rbp)
leaq 0x1f0f2(%rip), %rax     # 0x27304
leaq 0x1f0e8(%rip), %rcx     # 0x27301
leaq 0x1f0e0(%rip), %r14     # 0x27300
movq $0x0, -0x30(%rbp)
movq %r10, -0x80(%rbp)
movq %r13, -0x78(%rbp)
movq %rcx, -0x40(%rbp)
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %r12
movzbl (%r12,%r14), %r15d
movl %r15d, %eax
shll $0x5, %eax
movzbl 0xc(%r12,%r14), %r9d
movl %r9d, %ecx
shll $0x7, %ecx
leaq (%rcx,%r9,4), %rcx
addq %r13, %rcx
testb $0x1, -0x34(%rbp)
movq -0x60(%rbp), %rbx
movq %r10, (%rbx,%rax)
movl $0x0, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x10(%rbx,%rax)
movl %r15d, (%rsp)
leaq 0x1f6f3(%rip), %rdi     # 0x27972
movl $0x3, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x4a56
movzbl (%r14,%r12,4), %eax
movl %eax, %ecx
shll $0x5, %ecx
movzbl 0x3(%r14,%r12,4), %r9d
movl %r9d, %edx
shll $0x7, %edx
leaq (%rdx,%r9,4), %rdx
addq -0x70(%rbp), %rdx
movq -0x88(%rbp), %rsi
testq %rsi, %rsi
movq %rsi, 0x8(%rbx,%rcx)
cmoveq %rsi, %rdx
movq %rdx, 0x18(%rbx,%rcx)
movl %eax, (%rsp)
leaq 0x1f6d9(%rip), %rdi     # 0x279ac
movl %r12d, %esi
movl $0x3, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4a56
xorl %r14d, %r14d
leaq 0x1(%r14), %r13
movq -0x48(%rbp), %rax
movzbl (%rax,%r14,4), %ebx
movl %ebx, %eax
shll $0x5, %eax
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %rcx
movq %rcx, (%r12,%rax)
movzbl %r15b, %r9d
movl %r9d, %ecx
shll $0x7, %ecx
leaq (%rcx,%r9,4), %rcx
addq -0x50(%rbp), %rcx
movq %rcx, 0x10(%r12,%rax)
movl %ebx, (%rsp)
leaq 0x1f6ba(%rip), %rdi     # 0x279e4
movl %r14d, %esi
movq -0x30(%rbp), %r15
movl %r15d, %edx
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x4a56
movq -0x40(%rbp), %rcx
movzbl (%rcx,%r14), %eax
shll $0x5, %eax
movq -0x58(%rbp), %rdx
movq %rdx, 0x8(%r12,%rax)
movzbl -0x1(%rcx,%r14), %r9d
movl %r9d, %ecx
shll $0x7, %ecx
leaq (%rcx,%r9,4), %rcx
addq -0x50(%rbp), %rcx
movq %rcx, 0x18(%r12,%rax)
movl %ebx, (%rsp)
leaq 0x1f6a5(%rip), %rdi     # 0x27a1e
movl %r15d, %esi
movl %r14d, %edx
movl %r13d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x4a56
movq %r13, %r14
movl %ebx, %r15d
cmpq $0x3, %r13
jne 0x82eb
movq -0x30(%rbp), %rcx
incq %rcx
movq -0x48(%rbp), %rdx
incq %rdx
movq -0x40(%rbp), %rsi
addq $0x4, %rsi
movq %rcx, -0x30(%rbp)
cmpq $0x4, %rcx
movq -0x80(%rbp), %r10
movq -0x78(%rbp), %r13
leaq 0x1ef37(%rip), %r14     # 0x27300
movq %rdx, %rax
movq %rsi, %rcx
jne 0x8230
leaq 0x1f67c(%rip), %rdi     # 0x27a58
xorl %eax, %eax
callq 0x4a56
movl $0x10, %ecx
movb $0x1, %al
movl %ecx, -0x40(%rbp)
movl %eax, -0x64(%rbp)
testb $0x1, %al
leaq 0x1f687(%rip), %rdi     # 0x27a80
leaq 0x1f66d(%rip), %rax     # 0x27a6d
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x4a56
movb $0x1, %al
xorl %r12d, %r12d
movq %rax, -0x30(%rbp)
movzbl (%r12,%r14), %ecx
movl -0x40(%rbp), %ebx
addl %ebx, %ecx
movq %rcx, %rax
movq %rcx, %rsi
movq %rcx, -0x48(%rbp)
shlq $0x5, %rax
movzbl 0x4(%r12,%r14), %r15d
addl %ebx, %r15d
movq %r15, %rcx
shlq $0x7, %rcx
leaq (%rcx,%r15,4), %rcx
addq %r13, %rcx
testb $0x1, -0x34(%rbp)
movq -0x60(%rbp), %r13
movq -0x80(%rbp), %rdx
movq %rdx, (%r13,%rax)
movl $0x0, %edx
cmovneq %rcx, %rdx
movq %rdx, 0x10(%r13,%rax)
movl %esi, (%rsp)
leaq 0x1f506(%rip), %rdi     # 0x27972
movl $0x1, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
movl %r15d, %r9d
xorl %eax, %eax
callq 0x4a56
leaq 0x1ee76(%rip), %rax     # 0x27300
movzbl (%rax,%r12,4), %r14d
movl %ebx, %edx
addl %ebx, %r14d
movq %r14, %rax
shlq $0x5, %rax
leaq 0x1ee5e(%rip), %rcx     # 0x27300
movzbl 0x1(%rcx,%r12,4), %ebx
addl %edx, %ebx
movq %rbx, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rbx,4), %rcx
addq -0x70(%rbp), %rcx
movq -0x88(%rbp), %rdx
testq %rdx, %rdx
movq %rdx, 0x8(%r13,%rax)
cmoveq %rdx, %rcx
movq %rcx, 0x18(%r13,%rax)
movl %r14d, (%rsp)
leaq 0x1f4d0(%rip), %rdi     # 0x279ac
movl %r12d, %esi
movl $0x1, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x4a56
movq %r15, %rax
shlq $0x5, %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%r13,%rax)
movq -0x48(%rbp), %rdx
movq %rdx, %rcx
shlq $0x7, %rcx
leaq (%rcx,%rdx,4), %rcx
movq %rdx, %r9
addq -0x50(%rbp), %rcx
movq %rcx, 0x10(%r13,%rax)
movl %r15d, (%rsp)
leaq 0x1f4ba(%rip), %rdi     # 0x279e4
xorl %esi, %esi
movl %r12d, %edx
movl $0x1, %ecx
movl %r12d, %r8d
leaq 0x1f4e0(%rip), %r15     # 0x27a1e
xorl %eax, %eax
callq 0x4a56
movq %rbx, %rax
shlq $0x5, %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%r13,%rax)
movq %r14, %rcx
shlq $0x7, %rcx
leaq (%rcx,%r14,4), %rcx
addq -0x50(%rbp), %rcx
movq %rcx, 0x18(%r13,%rax)
movl %ebx, (%rsp)
movq -0x78(%rbp), %r13
movq %r15, %rdi
movl %r12d, %esi
xorl %edx, %edx
movl %r12d, %ecx
movl $0x1, %r8d
movl %r14d, %r9d
leaq 0x1ed75(%rip), %r14     # 0x27300
xorl %eax, %eax
callq 0x4a56
movl $0x1, %r12d
testb $0x1, -0x30(%rbp)
movl $0x0, %eax
jne 0x8410
movl $0x14, %ecx
testb $0x1, -0x64(%rbp)
movl $0x0, %eax
jne 0x83ea
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop