#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 uint32_t;

/* Variables and functions */
int abs_diff(int, int);
uint32_t __hsail_sad_u8x4(uint32_t a, uint32_t b, uint32_t add) {
  return abs_diff((a >> 24) & 0xff, (b >> 24) & 0xff) +
         abs_diff((a >> 16) & 0xff, (b >> 16) & 0xff) +
         abs_diff((a >> 8) & 0xff, (b >> 8) & 0xff) +
         abs_diff((a >> 0) & 0xff, (b >> 0) & 0xff) + add;
}


x86 assembly (clang, -O0):
<__hsail_sad_u8x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
sar    $0x18,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%esi
sar    $0x18,%esi
and    $0xff,%esi
call   1030 <abs_diff@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
sar    $0x10,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%esi
sar    $0x10,%esi
and    $0xff,%esi
call   1030 <abs_diff@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
call   1030 <abs_diff@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
sar    $0x0,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%esi
sar    $0x0,%esi
and    $0xff,%esi
call   1030 <abs_diff@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
add    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_sad_u8x4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %edi,%eax
mov    %edi,%ebx
shr    $0x18,%eax
mov    %esi,%ecx
mov    %esi,%r15d
shr    $0x18,%ecx
mov    %eax,%edi
mov    %ecx,%esi
call   1030 <abs_diff@plt>
mov    %eax,%ebp
mov    %ebx,%eax
mov    %ebx,%r13d
shr    $0x10,%eax
movzbl %al,%edi
mov    %r15d,%ebx
mov    %r15d,%eax
shr    $0x10,%eax
movzbl %al,%esi
call   1030 <abs_diff@plt>
mov    %eax,%r15d
mov    %r13d,%eax
movzbl %ah,%edi
movzbl %bh,%esi
call   1030 <abs_diff@plt>
mov    %eax,%r12d
movzbl %r13b,%edi
movzbl %bl,%esi
call   1030 <abs_diff@plt>
add    %r14d,%ebp
add    %r15d,%ebp
add    %r12d,%ebp
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__hsail_sad_u8x4(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = ashr i32 %7, 24
%9 = and i32 %8, 255
%10 = load i32, i32* %5
%11 = ashr i32 %10, 24
%12 = and i32 %11, 255
%13 = call i32 @abs_diff(i32 %9, i32 %12)
%14 = load i32, i32* %4
%15 = ashr i32 %14, 16
%16 = and i32 %15, 255
%17 = load i32, i32* %5
%18 = ashr i32 %17, 16
%19 = and i32 %18, 255
%20 = call i32 @abs_diff(i32 %16, i32 %19)
%21 = add nsw i32 %13, %20
%22 = load i32, i32* %4
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = load i32, i32* %5
%26 = ashr i32 %25, 8
%27 = and i32 %26, 255
%28 = call i32 @abs_diff(i32 %24, i32 %27)
%29 = add nsw i32 %21, %28
%30 = load i32, i32* %4
%31 = ashr i32 %30, 0
%32 = and i32 %31, 255
%33 = load i32, i32* %5
%34 = ashr i32 %33, 0
%35 = and i32 %34, 255
%36 = call i32 @abs_diff(i32 %32, i32 %35)
%37 = add nsw i32 %29, %36
%38 = load i32, i32* %6
%39 = add nsw i32 %37, %38
ret i32 %39
}

LLVM IR (-O2):
define i32 @__hsail_sad_u8x4(i32 %0, i32 %1, i32 %2) {
%4 = lshr i32 %0, 24
%5 = lshr i32 %1, 24
%6 = tail call i32 @abs_diff(i32 %4, i32 %5)
%7 = lshr i32 %0, 16
%8 = and i32 %7, 255
%9 = lshr i32 %1, 16
%10 = and i32 %9, 255
%11 = tail call i32 @abs_diff(i32 %8, i32 %10)
%12 = lshr i32 %0, 8
%13 = and i32 %12, 255
%14 = lshr i32 %1, 8
%15 = and i32 %14, 255
%16 = tail call i32 @abs_diff(i32 %13, i32 %15)
%17 = and i32 %0, 255
%18 = and i32 %1, 255
%19 = tail call i32 @abs_diff(i32 %17, i32 %18)
%20 = add i32 %6, %2
%21 = add i32 %20, %11
%22 = add i32 %21, %16
%23 = add i32 %22, %19
ret i32 %23
}