#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;

/* Variables and functions */
int pixel_ssd_16x16(uint8_t *pix1, int i_stride_pix1, uint8_t *pix2,
                    int i_stride_pix2) {
  int i_sum = 0;
  int x, y;
  for (y = 0; y < 16; y++) {
    for (x = 0; x < 16; x++) {
      int d = pix1[x] - pix2[x];
      i_sum += d * d;
    }
    pix1 += i_stride_pix1;
    pix2 += i_stride_pix2;
  }
  return i_sum;
}


x86 assembly (clang, -O0):
<pixel_ssd_16x16>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    11a7 <pixel_ssd_16x16+0xa7>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    116f <pixel_ssd_16x16+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <pixel_ssd_16x16+0x31>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1120 <pixel_ssd_16x16+0x20>
mov    -0x20(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pixel_ssd_16x16>:
movslq %esi,%r10
movslq %ecx,%r11
lea    0x0(,%r10,8),%r8
lea    0x0(,%r11,8),%r9
xor    %eax,%eax
mov    $0x10,%esi
nopl   (%rax)
movdqu (%rdi),%xmm2
movdqu 0x10(%rdi),%xmm0
movdqu 0x20(%rdi),%xmm3
movdqu 0x30(%rdi),%xmm1
movdqu (%rdx),%xmm4
psubd  %xmm4,%xmm2
movdqu 0x10(%rdx),%xmm4
psubd  %xmm4,%xmm0
movdqu 0x20(%rdx),%xmm4
psubd  %xmm4,%xmm3
movdqu 0x30(%rdx),%xmm4
psubd  %xmm4,%xmm1
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm3
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm1,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm0
paddd  %xmm1,%xmm0
paddd  %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ecx
add    %eax,%ecx
movdqu (%rdi,%r10,4),%xmm2
movdqu 0x10(%rdi,%r10,4),%xmm0
movdqu 0x20(%rdi,%r10,4),%xmm3
movdqu 0x30(%rdi,%r10,4),%xmm1
movdqu (%rdx,%r11,4),%xmm4
psubd  %xmm4,%xmm2
movdqu 0x10(%rdx,%r11,4),%xmm4
psubd  %xmm4,%xmm0
movdqu 0x20(%rdx,%r11,4),%xmm4
psubd  %xmm4,%xmm3
movdqu 0x30(%rdx,%r11,4),%xmm4
psubd  %xmm4,%xmm1
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm3
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm4,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm1,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm1
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm0,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm3,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm0
paddd  %xmm1,%xmm0
paddd  %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
add    %ecx,%eax
add    %r8,%rdi
add    %r9,%rdx
add    $0xfffffffe,%esi
jne    1120 <pixel_ssd_16x16+0x20>
ret

LLVM IR (-O0):
define i32 @pixel_ssd_16x16(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %11
br label %13
13: ; preds = %49, %4
%14 = load i32, i32* %11
%15 = icmp slt i32 %14, 16
br i1 %15, label %16, label %52
16: ; preds = %13
store i32 0, i32* %10
br label %17
17: ; preds = %37, %16
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 16
br i1 %19, label %20, label %40
20: ; preds = %17
%21 = load i32*, i32** %5
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32*, i32** %7
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = sub nsw i32 %25, %30
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = load i32, i32* %12
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %9
%36 = add nsw i32 %35, %34
store i32 %36, i32* %9
br label %37
37: ; preds = %20
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %17
40: ; preds = %17
%41 = load i32, i32* %6
%42 = load i32*, i32** %5
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i32, i32* %42, i64 %43
store i32* %44, i32** %5
%45 = load i32, i32* %8
%46 = load i32*, i32** %7
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i32, i32* %46, i64 %47
store i32* %48, i32** %7
br label %49
49: ; preds = %40
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %13
52: ; preds = %13
%53 = load i32, i32* %9
ret i32 %53
}

LLVM IR (-O2):
define i32 @pixel_ssd_16x16(i32* nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = sext i32 %3 to i64
br label %7
7: ; preds = %7, %4
%8 = phi i32* [ %0, %4 ], [ %30, %7 ]
%9 = phi i32 [ 0, %4 ], [ %32, %7 ]
%10 = phi i32 [ 0, %4 ], [ %29, %7 ]
%11 = phi i32* [ %2, %4 ], [ %31, %7 ]
%12 = bitcast i32* %8 to <16 x i32>*
%13 = load <16 x i32>, <16 x i32>* %12
%14 = bitcast i32* %11 to <16 x i32>*
%15 = load <16 x i32>, <16 x i32>* %14
%16 = sub nsw <16 x i32> %13, %15
%17 = mul nsw <16 x i32> %16, %16
%18 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %17)
%19 = add nsw i32 %18, %10
%20 = getelementptr inbounds i32, i32* %8, i64 %5
%21 = getelementptr inbounds i32, i32* %11, i64 %6
%22 = bitcast i32* %20 to <16 x i32>*
%23 = load <16 x i32>, <16 x i32>* %22
%24 = bitcast i32* %21 to <16 x i32>*
%25 = load <16 x i32>, <16 x i32>* %24
%26 = sub nsw <16 x i32> %23, %25
%27 = mul nsw <16 x i32> %26, %26
%28 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %27)
%29 = add nsw i32 %28, %19
%30 = getelementptr inbounds i32, i32* %20, i64 %5
%31 = getelementptr inbounds i32, i32* %21, i64 %6
%32 = add nuw nsw i32 %9, 2
%33 = icmp eq i32 %32, 16
br i1 %33, label %34, label %7
34: ; preds = %7
ret i32 %29
}