#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 /*<<< orphan*/ clipcolor(int, int, int, int *, int *, int *);
int lum(int, int, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int setlum(int base, int top) {
  int result = 0;
  int r = ((top >> 16) & 0xff), g = ((top >> 8) & 0xff), b = (top & 0xff);
  int d = 255 - lum(((base >> 16) & 0xff), ((base >> 8) & 0xff), (base & 0xff));
  int dr = 0, dg = 0, db = 0;
  clipcolor(r + d, g + d, b + d, &dr, &dg, &db);
  printf("### setlum 3: %i, %i, %i\n", dr, dg, db);
  return ((dr << 16) + (dg << 8) + db);
}


x86 assembly (clang, -O0):
<setlum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
sar    $0x10,%edi
and    $0xff,%edi
mov    -0x4(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
mov    -0x4(%rbp),%edx
and    $0xff,%edx
call   1040 <lum@plt>
mov    %eax,%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%edi
add    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
add    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1050 <clipcolor@plt>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
shl    $0x10,%eax
mov    -0x24(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
add    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ecx
mov    %edi,%eax
movzbl %ch,%ebx
movzbl %cl,%r14d
shr    $0x10,%ecx
movzbl %cl,%ebp
movzbl %ah,%esi
movzbl %al,%edx
shr    $0x10,%eax
movzbl %al,%edi
call   1040 <lum@plt>
mov    $0xff,%edx
sub    %eax,%edx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
add    %edx,%ebp
add    %edx,%ebx
add    %r14d,%edx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <clipcolor@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
mov    0xc(%rsp),%ecx
shl    $0x10,%ecx
mov    0x8(%rsp),%eax
shl    $0x8,%eax
add    %ecx,%eax
add    0x4(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"### setlum 3: %i, %i, %i\0A\00"
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
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%13 = load i32, i32* %4
%14 = ashr i32 %13, 16
%15 = and i32 %14, 255
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = ashr i32 %16, 8
%18 = and i32 %17, 255
store i32 %18, i32* %7
%19 = load i32, i32* %4
%20 = and i32 %19, 255
store i32 %20, i32* %8
%21 = load i32, i32* %3
%22 = ashr i32 %21, 16
%23 = and i32 %22, 255
%24 = load i32, i32* %3
%25 = ashr i32 %24, 8
%26 = and i32 %25, 255
%27 = load i32, i32* %3
%28 = and i32 %27, 255
%29 = call i32 @lum(i32 %23, i32 %26, i32 %28)
%30 = sub nsw i32 255, %29
store i32 %30, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%31 = load i32, i32* %6
%32 = load i32, i32* %9
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %7
%35 = load i32, i32* %9
%36 = add nsw i32 %34, %35
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = add nsw i32 %37, %38
%40 = call i32 @clipcolor(i32 %33, i32 %36, i32 %39, i32* %10, i32* %11, i32* %12)
%41 = load i32, i32* %10
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %41, i32 %42, i32 %43)
%45 = load i32, i32* %10
%46 = shl i32 %45, 16
%47 = load i32, i32* %11
%48 = shl i32 %47, 8
%49 = add nsw i32 %46, %48
%50 = load i32, i32* %12
%51 = add nsw i32 %49, %50
ret i32 %51
}

LLVM IR (-O2):
@.str = [26 x i8] c"### setlum 3: %i, %i, %i\0A\00"
define i32 @setlum(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = lshr i32 %1, 16
%7 = and i32 %6, 255
%8 = lshr i32 %1, 8
%9 = and i32 %8, 255
%10 = and i32 %1, 255
%11 = lshr i32 %0, 16
%12 = and i32 %11, 255
%13 = lshr i32 %0, 8
%14 = and i32 %13, 255
%15 = and i32 %0, 255
%16 = tail call i32 @lum(i32 %12, i32 %14, i32 %15)
%17 = sub nsw i32 255, %16
%18 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%19 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%20 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%21 = add nsw i32 %17, %7
%22 = add nsw i32 %17, %9
%23 = add nsw i32 %17, %10
%24 = call i32 @clipcolor(i32 %21, i32 %22, i32 %23, i32* %3, i32* %4, i32* %5)
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
%29 = load i32, i32* %3
%30 = shl i32 %29, 16
%31 = load i32, i32* %4
%32 = shl i32 %31, 8
%33 = add nsw i32 %32, %30
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
ret i32 %35
}