#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 scalar_t__ uint8_t;

/* Variables and functions */
scalar_t__ abs(scalar_t__);
int pixel_sad_4x4(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 < 4; y++) {
    for (x = 0; x < 4; x++) {
      i_sum += abs(pix1[x] - pix2[x]);
    }
    pix1 += i_stride_pix1;
    pix2 += i_stride_pix2;
  }
  return i_sum;
}


x86 assembly (clang, -O0):
<pixel_sad_4x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
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   $0x4,-0x28(%rbp)
jge    11bf <pixel_sad_4x4+0xaf>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1187 <pixel_sad_4x4+0x77>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
sub    (%rax,%rcx,8),%rdi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <pixel_sad_4x4+0x35>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1134 <pixel_sad_4x4+0x24>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pixel_sad_4x4>:
movslq %esi,%rsi
movslq %ecx,%rax
movdqu (%rdi),%xmm8
movdqu 0x10(%rdi),%xmm9
movdqu (%rdx),%xmm0
psubq  %xmm0,%xmm8
movdqu 0x10(%rdx),%xmm0
psubq  %xmm0,%xmm9
lea    (%rdi,%rsi,8),%rcx
lea    (%rdx,%rax,8),%r8
movdqu (%rdi,%rsi,8),%xmm6
movdqu 0x10(%rdi,%rsi,8),%xmm7
movdqu (%rdx,%rax,8),%xmm0
psubq  %xmm0,%xmm6
movdqu 0x10(%rdx,%rax,8),%xmm0
psubq  %xmm0,%xmm7
lea    (%rcx,%rsi,8),%rdx
lea    (%r8,%rax,8),%rdi
movdqu (%rcx,%rsi,8),%xmm11
movdqu 0x10(%rcx,%rsi,8),%xmm0
movdqu (%r8,%rax,8),%xmm1
psubq  %xmm1,%xmm11
movdqu 0x10(%r8,%rax,8),%xmm1
psubq  %xmm1,%xmm0
movdqu (%rdx,%rsi,8),%xmm1
movdqu 0x10(%rdx,%rsi,8),%xmm2
movdqu (%rdi,%rax,8),%xmm3
psubq  %xmm3,%xmm1
movdqu 0x10(%rdi,%rax,8),%xmm3
psubq  %xmm3,%xmm2
movdqa %xmm2,%xmm10
psrad  $0x1f,%xmm10
pshufd $0xf5,%xmm10,%xmm3
paddq  %xmm2,%xmm3
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm13
paddq  %xmm1,%xmm13
shufps $0x88,%xmm3,%xmm13
movdqa %xmm7,%xmm12
psrad  $0x1f,%xmm12
pshufd $0xf5,%xmm12,%xmm5
paddq  %xmm7,%xmm5
movdqa %xmm6,%xmm7
psrad  $0x1f,%xmm7
pshufd $0xf5,%xmm7,%xmm14
paddq  %xmm6,%xmm14
shufps $0x88,%xmm5,%xmm14
movdqa %xmm0,%xmm5
psrad  $0x1f,%xmm5
pshufd $0xf5,%xmm5,%xmm6
paddq  %xmm0,%xmm6
movdqa %xmm11,%xmm0
psrad  $0x1f,%xmm0
pshufd $0xf5,%xmm0,%xmm1
paddq  %xmm11,%xmm1
shufps $0x88,%xmm6,%xmm1
movdqa %xmm9,%xmm11
psrad  $0x1f,%xmm11
pshufd $0xf5,%xmm11,%xmm4
paddq  %xmm9,%xmm4
movdqa %xmm8,%xmm6
psrad  $0x1f,%xmm6
pshufd $0xf5,%xmm6,%xmm3
paddq  %xmm8,%xmm3
shufps $0x88,%xmm4,%xmm3
shufps $0xdd,%xmm5,%xmm0
xorps  %xmm1,%xmm0
shufps $0xdd,%xmm12,%xmm7
xorps  %xmm14,%xmm7
shufps $0xdd,%xmm10,%xmm2
xorps  %xmm13,%xmm2
paddd  %xmm7,%xmm2
shufps $0xdd,%xmm11,%xmm6
xorps  %xmm3,%xmm6
paddd  %xmm0,%xmm6
paddd  %xmm2,%xmm6
pshufd $0xee,%xmm6,%xmm0
paddd  %xmm6,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
ret

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

LLVM IR (-O2):
define i32 @pixel_sad_4x4(i64* nocapture %0, i32 %1, i64* nocapture %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = sext i32 %3 to i64
%7 = bitcast i64* %0 to <4 x i64>*
%8 = load <4 x i64>, <4 x i64>* %7
%9 = bitcast i64* %2 to <4 x i64>*
%10 = load <4 x i64>, <4 x i64>* %9
%11 = getelementptr inbounds i64, i64* %0, i64 %5
%12 = getelementptr inbounds i64, i64* %2, i64 %6
%13 = bitcast i64* %11 to <4 x i64>*
%14 = load <4 x i64>, <4 x i64>* %13
%15 = bitcast i64* %12 to <4 x i64>*
%16 = load <4 x i64>, <4 x i64>* %15
%17 = getelementptr inbounds i64, i64* %11, i64 %5
%18 = getelementptr inbounds i64, i64* %12, i64 %6
%19 = bitcast i64* %17 to <4 x i64>*
%20 = load <4 x i64>, <4 x i64>* %19
%21 = bitcast i64* %18 to <4 x i64>*
%22 = load <4 x i64>, <4 x i64>* %21
%23 = getelementptr inbounds i64, i64* %17, i64 %5
%24 = getelementptr inbounds i64, i64* %18, i64 %6
%25 = bitcast i64* %23 to <4 x i64>*
%26 = load <4 x i64>, <4 x i64>* %25
%27 = bitcast i64* %24 to <4 x i64>*
%28 = load <4 x i64>, <4 x i64>* %27
%29 = shufflevector <4 x i64> %8, <4 x i64> %14, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%30 = shufflevector <4 x i64> %20, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%31 = shufflevector <16 x i64> %29, <16 x i64> %30, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 18, i32 19, i32 undef, i32 undef, i32 undef, i32 undef>
%32 = shufflevector <4 x i64> %26, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%33 = shufflevector <16 x i64> %31, <16 x i64> %32, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 16, i32 17, i32 18, i32 19>
%34 = shufflevector <4 x i64> %10, <4 x i64> %16, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%35 = shufflevector <4 x i64> %22, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%36 = shufflevector <16 x i64> %34, <16 x i64> %35, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 16, i32 17, i32 18, i32 19, i32 undef, i32 undef, i32 undef, i32 undef>
%37 = shufflevector <4 x i64> %28, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
%38 = shufflevector <16 x i64> %36, <16 x i64> %37, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 16, i32 17, i32 18, i32 19>
%39 = sub nsw <16 x i64> %33, %38
%40 = call <16 x i64> @llvm.abs.v16i64(<16 x i64> %39, i1 true)
%41 = trunc <16 x i64> %40 to <16 x i32>
%42 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %41)
ret i32 %42
}