#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 */

/* Variables and functions */
int abs(unsigned int);
int color_dist(unsigned int c1, unsigned c2) {
  return (abs((c1 & 0xff) - (c2 & 0xff)) +
          2 * abs(((c1 >> 8) & 0xff) - ((c2 >> 8) & 0xff)) +
          abs(((c1 >> 16) & 0xff) - ((c2 >> 16) & 0xff)));
}


x86 assembly (clang, -O0):
<color_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
and    $0xff,%edi
mov    -0x8(%rbp),%eax
and    $0xff,%eax
sub    %eax,%edi
call   1030 <abs@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
shr    $0x8,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
sub    %eax,%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
shr    $0x10,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
sub    %eax,%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color_dist>:
mov    %esi,%eax
mov    %edi,%ecx
movzbl %cl,%edx
movzbl %al,%esi
sub    %esi,%edx
mov    %edx,%esi
neg    %esi
cmovs  %edx,%esi
movzbl %ch,%edx
movzbl %ah,%edi
sub    %edi,%edx
mov    %edx,%edi
neg    %edi
cmovs  %edx,%edi
shr    $0x10,%ecx
movzbl %cl,%ecx
shr    $0x10,%eax
movzbl %al,%eax
sub    %eax,%ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
add    %esi,%eax
lea    (%rax,%rdi,2),%eax
ret

LLVM IR (-O0):
define i32 @color_dist(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = and i32 %5, 255
%7 = load i32, i32* %4
%8 = and i32 %7, 255
%9 = sub i32 %6, %8
%10 = call i32 @abs(i32 %9)
%11 = load i32, i32* %3
%12 = lshr i32 %11, 8
%13 = and i32 %12, 255
%14 = load i32, i32* %4
%15 = lshr i32 %14, 8
%16 = and i32 %15, 255
%17 = sub i32 %13, %16
%18 = call i32 @abs(i32 %17)
%19 = mul nsw i32 2, %18
%20 = add nsw i32 %10, %19
%21 = load i32, i32* %3
%22 = lshr i32 %21, 16
%23 = and i32 %22, 255
%24 = load i32, i32* %4
%25 = lshr i32 %24, 16
%26 = and i32 %25, 255
%27 = sub i32 %23, %26
%28 = call i32 @abs(i32 %27)
%29 = add nsw i32 %20, %28
ret i32 %29
}

LLVM IR (-O2):
define i32 @color_dist(i32 %0, i32 %1) {
%3 = and i32 %0, 255
%4 = and i32 %1, 255
%5 = sub nsw i32 %3, %4
%6 = tail call i32 @llvm.abs.i32(i32 %5, i1 true)
%7 = lshr i32 %0, 8
%8 = and i32 %7, 255
%9 = lshr i32 %1, 8
%10 = and i32 %9, 255
%11 = sub nsw i32 %8, %10
%12 = tail call i32 @llvm.abs.i32(i32 %11, i1 true)
%13 = shl nuw nsw i32 %12, 1
%14 = lshr i32 %0, 16
%15 = and i32 %14, 255
%16 = lshr i32 %1, 16
%17 = and i32 %16, 255
%18 = sub nsw i32 %15, %17
%19 = tail call i32 @llvm.abs.i32(i32 %18, i1 true)
%20 = add nuw nsw i32 %19, %6
%21 = add nuw nsw i32 %20, %13
ret i32 %21
}