#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;
typedef int int32_t;

/* Variables and functions */
__attribute__((always_)) uint32_t __USAD8(uint32_t x, uint32_t y) {
  int32_t r, s, t, u;
  r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
  s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
  t = (((x << 8) >> 24) - ((y << 8) >> 24)) & 0x000000FF;
  u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
  return (u + t + s + r);
}


x86 assembly (clang, -O0):
<__USAD8>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x18,%eax
sar    $0x18,%eax
mov    -0x8(%rbp),%ecx
shl    $0x18,%ecx
sar    $0x18,%ecx
sub    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x10,%eax
sar    $0x18,%eax
mov    -0x8(%rbp),%ecx
shl    $0x10,%ecx
sar    $0x18,%ecx
sub    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
sar    $0x18,%eax
mov    -0x8(%rbp),%ecx
shl    $0x8,%ecx
sar    $0x18,%ecx
sub    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
mov    -0x8(%rbp),%ecx
sar    $0x18,%ecx
sub    %ecx,%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__USAD8>:
mov    %edi,%eax
sub    %esi,%eax
movzbl %al,%eax
mov    %edi,%ecx
shr    $0x8,%ecx
mov    %esi,%edx
shr    $0x8,%edx
sub    %edx,%ecx
movzbl %cl,%r8d
mov    %edi,%edx
shr    $0x10,%edx
mov    %esi,%ecx
shr    $0x10,%ecx
sub    %ecx,%edx
movzbl %dl,%ecx
add    %eax,%ecx
shr    $0x18,%edi
shr    $0x18,%esi
sub    %esi,%edi
movzbl %dil,%eax
add    %ecx,%eax
add    %r8d,%eax
ret

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

LLVM IR (-O2):
define i32 @__USAD8(i32 %0, i32 %1) {
%3 = sub i32 %0, %1
%4 = and i32 %3, 255
%5 = lshr i32 %0, 8
%6 = lshr i32 %1, 8
%7 = sub nsw i32 %5, %6
%8 = and i32 %7, 255
%9 = lshr i32 %0, 16
%10 = lshr i32 %1, 16
%11 = sub nsw i32 %9, %10
%12 = and i32 %11, 255
%13 = lshr i32 %0, 24
%14 = lshr i32 %1, 24
%15 = sub nsw i32 %13, %14
%16 = and i32 %15, 255
%17 = add nuw nsw i32 %12, %4
%18 = add nuw nsw i32 %17, %16
%19 = add nuw nsw i32 %18, %8
ret i32 %19
}