#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*/ fileno(int /*<<< orphan*/);
scalar_t__ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *color(int x) {
  if (isatty(fileno(stderr))) {
    switch (x) {
    case -1:
      return "\e[0m";
    case 0:
      return "\e[0;31m";
    case 1:
      return "\e[0;34m";
    case 2:
      return "\e[0;35m";
    case 3:
      return "\e[0;32m";
    case 4:
      return "\e[0;36m";
    case 5:
      return "\e[0;33m";
    }
  } else {
    return "";
  }
}


x86 assembly (clang, -O0):
<color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     11e8 <color+0xc8>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     11e3 <color+0xc3>
mov    -0x18(%rbp),%rax
lea    0xe96(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe97(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe8f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe87(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe7f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe77(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
lea    0xe6f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <color+0xd3>
jmp    11f3 <color+0xd3>
lea    0xe31(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
test   %rax,%rax
je     1155 <color+0x35>
cmp    $0x5,%ebx
ja     115e <color+0x3e>
movslq %ebx,%rax
lea    0xeec(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
pop    %rbx
ret
lea    0xea8(%rip),%rax
pop    %rbx
ret
lea    0xe9b(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [8 x i8] c"\1B[0;31m\00"
@.str.2 = [8 x i8] c"\1B[0;34m\00"
@.str.3 = [8 x i8] c"\1B[0;35m\00"
@.str.4 = [8 x i8] c"\1B[0;32m\00"
@.str.5 = [8 x i8] c"\1B[0;36m\00"
@.str.6 = [8 x i8] c"\1B[0;33m\00"
@.str.7 = [1 x i8] zeroinitializer
define i8* @color(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* @stderr
%5 = call i32 @fileno(i32 %4)
%6 = call i64 @isatty(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i32, i32* %3
switch i32 %9, label %17 [
i32 -1, label %10
i32 0, label %11
i32 1, label %12
i32 2, label %13
i32 3, label %14
i32 4, label %15
i32 5, label %16
]
10: ; preds = %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %19
11: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %19
12: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %19
13: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %19
14: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %19
15: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %19
16: ; preds = %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %19
17: ; preds = %8
br label %19
18: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %19
19: ; preds = %10, %11, %12, %13, %14, %15, %16, %18, %17
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [8 x i8] c"\1B[0;31m\00"
@.str.2 = [8 x i8] c"\1B[0;34m\00"
@.str.3 = [8 x i8] c"\1B[0;35m\00"
@.str.4 = [8 x i8] c"\1B[0;32m\00"
@.str.5 = [8 x i8] c"\1B[0;36m\00"
@.str.6 = [8 x i8] c"\1B[0;33m\00"
@.str.7 = [1 x i8] zeroinitializer
@reltable.color = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.color to i64)) to i32)]
define i8* @color(i32 %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 @fileno(i32 %2)
%4 = tail call i64 @isatty(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = icmp ult i32 %0, 6
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = sext i32 %0 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.color to i8*), i64 %10)
br label %12
12: ; preds = %8, %6, %1
%13 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), %1 ], [ %11, %8 ]
ret i8* %13
}