#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 */
uint32_t __hsail_lerp(uint32_t a, uint32_t b, uint32_t c) {
  uint32_t e3 =
      (((((a >> 24) & 0xff) + ((b >> 24) & 0xff) + ((c >> 24) & 0x1)) / 2) &
       0xff)
      << 24;
  uint32_t e2 =
      (((((a >> 16) & 0xff) + ((b >> 16) & 0xff) + ((c >> 16) & 0x1)) / 2) &
       0xff)
      << 16;
  uint32_t e1 =
      (((((a >> 8) & 0xff) + ((b >> 8) & 0xff) + ((c >> 8) & 0x1)) / 2) & 0xff)
      << 8;
  uint32_t e0 = (((a & 0xff) + (b & 0xff) + (c & 0x1)) / 2) & 0xff;
  return e3 | e2 | e1 | e0;
}


x86 assembly (clang, -O0):
<__hsail_lerp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    -0x8(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    -0xc(%rbp),%ecx
sar    $0x18,%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
and    $0xff,%eax
shl    $0x18,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    -0x8(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
and    $0xff,%eax
shl    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    -0x8(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
and    $0xff,%eax
shl    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    -0x8(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    -0xc(%rbp),%ecx
and    $0x1,%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
or     -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hsail_lerp>:
push   %rbp
push   %rbx
mov    %esi,%ecx
mov    %edi,%ebx
mov    %edi,%r9d
movzbl %bh,%ebp
movzbl %bl,%r8d
shr    $0x18,%ebx
mov    %esi,%edi
movzbl %ch,%esi
movzbl %cl,%eax
shr    $0x18,%ecx
add    %ebx,%ecx
mov    %edx,%ebx
shr    $0x18,%ebx
and    $0x1,%ebx
add    %ecx,%ebx
shr    $0x10,%r9d
movzbl %r9b,%ecx
shr    $0x10,%edi
movzbl %dil,%edi
add    %ecx,%edi
mov    %edx,%ecx
shr    $0x10,%ecx
and    $0x1,%ecx
add    %edi,%ecx
and    $0xfffffffe,%ebx
shl    $0x17,%ebx
shl    $0xf,%ecx
and    $0xff0000,%ecx
add    %ebp,%esi
mov    %edx,%edi
shr    $0x8,%edi
and    $0x1,%edi
add    %esi,%edi
shl    $0x7,%edi
and    $0xff00,%edi
add    %r8d,%eax
and    $0x1,%edx
add    %edx,%eax
shr    %eax
or     %ecx,%eax
or     %ebx,%eax
or     %edi,%eax
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__hsail_lerp(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %4
%12 = ashr i32 %11, 24
%13 = and i32 %12, 255
%14 = load i32, i32* %5
%15 = ashr i32 %14, 24
%16 = and i32 %15, 255
%17 = add nsw i32 %13, %16
%18 = load i32, i32* %6
%19 = ashr i32 %18, 24
%20 = and i32 %19, 1
%21 = add nsw i32 %17, %20
%22 = sdiv i32 %21, 2
%23 = and i32 %22, 255
%24 = shl i32 %23, 24
store i32 %24, i32* %7
%25 = load i32, i32* %4
%26 = ashr i32 %25, 16
%27 = and i32 %26, 255
%28 = load i32, i32* %5
%29 = ashr i32 %28, 16
%30 = and i32 %29, 255
%31 = add nsw i32 %27, %30
%32 = load i32, i32* %6
%33 = ashr i32 %32, 16
%34 = and i32 %33, 1
%35 = add nsw i32 %31, %34
%36 = sdiv i32 %35, 2
%37 = and i32 %36, 255
%38 = shl i32 %37, 16
store i32 %38, i32* %8
%39 = load i32, i32* %4
%40 = ashr i32 %39, 8
%41 = and i32 %40, 255
%42 = load i32, i32* %5
%43 = ashr i32 %42, 8
%44 = and i32 %43, 255
%45 = add nsw i32 %41, %44
%46 = load i32, i32* %6
%47 = ashr i32 %46, 8
%48 = and i32 %47, 1
%49 = add nsw i32 %45, %48
%50 = sdiv i32 %49, 2
%51 = and i32 %50, 255
%52 = shl i32 %51, 8
store i32 %52, i32* %9
%53 = load i32, i32* %4
%54 = and i32 %53, 255
%55 = load i32, i32* %5
%56 = and i32 %55, 255
%57 = add nsw i32 %54, %56
%58 = load i32, i32* %6
%59 = and i32 %58, 1
%60 = add nsw i32 %57, %59
%61 = sdiv i32 %60, 2
%62 = and i32 %61, 255
store i32 %62, i32* %10
%63 = load i32, i32* %7
%64 = load i32, i32* %8
%65 = or i32 %63, %64
%66 = load i32, i32* %9
%67 = or i32 %65, %66
%68 = load i32, i32* %10
%69 = or i32 %67, %68
ret i32 %69
}

LLVM IR (-O2):
define i32 @__hsail_lerp(i32 %0, i32 %1, i32 %2) {
%4 = lshr i32 %0, 24
%5 = lshr i32 %1, 24
%6 = add nuw nsw i32 %5, %4
%7 = lshr i32 %2, 24
%8 = and i32 %7, 1
%9 = add nuw nsw i32 %6, %8
%10 = shl nuw i32 %9, 23
%11 = and i32 %10, -16777216
%12 = lshr i32 %0, 16
%13 = and i32 %12, 255
%14 = lshr i32 %1, 16
%15 = and i32 %14, 255
%16 = add nuw nsw i32 %15, %13
%17 = lshr i32 %2, 16
%18 = and i32 %17, 1
%19 = add nuw nsw i32 %16, %18
%20 = shl nuw nsw i32 %19, 15
%21 = and i32 %20, 16711680
%22 = lshr i32 %0, 8
%23 = and i32 %22, 255
%24 = lshr i32 %1, 8
%25 = and i32 %24, 255
%26 = add nuw nsw i32 %25, %23
%27 = lshr i32 %2, 8
%28 = and i32 %27, 1
%29 = add nuw nsw i32 %26, %28
%30 = shl nuw nsw i32 %29, 7
%31 = and i32 %30, 65280
%32 = and i32 %0, 255
%33 = and i32 %1, 255
%34 = add nuw nsw i32 %33, %32
%35 = and i32 %2, 1
%36 = add nuw nsw i32 %34, %35
%37 = lshr i32 %36, 1
%38 = or i32 %21, %37
%39 = or i32 %38, %11
%40 = or i32 %39, %31
ret i32 %40
}