// File: /workspace/github_cpp_makefile_star2_O1/lukasz-wiecaszek[P]h264iframedecoder/picture.cpp
// Function: ymn::h264::picture::calculate_neighbours_part1()
void picture::calculate_neighbours_part1()
{
    int y = m_context_variables.mb_y;
    int n = m_context_variables.mb_pos;
    int mb_width = m_decoder.m_dimensions.mb_width;
    mb& mb = m_mbs[n];

    if (m_context_variables.mb_aff_frame) {
        int shift = y & 1 ? 3 * mb_width : 2 * mb_width;

        mb.A = (n % mb_width) ? get_mb(n - 1 - (y & 1) * mb_width) : nullptr;
        mb.B = get_mb(n - shift);
        mb.C = ((n + 1) % mb_width) ? get_mb(n - shift + 1) : nullptr;
        mb.D = (n % mb_width) ? get_mb(n - shift - 1) : nullptr;
    }
    else {
        if (m_picture_structure == picture_structure_e::frame) {
            mb.A = (n % mb_width) ? get_mb(n - 1) : nullptr;
            mb.B = get_mb(n - mb_width);
            mb.C = ((n + 1) % mb_width) ? get_mb(n - mb_width + 1) : nullptr;
            mb.D = (n % mb_width) ? get_mb(n - mb_width - 1) : nullptr;
        }
        else {
            int shift = 2 * mb_width;

            mb.A = (n % mb_width) ? get_mb(n - 1) : nullptr;
            mb.B = get_mb(n - shift);
            mb.C = ((n + 1) % mb_width) ? get_mb(n - shift + 1) : nullptr;
            mb.D = (n % mb_width) ? get_mb(n - shift - 1) : nullptr;
        }
    }

    /* To calculate left and top references it is necessary to know
    whether the current macroblock is a frame or field macroblock.
    This is why left and top references will be calculated later (in part2)
    when current macroblock frame/field status is already known. */
    mb.left = nullptr;
    mb.left_pair[0] = nullptr;
    mb.left_pair[1] = nullptr;
    mb.top = nullptr;
}

// Assembly:
pushq %rbx
movslq 0x24(%rdi), %rcx
movq 0x8(%rdi), %rax
movl 0x88340(%rax), %r9d
movq 0xdb8(%rdi), %r10
imulq $0xb0, %rcx, %rbx
leaq (%r10,%rbx), %r8
cmpb $0x1, 0x18(%rdi)
jne 0x166b3
movl 0x20(%rdi), %ebx
leal (%r9,%r9), %eax
andl $0x1, %ebx
leal (%r9,%r9,2), %r11d
cmovel %eax, %r11d
movl %ecx, %eax
cltd
idivl %r9d
movl %edx, %esi
testl %edx, %edx
je 0x166ef
imull %r9d, %ebx
notl %ebx
addl %ecx, %ebx
movslq %ebx, %rax
imulq $0xb0, %rax, %rdx
addq %rdx, %r10
xorl %edx, %edx
cmpl %eax, %ecx
cmovlq %rdx, %r10
testl %eax, %eax
cmovsq %rdx, %r10
jmp 0x166f2
cmpl $0x0, 0x10(%rdi)
je 0x1675b
movl %ecx, %eax
cltd
idivl %r9d
movl %edx, %esi
xorl %r11d, %r11d
testl %ecx, %ecx
leaq -0xb0(%r10,%rbx), %rax
cmovleq %r11, %rax
testl %edx, %edx
cmoveq %r11, %rax
leal (%r9,%r9), %edx
movq %rax, 0x18(%r8)
movl %ecx, %r10d
subl %edx, %r10d
jmp 0x16784
xorl %r10d, %r10d
movq %r10, 0x18(%r8)
movl %ecx, %r10d
subl %r11d, %r10d
movslq %r10d, %rax
imulq $0xb0, %rax, %r11
movq 0xdb8(%rdi), %rdx
addq %r11, %rdx
xorl %ebx, %ebx
cmpl %eax, 0x24(%rdi)
cmovlq %rbx, %rdx
testl %eax, %eax
cmovsq %rbx, %rdx
movq %rdx, 0x20(%r8)
incl %ecx
movl %ecx, %eax
cltd
idivl %r9d
testl %edx, %edx
je 0x16752
addq 0xdb8(%rdi), %r11
addq $0xb0, %r11
xorl %eax, %eax
cmpl %r10d, 0x24(%rdi)
cmovleq %rax, %r11
cmpl $-0x1, %r10d
cmovlq %rax, %r11
movq %r11, %rbx
movq %rbx, 0x28(%r8)
jmp 0x167dc
movl %ecx, %eax
cltd
idivl %r9d
movl %edx, %esi
xorl %r11d, %r11d
testl %ecx, %ecx
leaq -0xb0(%r10,%rbx), %rax
cmovleq %r11, %rax
testl %edx, %edx
cmoveq %r11, %rax
movq %rax, 0x18(%r8)
movl %ecx, %r10d
subl %r9d, %r10d
movslq %r10d, %rax
imulq $0xb0, %rax, %rbx
movq 0xdb8(%rdi), %rdx
addq %rbx, %rdx
cmpl %eax, 0x24(%rdi)
cmovlq %r11, %rdx
testl %eax, %eax
cmovsq %r11, %rdx
movq %rdx, 0x20(%r8)
incl %ecx
movl %ecx, %eax
cltd
idivl %r9d
testl %edx, %edx
je 0x167d8
addq 0xdb8(%rdi), %rbx
addq $0xb0, %rbx
xorl %eax, %eax
cmpl %r10d, 0x24(%rdi)
cmovleq %rax, %rbx
cmpl $-0x1, %r10d
cmovlq %rax, %rbx
movq %rbx, %r11
movq %r11, 0x28(%r8)
testl %esi, %esi
je 0x16807
leal -0x1(%r10), %eax
movslq %eax, %rcx
imulq $0xb0, %rcx, %rax
addq 0xdb8(%rdi), %rax
xorl %edx, %edx
cmpl %ecx, 0x24(%rdi)
cmovlq %rdx, %rax
testl %r10d, %r10d
cmovleq %rdx, %rax
jmp 0x16809
xorl %eax, %eax
movq %rax, 0x30(%r8)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r8)
movups %xmm0, 0x48(%r8)
popq %rbx
retq