#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*/ printf(char *, unsigned int, ...);
void textcolor(unsigned int code) {
  unsigned int mode = code >> 24;
  if (mode == 0)
    printf("\e[3%dm", (code << 24) >> 24);
  else if (mode == 1)
    printf("\e[38;5;%dm", (code << 24) >> 24);
  else if (mode == 2) {
    printf("\e[38;2;%d;%d;%dm", (code << 8) >> 24, (code << 16) >> 24,
           (code << 24) >> 24);
  }
}


x86 assembly (clang, -O0):
<textcolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x18,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114a <textcolor+0x3a>
mov    -0x4(%rbp),%esi
shl    $0x18,%esi
shr    $0x18,%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ad <textcolor+0x9d>
cmpl   $0x1,-0x8(%rbp)
jne    1170 <textcolor+0x60>
mov    -0x4(%rbp),%esi
shl    $0x18,%esi
shr    $0x18,%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a8 <textcolor+0x98>
cmpl   $0x2,-0x8(%rbp)
jne    11a3 <textcolor+0x93>
mov    -0x4(%rbp),%esi
shl    $0x8,%esi
shr    $0x18,%esi
mov    -0x4(%rbp),%edx
shl    $0x10,%edx
shr    $0x18,%edx
mov    -0x4(%rbp),%ecx
shl    $0x18,%ecx
shr    $0x18,%ecx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a8 <textcolor+0x98>
jmp    11ad <textcolor+0x9d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<textcolor>:
mov    %edi,%eax
cmp    $0xffffff,%edi
ja     112b <textcolor+0x1b>
movzbl %al,%esi
lea    0xedc(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    %eax,%ecx
shr    $0x18,%ecx
cmp    $0x2,%cl
je     114b <textcolor+0x3b>
cmp    $0x1,%cl
jne    1167 <textcolor+0x57>
movzbl %al,%esi
lea    0xec3(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%esi
movzbl %ah,%edx
movzbl %al,%ecx
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"\1B[3%dm\00"
@.str.1 = [11 x i8] c"\1B[38;5;%dm\00"
@.str.2 = [17 x i8] c"\1B[38;2;%d;%d;%dm\00"
define void @textcolor(i32 %0) {
%2 = icmp ult i32 %0, 16777216
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = and i32 %0, 255
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %19
6: ; preds = %1
%7 = lshr i32 %0, 24
%8 = trunc i32 %7 to i8
switch i8 %8, label %19 [
i8 1, label %9
i8 2, label %12
]
9: ; preds = %6
%10 = and i32 %0, 255
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %19
12: ; preds = %6
%13 = lshr i32 %0, 16
%14 = and i32 %13, 255
%15 = lshr i32 %0, 8
%16 = and i32 %15, 255
%17 = and i32 %0, 255
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %16, i32 %17)
br label %19
19: ; preds = %6, %9, %12, %3
ret void
}