#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_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++) {
      i_sum += abs(pix1[x] - pix2[x]);
    }
    pix1 += i_stride_pix1;
    pix2 += i_stride_pix2;
  }
  return i_sum;
}


x86 assembly (clang, -O0):
<pixel_sad_16x16>:
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   $0x10,-0x28(%rbp)
jge    11bf <pixel_sad_16x16+0xaf>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    1187 <pixel_sad_16x16+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_16x16+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_16x16+0x24>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pixel_sad_16x16>:
movslq %esi,%r8
movslq %ecx,%r9
shl    $0x3,%r8
shl    $0x3,%r9
xor    %eax,%eax
mov    $0x10,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movdqu 0x70(%rdi),%xmm7
movdqu 0x60(%rdi),%xmm0
movdqu (%rdi),%xmm10
movdqu 0x10(%rdi),%xmm12
movdqu 0x20(%rdi),%xmm2
movdqu 0x30(%rdi),%xmm1
movdqu 0x50(%rdi),%xmm9
movdqu 0x40(%rdi),%xmm8
movdqu 0x70(%rdx),%xmm3
psubq  %xmm3,%xmm7
movdqu 0x60(%rdx),%xmm3
psubq  %xmm3,%xmm0
movdqu (%rdx),%xmm3
psubq  %xmm3,%xmm10
movdqu 0x10(%rdx),%xmm3
psubq  %xmm3,%xmm12
movdqu 0x20(%rdx),%xmm3
psubq  %xmm3,%xmm2
movdqu 0x30(%rdx),%xmm3
psubq  %xmm3,%xmm1
movdqu 0x50(%rdx),%xmm3
psubq  %xmm3,%xmm9
movdqu 0x40(%rdx),%xmm3
psubq  %xmm3,%xmm8
movdqa %xmm1,%xmm11
psrad  $0x1f,%xmm11
pshufd $0xf5,%xmm11,%xmm3
paddq  %xmm1,%xmm3
movdqa %xmm2,%xmm1
psrad  $0x1f,%xmm1
pshufd $0xf5,%xmm1,%xmm14
paddq  %xmm2,%xmm14
shufps $0x88,%xmm3,%xmm14
movdqa %xmm7,%xmm13
psrad  $0x1f,%xmm13
pshufd $0xf5,%xmm13,%xmm4
paddq  %xmm7,%xmm4
movdqa %xmm0,%xmm7
psrad  $0x1f,%xmm7
pshufd $0xf5,%xmm7,%xmm15
paddq  %xmm0,%xmm15
shufps $0x88,%xmm4,%xmm15
movdqa %xmm12,%xmm4
psrad  $0x1f,%xmm4
pshufd $0xf5,%xmm4,%xmm6
paddq  %xmm12,%xmm6
movdqa %xmm10,%xmm0
psrad  $0x1f,%xmm0
pshufd $0xf5,%xmm0,%xmm2
paddq  %xmm10,%xmm2
shufps $0x88,%xmm6,%xmm2
movdqa %xmm9,%xmm6
psrad  $0x1f,%xmm6
pshufd $0xf5,%xmm6,%xmm10
paddq  %xmm9,%xmm10
movdqa %xmm8,%xmm3
psrad  $0x1f,%xmm3
pshufd $0xf5,%xmm3,%xmm5
paddq  %xmm8,%xmm5
shufps $0x88,%xmm10,%xmm5
shufps $0xdd,%xmm6,%xmm3
xorps  %xmm5,%xmm3
shufps $0xdd,%xmm4,%xmm0
xorps  %xmm2,%xmm0
paddd  %xmm3,%xmm0
shufps $0xdd,%xmm13,%xmm7
xorps  %xmm15,%xmm7
shufps $0xdd,%xmm11,%xmm1
xorps  %xmm14,%xmm1
paddd  %xmm7,%xmm1
paddd  %xmm0,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ecx
add    %ecx,%eax
add    %r8,%rdi
add    %r9,%rdx
add    $0xffffffff,%esi
jne    1120 <pixel_sad_16x16+0x20>
ret

LLVM IR (-O0):
define i32 @pixel_sad_16x16(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, 16
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, 16
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_16x16(i64* nocapture %0, i32 %1, i64* nocapture %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = sext i32 %3 to i64
br label %7
7: ; preds = %4, %7
%8 = phi i32 [ 0, %4 ], [ %23, %7 ]
%9 = phi i32 [ 0, %4 ], [ %20, %7 ]
%10 = phi i64* [ %0, %4 ], [ %21, %7 ]
%11 = phi i64* [ %2, %4 ], [ %22, %7 ]
%12 = bitcast i64* %10 to <16 x i64>*
%13 = load <16 x i64>, <16 x i64>* %12
%14 = bitcast i64* %11 to <16 x i64>*
%15 = load <16 x i64>, <16 x i64>* %14
%16 = sub nsw <16 x i64> %13, %15
%17 = call <16 x i64> @llvm.abs.v16i64(<16 x i64> %16, i1 true)
%18 = trunc <16 x i64> %17 to <16 x i32>
%19 = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %18)
%20 = add i32 %19, %9
%21 = getelementptr inbounds i64, i64* %10, i64 %5
%22 = getelementptr inbounds i64, i64* %11, i64 %6
%23 = add nuw nsw i32 %8, 1
%24 = icmp eq i32 %23, 16
br i1 %24, label %25, label %7
25: ; preds = %7
ret i32 %20
}