// File: /workspace/github_cpp_makefile_star2_O3/markondej[P]phase_correl/phase_correl.c
// Function: main
int main()
{
    unsigned char image1[256 * 128];
    unsigned char image2[256 * 128];

    unsigned i, j;
    int deltax, deltay;

    // Generate pair of images
    for (j = 0; j < 128; j++)
        for (i = 0; i < 256; i++) {
            unsigned offset = i + j * 256;
            if ((i >= 16) && (i < 76) && (j >= 32) && (j < 92))
                image1[offset] = 128;
            else
                image1[offset] = 0;

            if ((i >= 8) && (i < 68) && (j >= 40) && (j < 100))
                image2[offset] = 16;
            else
                image2[offset] = 255;
        }

    computeShift(image1, image2, 256, 128, &deltax, &deltay);

    printf("Calculated shift: [%d, %d]\n", deltax, deltay);

    return EXIT_SUCCESS;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x10048, %rsp          # imm = 0x10048
leaq 0x40(%rsp), %rax
leaq 0x8040(%rsp), %rcx
xorl %edx, %edx
movdqa 0x51f(%rip), %xmm7      # 0x2050
movdqa 0x576(%rip), %xmm10     # 0x20b0
movdqa 0x57d(%rip), %xmm8      # 0x20c0
movdqa 0x585(%rip), %xmm6      # 0x20d0
movl $0x100, %esi            # imm = 0x100
movdqa 0x587(%rip), %xmm15     # 0x20e0
movd %edx, %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
paddd 0x4d6(%rip), %xmm0      # 0x2040
pxor %xmm7, %xmm0
movdqa 0x4ea(%rip), %xmm2      # 0x2060
pcmpgtd %xmm0, %xmm2
pshufd $0x50, %xmm2, %xmm0     # xmm0 = xmm2[0,0,1,1]
punpcklbw %xmm2, %xmm2    # xmm2 = xmm2[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7]
pshuflw $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0,4,5,6,7]
pshufd $0x0, %xmm2, %xmm1      # xmm1 = xmm2[0,0,0,0]
movdqa %xmm1, 0x20(%rsp)
punpckhbw %xmm0, %xmm0    # xmm0 = xmm0[8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15]
pshuflw $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0,4,5,6,7]
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa %xmm0, 0x10(%rsp)
xorl %edi, %edi
movdqa 0x4ef(%rip), %xmm0      # 0x20a0
movdqa %xmm0, %xmm13
movdqa 0x4d2(%rip), %xmm2      # 0x2090
movdqa %xmm2, %xmm14
movdqa 0x4b4(%rip), %xmm11     # 0x2080
movdqa %xmm11, %xmm4
movdqa 0x496(%rip), %xmm12     # 0x2070
movdqa %xmm12, %xmm9
movdqa %xmm13, 0x30(%rsp)
movdqa %xmm9, %xmm3
paddd %xmm10, %xmm3
movdqa %xmm14, %xmm5
paddd %xmm10, %xmm5
movdqa %xmm6, %xmm1
movdqa %xmm13, %xmm6
paddd %xmm10, %xmm6
pxor %xmm7, %xmm6
movdqa %xmm8, %xmm13
pcmpgtd %xmm6, %xmm8
pxor %xmm7, %xmm5
movdqa %xmm13, %xmm6
pcmpgtd %xmm5, %xmm6
movdqa %xmm4, %xmm5
paddd %xmm10, %xmm5
packssdw %xmm6, %xmm8
pxor %xmm7, %xmm5
movdqa %xmm13, %xmm6
pcmpgtd %xmm5, %xmm6
pxor %xmm7, %xmm3
movdqa %xmm13, %xmm5
pcmpgtd %xmm3, %xmm5
packssdw %xmm5, %xmm6
packsswb %xmm6, %xmm8
pand 0x20(%rsp), %xmm8
psllw $0x7, %xmm8
pand %xmm1, %xmm8
movdqa %xmm8, (%rcx,%rdi)
movdqa %xmm12, %xmm3
paddd %xmm15, %xmm3
movdqa %xmm2, %xmm5
paddd %xmm15, %xmm5
movdqa %xmm0, %xmm6
paddd %xmm15, %xmm6
pxor %xmm7, %xmm6
movdqa %xmm13, %xmm8
pcmpgtd %xmm6, %xmm8
pxor %xmm7, %xmm5
movdqa %xmm13, %xmm6
pcmpgtd %xmm5, %xmm6
movdqa %xmm11, %xmm5
paddd %xmm15, %xmm5
packssdw %xmm6, %xmm8
pxor %xmm7, %xmm5
movdqa %xmm13, %xmm6
pcmpgtd %xmm5, %xmm6
pxor %xmm7, %xmm3
movdqa %xmm13, %xmm5
pcmpgtd %xmm3, %xmm5
packssdw %xmm5, %xmm6
packsswb %xmm6, %xmm8
movdqa %xmm1, %xmm6
pand 0x10(%rsp), %xmm8
psllw $0x7, %xmm8
pand %xmm1, %xmm8
pxor %xmm3, %xmm3
pcmpgtb %xmm8, %xmm3
movdqa %xmm13, %xmm8
movdqa 0x3ee(%rip), %xmm13     # 0x20f0
pcmpeqd %xmm1, %xmm1
movdqa %xmm3, %xmm5
pxor %xmm1, %xmm5
pand %xmm13, %xmm3
movdqa 0x30(%rsp), %xmm13
por %xmm5, %xmm3
movdqa %xmm3, (%rax,%rdi)
movdqa 0x3d5(%rip), %xmm1      # 0x2100
addq $0x10, %rdi
paddd %xmm1, %xmm13
paddd %xmm1, %xmm14
paddd %xmm1, %xmm4
paddd %xmm1, %xmm9
paddd %xmm1, %xmm0
paddd %xmm1, %xmm2
paddd %xmm1, %xmm11
paddd %xmm1, %xmm12
cmpq $0x100, %rdi            # imm = 0x100
jne 0x1bdf
incq %rdx
addq %rsi, %rax
addq %rsi, %rcx
cmpq $0x80, %rdx
jne 0x1b59
leaq 0x8040(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0xc(%rsp), %rbx
leaq 0x8(%rsp), %r14
movl $0x100, %edx            # imm = 0x100
movl $0x80, %ecx
movq %rbx, %r8
movq %r14, %r9
callq 0x1880
movl (%rbx), %esi
movl (%r14), %edx
leaq 0x369(%rip), %rdi       # 0x2118
xorl %eax, %eax
callq 0x1050
xorl %eax, %eax
addq $0x10048, %rsp          # imm = 0x10048
popq %rbx
popq %r14
retq