#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 ClipColour(int, int, int, int);
int setLum(int base, int top) {
  int red = ((top >> 16) & 0xff), green = ((top >> 8) & 0xff),
      blue = (top & 0xff);
  int lum = (((base >> 16) & 0xff) * 0.3 + ((base >> 8) & 0xff) * 0.59 +
             (base & 0xff) * 0.11);
  int diff = lum - (((top >> 16) & 0xff) * 0.3 + ((top >> 8) & 0xff) * 0.59 +
                    (top & 0xff) * 0.11);
  red += diff;
  green += diff;
  blue += diff;
  return ClipColour(red, green, blue, lum);
}


x86 assembly (clang, -O0):
<setLum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm1
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm0
movsd  0xea5(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0xe91(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x4(%rbp),%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe6d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm2
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe43(%rip),%xmm3
mulsd  %xmm3,%xmm1
movsd  0xe2f(%rip),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
mov    -0x8(%rbp),%eax
and    $0xff,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe0b(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <ClipColour@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setLum>:
push   %rbp
push   %rbx
mov    %esi,%eax
mov    %edi,%ecx
movzbl %ch,%ebp
movzbl %cl,%ebx
shr    $0x10,%ecx
movzbl %cl,%ecx
cvtsi2sd %ecx,%xmm0
movzbl %ah,%esi
movzbl %al,%edx
shr    $0x10,%eax
movzbl %al,%edi
cvtsi2sd %ebp,%xmm1
movsd  0xec2(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xebe(%rip),%xmm3
mulsd  %xmm3,%xmm0
cvtsi2sd %ebx,%xmm4
addsd  %xmm1,%xmm0
movsd  0xeb2(%rip),%xmm1
mulsd  %xmm1,%xmm4
addsd  %xmm0,%xmm4
cvttsd2si %xmm4,%ecx
cvttpd2dq %xmm4,%xmm0
cvtdq2pd %xmm0,%xmm0
xorps  %xmm4,%xmm4
cvtsi2sd %edi,%xmm4
cvtsi2sd %esi,%xmm5
mulsd  %xmm2,%xmm5
mulsd  %xmm3,%xmm4
addsd  %xmm5,%xmm4
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm4,%xmm2
subsd  %xmm2,%xmm0
cvttsd2si %xmm0,%eax
add    %eax,%edi
add    %eax,%esi
add    %eax,%edx
pop    %rbx
pop    %rbp
jmp    1030 <ClipColour@plt>

LLVM IR (-O0):
define i32 @setLum(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = ashr i32 %10, 16
%12 = and i32 %11, 255
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = ashr i32 %13, 8
%15 = and i32 %14, 255
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = and i32 %16, 255
store i32 %17, i32* %7
%18 = load i32, i32* %3
%19 = ashr i32 %18, 16
%20 = and i32 %19, 255
%21 = sitofp i32 %20 to double
%22 = load i32, i32* %3
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = sitofp i32 %24 to double
%26 = fmul double %25, 5.900000e-01
%27 = call double @llvm.fmuladd.f64(double %21, double 3.000000e-01, double %26)
%28 = load i32, i32* %3
%29 = and i32 %28, 255
%30 = sitofp i32 %29 to double
%31 = call double @llvm.fmuladd.f64(double %30, double 1.100000e-01, double %27)
%32 = fptosi double %31 to i32
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = sitofp i32 %33 to double
%35 = load i32, i32* %4
%36 = ashr i32 %35, 16
%37 = and i32 %36, 255
%38 = sitofp i32 %37 to double
%39 = load i32, i32* %4
%40 = ashr i32 %39, 8
%41 = and i32 %40, 255
%42 = sitofp i32 %41 to double
%43 = fmul double %42, 5.900000e-01
%44 = call double @llvm.fmuladd.f64(double %38, double 3.000000e-01, double %43)
%45 = load i32, i32* %4
%46 = and i32 %45, 255
%47 = sitofp i32 %46 to double
%48 = call double @llvm.fmuladd.f64(double %47, double 1.100000e-01, double %44)
%49 = fsub double %34, %48
%50 = fptosi double %49 to i32
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = load i32, i32* %5
%53 = add nsw i32 %52, %51
store i32 %53, i32* %5
%54 = load i32, i32* %9
%55 = load i32, i32* %6
%56 = add nsw i32 %55, %54
store i32 %56, i32* %6
%57 = load i32, i32* %9
%58 = load i32, i32* %7
%59 = add nsw i32 %58, %57
store i32 %59, i32* %7
%60 = load i32, i32* %5
%61 = load i32, i32* %6
%62 = load i32, i32* %7
%63 = load i32, i32* %8
%64 = call i32 @ClipColour(i32 %60, i32 %61, i32 %62, i32 %63)
ret i32 %64
}

LLVM IR (-O2):
define i32 @setLum(i32 %0, i32 %1) {
%3 = lshr i32 %1, 16
%4 = and i32 %3, 255
%5 = lshr i32 %1, 8
%6 = and i32 %5, 255
%7 = and i32 %1, 255
%8 = lshr i32 %0, 16
%9 = and i32 %8, 255
%10 = sitofp i32 %9 to double
%11 = lshr i32 %0, 8
%12 = and i32 %11, 255
%13 = sitofp i32 %12 to double
%14 = fmul double %13, 5.900000e-01
%15 = tail call double @llvm.fmuladd.f64(double %10, double 3.000000e-01, double %14)
%16 = and i32 %0, 255
%17 = sitofp i32 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %17, double 1.100000e-01, double %15)
%19 = fptosi double %18 to i32
%20 = sitofp i32 %19 to double
%21 = sitofp i32 %4 to double
%22 = sitofp i32 %6 to double
%23 = fmul double %22, 5.900000e-01
%24 = tail call double @llvm.fmuladd.f64(double %21, double 3.000000e-01, double %23)
%25 = sitofp i32 %7 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 1.100000e-01, double %24)
%27 = fsub double %20, %26
%28 = fptosi double %27 to i32
%29 = add nsw i32 %4, %28
%30 = add nsw i32 %6, %28
%31 = add nsw i32 %7, %28
%32 = tail call i32 @ClipColour(i32 %29, i32 %30, i32 %31, i32 %19)
ret i32 %32
}