#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*/ print(int, char *, int, int, int);
int color(int tty, int fg, int bg) {
  if (fg > -1)
    print(tty, "\033[38;2;%d;%d;%dm", (fg & 0x00FF0000) >> 16,
          (fg & 0x0000FF00) >> 8, (fg & 0x0000FF));
  if (bg > -1)
    print(tty, "\033[48;2;%d;%d;%dm", (bg & 0x00FF0000) >> 16,
          (bg & 0x0000FF00) >> 8, (bg & 0x0000FF));
  return 0;
}


x86 assembly (clang, -O0):
<color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jle    115d <color+0x4d>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
and    $0xff0000,%edx
sar    $0x10,%edx
mov    -0x8(%rbp),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%r8d
and    $0xff,%r8d
lea    0xea8(%rip),%rsi
call   1030 <print@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jle    1199 <color+0x89>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
and    $0xff0000,%edx
sar    $0x10,%edx
mov    -0xc(%rbp),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
mov    -0xc(%rbp),%r8d
and    $0xff,%r8d
lea    0xe7d(%rip),%rsi
call   1030 <print@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %edi,%ebp
test   %esi,%esi
js     113a <color+0x2a>
mov    %esi,%eax
mov    %esi,%ecx
shr    $0x10,%ecx
movzbl %cl,%edx
movzbl %ah,%ecx
movzbl %al,%r8d
lea    0xecd(%rip),%rsi
mov    %ebp,%edi
call   1030 <print@plt>
test   %ebx,%ebx
js     115b <color+0x4b>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edx
movzbl %bh,%ecx
movzbl %bl,%r8d
lea    0xebd(%rip),%rsi
mov    %ebp,%edi
call   1030 <print@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\1B[38;2;%d;%d;%dm\00"
@.str.1 = [17 x i8] c"\1B[48;2;%d;%d;%dm\00"
define i32 @color(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %5
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = and i32 %11, 16711680
%13 = ashr i32 %12, 16
%14 = load i32, i32* %5
%15 = and i32 %14, 65280
%16 = ashr i32 %15, 8
%17 = load i32, i32* %5
%18 = and i32 %17, 255
%19 = call i32 @print(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %18)
br label %20
20: ; preds = %9, %3
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %34
23: ; preds = %20
%24 = load i32, i32* %4
%25 = load i32, i32* %6
%26 = and i32 %25, 16711680
%27 = ashr i32 %26, 16
%28 = load i32, i32* %6
%29 = and i32 %28, 65280
%30 = ashr i32 %29, 8
%31 = load i32, i32* %6
%32 = and i32 %31, 255
%33 = call i32 @print(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %30, i32 %32)
br label %34
34: ; preds = %23, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"\1B[38;2;%d;%d;%dm\00"
@.str.1 = [17 x i8] c"\1B[48;2;%d;%d;%dm\00"
define i32 @color(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, -1
br i1 %4, label %5, label %12
5: ; preds = %3
%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 = tail call i32 @print(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %10)
br label %12
12: ; preds = %5, %3
%13 = icmp sgt i32 %2, -1
br i1 %13, label %14, label %21
14: ; preds = %12
%15 = lshr i32 %2, 16
%16 = and i32 %15, 255
%17 = lshr i32 %2, 8
%18 = and i32 %17, 255
%19 = and i32 %2, 255
%20 = tail call i32 @print(i32 %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18, i32 %19)
br label %21
21: ; preds = %14, %12
ret i32 0
}