#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 /*<<< orphan*/ GC;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XSetForeground(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  unsigned long);
void set_color(Display *disp, GC gc, int r, int g, int b) {
  unsigned long int p;
  if (r < 0)
    r = 0;
  else if (r > 255)
    r = 255;
  if (g < 0)
    g = 0;
  else if (g > 255)
    g = 255;
  if (b < 0)
    b = 0;
  else if (b > 255)
    b = 255;
  p = (r << 16) | (g << 8) | (b);
  XSetForeground(disp, gc, p);
}


x86 assembly (clang, -O0):
<set_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    113f <set_color+0x2f>
movl   $0x0,-0x10(%rbp)
jmp    1158 <set_color+0x48>
cmpl   $0xff,-0x10(%rbp)
jle    1153 <set_color+0x43>
movl   $0xff,-0x10(%rbp)
jmp    1158 <set_color+0x48>
cmpl   $0x0,-0x14(%rbp)
jge    116e <set_color+0x5e>
movl   $0x0,-0x14(%rbp)
jmp    1187 <set_color+0x77>
cmpl   $0xff,-0x14(%rbp)
jle    1182 <set_color+0x72>
movl   $0xff,-0x14(%rbp)
jmp    1187 <set_color+0x77>
cmpl   $0x0,-0x18(%rbp)
jge    119d <set_color+0x8d>
movl   $0x0,-0x18(%rbp)
jmp    11b6 <set_color+0xa6>
cmpl   $0xff,-0x18(%rbp)
jle    11b1 <set_color+0xa1>
movl   $0xff,-0x18(%rbp)
jmp    11b6 <set_color+0xa6>
mov    -0x10(%rbp),%eax
shl    $0x10,%eax
mov    -0x14(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x18(%rbp),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <XSetForeground@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_color>:
cmp    $0xff,%edx
mov    $0xff,%eax
cmovl  %edx,%eax
shl    $0x10,%eax
xor    %r9d,%r9d
test   %edx,%edx
cmovs  %r9d,%eax
cmp    $0xff,%ecx
mov    $0xff,%edx
cmovl  %ecx,%edx
shl    $0x8,%edx
test   %ecx,%ecx
cmovs  %r9d,%edx
mov    $0xff,%ecx
cmp    $0xff,%r8d
cmovl  %r8d,%ecx
test   %ecx,%ecx
cmovs  %r9d,%ecx
or     %eax,%edx
or     %ecx,%edx
movslq %edx,%rdx
jmp    1030 <XSetForeground@plt>

LLVM IR (-O0):
define void @set_color(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %5
store i32 0, i32* %8
br label %20
15: ; preds = %5
%16 = load i32, i32* %8
%17 = icmp sgt i32 %16, 255
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 255, i32* %8
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %9
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 0, i32* %9
br label %29
24: ; preds = %20
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 255
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 255, i32* %9
br label %28
28: ; preds = %27, %24
br label %29
29: ; preds = %28, %23
%30 = load i32, i32* %10
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 0, i32* %10
br label %38
33: ; preds = %29
%34 = load i32, i32* %10
%35 = icmp sgt i32 %34, 255
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 255, i32* %10
br label %37
37: ; preds = %36, %33
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %8
%40 = shl i32 %39, 16
%41 = load i32, i32* %9
%42 = shl i32 %41, 8
%43 = or i32 %40, %42
%44 = load i32, i32* %10
%45 = or i32 %43, %44
%46 = sext i32 %45 to i64
store i64 %46, i64* %11
%47 = load i32*, i32** %6
%48 = load i32, i32* %7
%49 = load i64, i64* %11
%50 = call i32 @XSetForeground(i32* %47, i32 %48, i64 %49)
ret void
}

LLVM IR (-O2):
define void @set_color(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %2, 0
%7 = icmp slt i32 %2, 255
%8 = select i1 %7, i32 %2, i32 255
%9 = shl i32 %8, 16
%10 = select i1 %6, i32 0, i32 %9
%11 = icmp slt i32 %3, 0
%12 = icmp slt i32 %3, 255
%13 = select i1 %12, i32 %3, i32 255
%14 = shl i32 %13, 8
%15 = select i1 %11, i32 0, i32 %14
%16 = icmp slt i32 %4, 255
%17 = select i1 %16, i32 %4, i32 255
%18 = icmp sgt i32 %17, 0
%19 = select i1 %18, i32 %17, i32 0
%20 = or i32 %15, %10
%21 = or i32 %20, %19
%22 = sext i32 %21 to i64
%23 = tail call i32 @XSetForeground(i32* %0, i32 %1, i64 %22)
ret void
}