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

x86 assembly (clang, -O2):
<pixel_sad_8x4>:
movslq %esi,%rsi
movslq %ecx,%rax
movdqu (%rdi),%xmm1
movdqu 0x10(%rdi),%xmm2
movdqu 0x20(%rdi),%xmm0
movdqu 0x30(%rdi),%xmm3
movdqu (%rdx),%xmm4
psubq  %xmm4,%xmm1
movdqu 0x10(%rdx),%xmm4
psubq  %xmm4,%xmm2
movdqu 0x20(%rdx),%xmm4
psubq  %xmm4,%xmm0
movdqu 0x30(%rdx),%xmm4
psubq  %xmm4,%xmm3
movdqa %xmm2,%xmm4
psrad  $0x1f,%xmm4
pshufd $0xf5,%xmm4,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm6
paddq  %xmm1,%xmm6
shufps $0x88,%xmm5,%xmm6
movdqa %xmm3,%xmm1
psrad  $0x1f,%xmm1
pshufd $0xf5,%xmm1,%xmm5
paddq  %xmm3,%xmm5
movdqa %xmm0,%xmm3
psrad  $0x1f,%xmm3
pshufd $0xf5,%xmm3,%xmm7
paddq  %xmm0,%xmm7
shufps $0x88,%xmm5,%xmm7
shufps $0xdd,%xmm1,%xmm3
xorps  %xmm7,%xmm3
shufps $0xdd,%xmm4,%xmm2
xorps  %xmm6,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%r10d
lea    (%rdi,%rsi,8),%rcx
lea    (%rdx,%rax,8),%r8
movdqu (%rdi,%rsi,8),%xmm1
movdqu 0x10(%rdi,%rsi,8),%xmm2
movdqu 0x20(%rdi,%rsi,8),%xmm0
movdqu 0x30(%rdi,%rsi,8),%xmm3
movdqu (%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm1
movdqu 0x10(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm2
movdqu 0x20(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm0
movdqu 0x30(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm3
movdqa %xmm2,%xmm4
psrad  $0x1f,%xmm4
pshufd $0xf5,%xmm4,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm6
paddq  %xmm1,%xmm6
shufps $0x88,%xmm5,%xmm6
movdqa %xmm3,%xmm1
psrad  $0x1f,%xmm1
pshufd $0xf5,%xmm1,%xmm5
paddq  %xmm3,%xmm5
movdqa %xmm0,%xmm3
psrad  $0x1f,%xmm3
pshufd $0xf5,%xmm3,%xmm7
paddq  %xmm0,%xmm7
shufps $0x88,%xmm5,%xmm7
shufps $0xdd,%xmm1,%xmm3
xorps  %xmm7,%xmm3
shufps $0xdd,%xmm4,%xmm2
xorps  %xmm6,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%r9d
add    %r10d,%r9d
lea    (%rcx,%rsi,8),%rdi
lea    (%r8,%rax,8),%rdx
movdqu (%rcx,%rsi,8),%xmm1
movdqu 0x10(%rcx,%rsi,8),%xmm2
movdqu 0x20(%rcx,%rsi,8),%xmm0
movdqu 0x30(%rcx,%rsi,8),%xmm3
movdqu (%r8,%rax,8),%xmm4
psubq  %xmm4,%xmm1
movdqu 0x10(%r8,%rax,8),%xmm4
psubq  %xmm4,%xmm2
movdqu 0x20(%r8,%rax,8),%xmm4
psubq  %xmm4,%xmm0
movdqu 0x30(%r8,%rax,8),%xmm4
psubq  %xmm4,%xmm3
movdqa %xmm2,%xmm4
psrad  $0x1f,%xmm4
pshufd $0xf5,%xmm4,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm6
paddq  %xmm1,%xmm6
shufps $0x88,%xmm5,%xmm6
movdqa %xmm3,%xmm1
psrad  $0x1f,%xmm1
pshufd $0xf5,%xmm1,%xmm5
paddq  %xmm3,%xmm5
movdqa %xmm0,%xmm3
psrad  $0x1f,%xmm3
pshufd $0xf5,%xmm3,%xmm7
paddq  %xmm0,%xmm7
shufps $0x88,%xmm5,%xmm7
shufps $0xdd,%xmm1,%xmm3
xorps  %xmm7,%xmm3
shufps $0xdd,%xmm4,%xmm2
xorps  %xmm6,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ecx
add    %r9d,%ecx
movdqu (%rdi,%rsi,8),%xmm1
movdqu 0x10(%rdi,%rsi,8),%xmm2
movdqu 0x20(%rdi,%rsi,8),%xmm0
movdqu 0x30(%rdi,%rsi,8),%xmm3
movdqu (%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm1
movdqu 0x10(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm2
movdqu 0x20(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm0
movdqu 0x30(%rdx,%rax,8),%xmm4
psubq  %xmm4,%xmm3
movdqa %xmm2,%xmm4
psrad  $0x1f,%xmm4
pshufd $0xf5,%xmm4,%xmm5
paddq  %xmm2,%xmm5
movdqa %xmm1,%xmm2
psrad  $0x1f,%xmm2
pshufd $0xf5,%xmm2,%xmm6
paddq  %xmm1,%xmm6
shufps $0x88,%xmm5,%xmm6
movdqa %xmm3,%xmm1
psrad  $0x1f,%xmm1
pshufd $0xf5,%xmm1,%xmm5
paddq  %xmm3,%xmm5
movdqa %xmm0,%xmm3
psrad  $0x1f,%xmm3
pshufd $0xf5,%xmm3,%xmm7
paddq  %xmm0,%xmm7
shufps $0x88,%xmm5,%xmm7
shufps $0xdd,%xmm1,%xmm3
xorps  %xmm7,%xmm3
shufps $0xdd,%xmm4,%xmm2
xorps  %xmm6,%xmm2
paddd  %xmm3,%xmm2
pshufd $0xee,%xmm2,%xmm0
paddd  %xmm2,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
define i32 @pixel_sad_8x4(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, 8
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_8x4(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 <8 x i64>*
%8 = load <8 x i64>, <8 x i64>* %7
%9 = bitcast i64* %2 to <8 x i64>*
%10 = load <8 x i64>, <8 x i64>* %9
%11 = sub nsw <8 x i64> %8, %10
%12 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> %11, i1 true)
%13 = trunc <8 x i64> %12 to <8 x i32>
%14 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %13)
%15 = getelementptr inbounds i64, i64* %0, i64 %5
%16 = getelementptr inbounds i64, i64* %2, i64 %6
%17 = bitcast i64* %15 to <8 x i64>*
%18 = load <8 x i64>, <8 x i64>* %17
%19 = bitcast i64* %16 to <8 x i64>*
%20 = load <8 x i64>, <8 x i64>* %19
%21 = sub nsw <8 x i64> %18, %20
%22 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> %21, i1 true)
%23 = trunc <8 x i64> %22 to <8 x i32>
%24 = call i32 @llvm.vector.reduce.add.v8i32(<8 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 <8 x i64>*
%29 = load <8 x i64>, <8 x i64>* %28
%30 = bitcast i64* %27 to <8 x i64>*
%31 = load <8 x i64>, <8 x i64>* %30
%32 = sub nsw <8 x i64> %29, %31
%33 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> %32, i1 true)
%34 = trunc <8 x i64> %33 to <8 x i32>
%35 = call i32 @llvm.vector.reduce.add.v8i32(<8 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 <8 x i64>*
%40 = load <8 x i64>, <8 x i64>* %39
%41 = bitcast i64* %38 to <8 x i64>*
%42 = load <8 x i64>, <8 x i64>* %41
%43 = sub nsw <8 x i64> %40, %42
%44 = call <8 x i64> @llvm.abs.v8i64(<8 x i64> %43, i1 true)
%45 = trunc <8 x i64> %44 to <8 x i32>
%46 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %45)
%47 = add i32 %46, %36
ret i32 %47
}