// File: /workspace/github_c_makefile_star2_O2/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 0x14578(%rip), %rdi     # 0x1b1b4
leaq 0x14f55(%rip), %rsi     # 0x1bb98
leaq 0x15073(%rip), %rdx     # 0x1bcbd
xorl %eax, %eax
callq 0x39ba
xorl %r10d, %r10d
movq %rbx, 0x10(%r14)
movl 0x8(%r14), %eax
leaq -0xf88(%r14), %rcx
testb $0x1, %al
cmoveq %r10, %rcx
movq %rbx, -0x30(%rbp)
movq %rcx, -0x80(%rbp)
movq %rcx, (%rbx)
movl %eax, -0x34(%rbp)
testb $0x2, %al
je 0x6c96
movq 0x8ed8(%r15), %rax
movslq 0x43c(%rax), %rax
negq %rax
imulq $0xf88, %rax, %r10      # imm = 0xF88
addq %r14, %r10
movq -0x30(%rbp), %r8
movq %r10, 0x8(%r8)
leaq 0xf88(%r10), %rcx
xorl %eax, %eax
testb $0x4, -0x34(%rbp)
cmoveq %rax, %rcx
movq %rcx, 0x10(%r8)
movq 0x10ee48(%r15), %rsi
movl (%r14), %edx
movl 0x4(%r14), %ecx
movl 0xc(%rsi), %edi
imull %ecx, %edi
addl %edx, %edi
shll $0x4, %edi
movslq %edi, %rdi
addq 0x20(%rsi), %rdi
movq %rdi, 0x18(%r8)
movq 0x10ee48(%r15), %rsi
movl 0x10(%rsi), %edi
imull %ecx, %edi
addl %edx, %edi
shll $0x3, %edi
movslq %edi, %rdi
addq 0x28(%rsi), %rdi
movq %rdi, 0x20(%r8)
movq 0x10ee48(%r15), %rsi
imull 0x14(%rsi), %ecx
addl %edx, %ecx
shll $0x3, %ecx
movslq %ecx, %rcx
addq 0x30(%rsi), %rcx
movq %rcx, 0x28(%r8)
movq 0x10ee48(%r15), %rcx
movl 0xc(%rcx), %edx
movl %edx, 0x30(%r8)
movl 0x10(%rcx), %edx
movl %edx, 0x34(%r8)
movl 0x14(%rcx), %ecx
movl %ecx, 0x38(%r8)
movq 0x10efe0(%r15), %rsi
movl (%r14), %edx
movl 0x4(%r14), %ecx
movl 0x24(%rsi), %edi
imull %ecx, %edi
addl %edx, %edi
shll $0x4, %edi
movslq %edi, %rdi
addq 0x48(%rsi), %rdi
movq %rdi, 0x40(%r8)
movq 0x10efe0(%r15), %rsi
movl 0x28(%rsi), %edi
imull %ecx, %edi
addl %edx, %edi
shll $0x3, %edi
movslq %edi, %rdi
addq 0x50(%rsi), %rdi
movq %rdi, 0x48(%r8)
movq 0x10efe0(%r15), %rsi
imull 0x2c(%rsi), %ecx
addl %edx, %ecx
shll $0x3, %ecx
movslq %ecx, %rcx
addq 0x58(%rsi), %rcx
movq %rcx, 0x50(%r8)
movq 0x10efe0(%r15), %rcx
movl 0x24(%rcx), %edx
movl %edx, 0x58(%r8)
movl 0x28(%rcx), %edx
movl %edx, 0x5c(%r8)
movl 0x2c(%rcx), %ecx
movl %ecx, 0x60(%r8)
xorl %ecx, %ecx
movq -0x30(%rbp), %r9
movslq 0x10f078(%r15), %rdx
cmpq %rdx, %rcx
jge 0x6e58
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(%r9,%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(%r9,%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(%r9,%rax,2)
movq 0x10f080(%r15,%rcx,8), %rdx
movl 0x24(%rdx), %esi
movl %esi, 0x1e8(%r9,%rax)
movl 0x28(%rdx), %esi
movl %esi, 0x1ec(%r9,%rax)
movl 0x2c(%rdx), %edx
movl %edx, 0x1f0(%r9,%rax)
incq %rcx
addq $0xc, %rax
jmp 0x6da9
xorl %eax, %eax
xorl %ecx, %ecx
movq -0x30(%rbp), %r9
movslq 0x10f100(%r15), %rdx
cmpq %rdx, %rcx
jge 0x6f18
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(%r9,%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(%r9,%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(%r9,%rax,2)
movq 0x10f108(%r15,%rcx,8), %rdx
movl 0x24(%rdx), %esi
movl %esi, 0x428(%r9,%rax)
movl 0x28(%rdx), %esi
movl %esi, 0x42c(%r9,%rax)
movl 0x2c(%rdx), %edx
movl %edx, 0x430(%r9,%rax)
incq %rcx
addq $0xc, %rax
jmp 0x6e60
addq $0x4e8, -0x30(%rbp)     # imm = 0x4E8
leaq -0xc64(%r14), %rax
movq %rax, -0x78(%rbp)
movl $0x324, %eax            # imm = 0x324
movq %r10, -0x88(%rbp)
leaq (%r10,%rax), %rcx
movq %rcx, -0x70(%rbp)
movq %r14, -0x68(%rbp)
addq %r14, %rax
movq %rax, -0x60(%rbp)
leaq 0x143b3(%rip), %rax     # 0x1b304
movq %rax, -0x48(%rbp)
leaq 0x143a5(%rip), %rax     # 0x1b301
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
movq -0x30(%rbp), %r13
cmpq $0x4, %r12
je 0x70e5
leaq 0x14388(%rip), %r14     # 0x1b300
movzbl (%r12,%r14), %eax
movl %eax, %ecx
shll $0x5, %ecx
movzbl 0xc(%r12,%r14), %r9d
imulq $0x84, %r9, %rdx
addq -0x78(%rbp), %rdx
testb $0x1, -0x34(%rbp)
movq -0x30(%rbp), %rbx
movq -0x80(%rbp), %rsi
movq %rsi, (%rbx,%rcx)
movl $0x0, %esi
cmoveq %rsi, %rdx
movq %rdx, 0x10(%rbx,%rcx)
movl %eax, (%rsp)
leaq 0x14d1f(%rip), %rdi     # 0x1bcda
pushq $0x3
popq %r15
movl %r15d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x39ba
movzbl (%r14,%r12,4), %eax
movl %eax, %ecx
shll $0x5, %ecx
movzbl 0x3(%r14,%r12,4), %r9d
imulq $0x84, %r9, %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 0x14d06(%rip), %rdi     # 0x1bd14
movl %r12d, %esi
movl %r15d, %edx
movq %r12, -0x50(%rbp)
movl %r12d, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x39ba
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0x70d0
leaq 0x1(%rbx), %rcx
movq %rcx, -0x58(%rbp)
movq -0x48(%rbp), %rdx
movzbl (%rdx,%rbx,4), %r15d
movl %r15d, %eax
shll $0x5, %eax
movq -0x68(%rbp), %r12
movq %r12, (%r13,%rax)
movzbl -0x4(%rdx,%rbx,4), %r9d
imulq $0x84, %r9, %rdx
addq -0x60(%rbp), %rdx
movq %rdx, 0x10(%r13,%rax)
movl %r15d, (%rsp)
leaq 0x14cda(%rip), %rdi     # 0x1bd4c
movl %ebx, %esi
movq -0x50(%rbp), %r14
movl %r14d, %edx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x39ba
movq -0x40(%rbp), %rcx
movzbl (%rcx,%rbx), %eax
shll $0x5, %eax
movq %r12, 0x8(%r13,%rax)
movzbl -0x1(%rcx,%rbx), %r9d
imulq $0x84, %r9, %rcx
addq -0x60(%rbp), %rcx
movq %rcx, 0x18(%r13,%rax)
movl %r15d, (%rsp)
leaq 0x14cd0(%rip), %rdi     # 0x1bd86
movl %r14d, %esi
movl %ebx, %edx
movq -0x58(%rbp), %rbx
movl %ebx, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x39ba
jmp 0x7027
movq -0x50(%rbp), %r12
incq %r12
incq -0x48(%rbp)
addq $0x4, -0x40(%rbp)
jmp 0x6f67
leaq 0x14cd4(%rip), %rdi     # 0x1bdc0
xorl %eax, %eax
callq 0x39ba
xorl %ebx, %ebx
movq -0x30(%rbp), %r13
leaq 0x14cd5(%rip), %rdi     # 0x1bdd5
testl %ebx, %ebx
je 0x7114
cmpl $0x2, %ebx
je 0x729e
leaq 0x14cd4(%rip), %rdi     # 0x1bde8
xorl %eax, %eax
callq 0x39ba
movq %rbx, -0x40(%rbp)
leal 0x10(,%rbx,4), %eax
movl %eax, -0x48(%rbp)
xorl %r15d, %r15d
cmpq $0x2, %r15
je 0x7293
leaq 0x141c3(%rip), %rbx     # 0x1b300
movzbl (%r15,%rbx), %ecx
movl -0x48(%rbp), %r14d
addl %r14d, %ecx
movq %rcx, %rax
movq %rcx, %rsi
movq %rcx, -0x58(%rbp)
shlq $0x5, %rax
movzbl 0x4(%r15,%rbx), %edx
addl %r14d, %edx
imulq $0x84, %rdx, %rcx
movq %rdx, %r9
movq %rdx, -0x50(%rbp)
addq -0x78(%rbp), %rcx
testb $0x1, -0x34(%rbp)
movq -0x80(%rbp), %rdx
movq %rdx, (%r13,%rax)
movl $0x0, %edx
cmovneq %rcx, %rdx
movq %rdx, 0x10(%r13,%rax)
movl %esi, (%rsp)
leaq 0x14b43(%rip), %rdi     # 0x1bcda
pushq $0x1
popq %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x39ba
movzbl (%rbx,%r15,4), %r12d
addl %r14d, %r12d
movq %r12, %rax
shlq $0x5, %rax
movzbl 0x1(%rbx,%r15,4), %ebx
addl %r14d, %ebx
imulq $0x84, %rbx, %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 %r12d, (%rsp)
leaq 0x14b25(%rip), %rdi     # 0x1bd14
movl %r15d, %esi
pushq $0x1
popq %rdx
movl %r15d, %ecx
xorl %r8d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x39ba
movq -0x50(%rbp), %rdx
movq %rdx, %rax
shlq $0x5, %rax
movq -0x68(%rbp), %rcx
movq %rcx, (%r13,%rax)
movq -0x58(%rbp), %r9
imulq $0x84, %r9, %rcx
movq -0x60(%rbp), %r14
addq %r14, %rcx
movq %rcx, 0x10(%r13,%rax)
movl %edx, (%rsp)
leaq 0x14b12(%rip), %rdi     # 0x1bd4c
xorl %esi, %esi
movl %r15d, %edx
pushq $0x1
popq %rcx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x39ba
movq %rbx, %rax
shlq $0x5, %rax
movq -0x68(%rbp), %rcx
movq %rcx, 0x8(%r13,%rax)
imulq $0x84, %r12, %rcx
addq %r14, %rcx
movq %rcx, 0x18(%r13,%rax)
movl %ebx, (%rsp)
leaq 0x14b11(%rip), %rdi     # 0x1bd86
movl %r15d, %esi
xorl %edx, %edx
movl %r15d, %ecx
pushq $0x1
popq %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x39ba
incq %r15
jmp 0x712c
movq -0x40(%rbp), %rbx
incl %ebx
jmp 0x70f9
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)