#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_sadhi_u16x2_u8x4(uint32_t a, uint32_t b, uint32_t add) {
  return (abs_diff((a >> 24) & 0xff, (b >> 24) & 0xff) << 16) +
         (abs_diff((a >> 16) & 0xff, (b >> 16) & 0xff) << 16) +
         (abs_diff((a >> 8) & 0xff, (b >> 8) & 0xff) << 16) +
         (abs_diff((a >> 0) & 0xff, (b >> 0) & 0xff) << 16) + add;
}


x86 assembly (clang, -O0):
<__hsail_sadhi_u16x2_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>
shl    $0x10,%eax
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
shl    $0x10,%ecx
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
shl    $0x10,%ecx
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
shl    $0x10,%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @__hsail_sadhi_u16x2_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 = shl i32 %13, 16
%15 = load i32, i32* %4
%16 = ashr i32 %15, 16
%17 = and i32 %16, 255
%18 = load i32, i32* %5
%19 = ashr i32 %18, 16
%20 = and i32 %19, 255
%21 = call i32 @abs_diff(i32 %17, i32 %20)
%22 = shl i32 %21, 16
%23 = add nsw i32 %14, %22
%24 = load i32, i32* %4
%25 = ashr i32 %24, 8
%26 = and i32 %25, 255
%27 = load i32, i32* %5
%28 = ashr i32 %27, 8
%29 = and i32 %28, 255
%30 = call i32 @abs_diff(i32 %26, i32 %29)
%31 = shl i32 %30, 16
%32 = add nsw i32 %23, %31
%33 = load i32, i32* %4
%34 = ashr i32 %33, 0
%35 = and i32 %34, 255
%36 = load i32, i32* %5
%37 = ashr i32 %36, 0
%38 = and i32 %37, 255
%39 = call i32 @abs_diff(i32 %35, i32 %38)
%40 = shl i32 %39, 16
%41 = add nsw i32 %32, %40
%42 = load i32, i32* %6
%43 = add nsw i32 %41, %42
ret i32 %43
}

LLVM IR (-O2):
define i32 @__hsail_sadhi_u16x2_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 = add i32 %11, %6
%13 = lshr i32 %0, 8
%14 = and i32 %13, 255
%15 = lshr i32 %1, 8
%16 = and i32 %15, 255
%17 = tail call i32 @abs_diff(i32 %14, i32 %16)
%18 = add i32 %12, %17
%19 = and i32 %0, 255
%20 = and i32 %1, 255
%21 = tail call i32 @abs_diff(i32 %19, i32 %20)
%22 = add i32 %18, %21
%23 = shl i32 %22, 16
%24 = add nsw i32 %23, %2
ret i32 %24
}