#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_4x8(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 < 8; 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_4x8>:
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   $0x8,-0x28(%rbp)
jge    11bf <pixel_sad_4x8+0xaf>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1187 <pixel_sad_4x8+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_4x8+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_4x8+0x24>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pixel_sad_4x8>:
movslq %esi,%rsi
movslq %ecx,%rax
movdqu (%rdi),%xmm0
movdqu 0x10(%rdi),%xmm1
movdqu (%rdx),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%rdx),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%r9d
lea    (%rdi,%rsi,8),%rcx
lea    (%rdx,%rax,8),%r8
movdqu (%rdi,%rsi,8),%xmm0
movdqu 0x10(%rdi,%rsi,8),%xmm1
movdqu (%rdx,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%rdx,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
add    %r9d,%edx
lea    (%rcx,%rsi,8),%rdi
lea    (%r8,%rax,8),%r9
movdqu (%rcx,%rsi,8),%xmm0
movdqu 0x10(%rcx,%rsi,8),%xmm1
movdqu (%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ecx
add    %edx,%ecx
lea    (%rdi,%rsi,8),%r10
lea    (%r9,%rax,8),%r8
movdqu (%rdi,%rsi,8),%xmm0
movdqu 0x10(%rdi,%rsi,8),%xmm1
movdqu (%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
add    %ecx,%edx
lea    (%r10,%rsi,8),%rdi
lea    (%r8,%rax,8),%r9
movdqu (%r10,%rsi,8),%xmm0
movdqu 0x10(%r10,%rsi,8),%xmm1
movdqu (%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ecx
add    %edx,%ecx
lea    (%rdi,%rsi,8),%rdx
lea    (%r9,%rax,8),%r8
movdqu (%rdi,%rsi,8),%xmm0
movdqu 0x10(%rdi,%rsi,8),%xmm1
movdqu (%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edi
add    %ecx,%edi
lea    (%rdx,%rsi,8),%rcx
lea    (%r8,%rax,8),%r9
movdqu (%rdx,%rsi,8),%xmm0
movdqu 0x10(%rdx,%rsi,8),%xmm1
movdqu (%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r8,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
add    %edi,%edx
movdqu (%rcx,%rsi,8),%xmm0
movdqu 0x10(%rcx,%rsi,8),%xmm1
movdqu (%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm0
movdqu 0x10(%r9,%rax,8),%xmm2
psubq  %xmm2,%xmm1
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm1
pxor   %xmm2,%xmm1
movdqa %xmm0,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm2
paddq  %xmm2,%xmm0
pxor   %xmm2,%xmm0
shufps $0x88,%xmm1,%xmm0
pshufd $0x88,%xmm1,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
define i32 @pixel_sad_4x8(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, 8
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_4x8(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 = sub nsw <4 x i64> %8, %10
%12 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %11, i1 true)
%13 = trunc <4 x i64> %12 to <4 x i32>
%14 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %13)
%15 = getelementptr inbounds i64, i64* %0, i64 %5
%16 = getelementptr inbounds i64, i64* %2, i64 %6
%17 = bitcast i64* %15 to <4 x i64>*
%18 = load <4 x i64>, <4 x i64>* %17
%19 = bitcast i64* %16 to <4 x i64>*
%20 = load <4 x i64>, <4 x i64>* %19
%21 = sub nsw <4 x i64> %18, %20
%22 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %21, i1 true)
%23 = trunc <4 x i64> %22 to <4 x i32>
%24 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %23)
%25 = add i32 %24, %14
%26 = getelementptr inbounds i64, i64* %15, i64 %5
%27 = getelementptr inbounds i64, i64* %16, i64 %6
%28 = bitcast i64* %26 to <4 x i64>*
%29 = load <4 x i64>, <4 x i64>* %28
%30 = bitcast i64* %27 to <4 x i64>*
%31 = load <4 x i64>, <4 x i64>* %30
%32 = sub nsw <4 x i64> %29, %31
%33 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %32, i1 true)
%34 = trunc <4 x i64> %33 to <4 x i32>
%35 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %34)
%36 = add i32 %35, %25
%37 = getelementptr inbounds i64, i64* %26, i64 %5
%38 = getelementptr inbounds i64, i64* %27, i64 %6
%39 = bitcast i64* %37 to <4 x i64>*
%40 = load <4 x i64>, <4 x i64>* %39
%41 = bitcast i64* %38 to <4 x i64>*
%42 = load <4 x i64>, <4 x i64>* %41
%43 = sub nsw <4 x i64> %40, %42
%44 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %43, i1 true)
%45 = trunc <4 x i64> %44 to <4 x i32>
%46 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %45)
%47 = add i32 %46, %36
%48 = getelementptr inbounds i64, i64* %37, i64 %5
%49 = getelementptr inbounds i64, i64* %38, i64 %6
%50 = bitcast i64* %48 to <4 x i64>*
%51 = load <4 x i64>, <4 x i64>* %50
%52 = bitcast i64* %49 to <4 x i64>*
%53 = load <4 x i64>, <4 x i64>* %52
%54 = sub nsw <4 x i64> %51, %53
%55 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %54, i1 true)
%56 = trunc <4 x i64> %55 to <4 x i32>
%57 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %56)
%58 = add i32 %57, %47
%59 = getelementptr inbounds i64, i64* %48, i64 %5
%60 = getelementptr inbounds i64, i64* %49, i64 %6
%61 = bitcast i64* %59 to <4 x i64>*
%62 = load <4 x i64>, <4 x i64>* %61
%63 = bitcast i64* %60 to <4 x i64>*
%64 = load <4 x i64>, <4 x i64>* %63
%65 = sub nsw <4 x i64> %62, %64
%66 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %65, i1 true)
%67 = trunc <4 x i64> %66 to <4 x i32>
%68 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %67)
%69 = add i32 %68, %58
%70 = getelementptr inbounds i64, i64* %59, i64 %5
%71 = getelementptr inbounds i64, i64* %60, i64 %6
%72 = bitcast i64* %70 to <4 x i64>*
%73 = load <4 x i64>, <4 x i64>* %72
%74 = bitcast i64* %71 to <4 x i64>*
%75 = load <4 x i64>, <4 x i64>* %74
%76 = sub nsw <4 x i64> %73, %75
%77 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %76, i1 true)
%78 = trunc <4 x i64> %77 to <4 x i32>
%79 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %78)
%80 = add i32 %79, %69
%81 = getelementptr inbounds i64, i64* %70, i64 %5
%82 = getelementptr inbounds i64, i64* %71, i64 %6
%83 = bitcast i64* %81 to <4 x i64>*
%84 = load <4 x i64>, <4 x i64>* %83
%85 = bitcast i64* %82 to <4 x i64>*
%86 = load <4 x i64>, <4 x i64>* %85
%87 = sub nsw <4 x i64> %84, %86
%88 = call <4 x i64> @llvm.abs.v4i64(<4 x i64> %87, i1 true)
%89 = trunc <4 x i64> %88 to <4 x i32>
%90 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %89)
%91 = add i32 %90, %80
ret i32 %91
}