#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void write_to_console(const char *_string, int color, int bold, int flush) {
  if (bold)
    printf("\033[1m");
  switch (color) {
  case 0x1:
    printf("\x1b[31m"
           "%s",
           _string);
    break;
  case 0x2:
    printf("\x1b[34m"
           "%s",
           _string);
    break;
  case 0x4:
    printf("\x1b[32m"
           "%s",
           _string);
    break;
  case 0x1 | 0x2:
    printf("\x1b[35m"
           "%s",
           _string);
    break;
  case 0x1 | 0x4:
    printf("\x1b[33m"
           "%s",
           _string);
    break;
  case 0x4 | 0x2:
    printf("\x1b[36m"
           "%s",
           _string);
    break;
  default:
    printf("%s", _string);
    break;
  }
  printf("\x1b[0m");
  if (flush)
    fflush(stdout);
}


x86 assembly (clang, -O0):
<write_to_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     114d <write_to_console+0x2d>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     1200 <write_to_console+0xe0>
mov    -0x20(%rbp),%rax
lea    0xe93(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <write_to_console+0xf2>
mov    -0x8(%rbp),%rsi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1238 <write_to_console+0x118>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_console>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %edx,%edx
je     113e <write_to_console+0x1e>
lea    0xec9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x5,%ebp
ja     1159 <write_to_console+0x39>
movslq %ebp,%rax
lea    0xeec(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1160 <write_to_console+0x40>
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14d,%r14d
je     118f <write_to_console+0x6f>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fflush@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[1m\00"
@.str.1 = [8 x i8] c"\1B[31m%s\00"
@.str.2 = [8 x i8] c"\1B[34m%s\00"
@.str.3 = [8 x i8] c"\1B[32m%s\00"
@.str.4 = [8 x i8] c"\1B[35m%s\00"
@.str.5 = [8 x i8] c"\1B[33m%s\00"
@.str.6 = [8 x i8] c"\1B[36m%s\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [5 x i8] c"\1B[0m\00"
@stdout = global i32 0
@reltable.write_to_console = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.write_to_console to i64)) to i32)]
define void @write_to_console(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = add i32 %1, -1
%10 = icmp ult i32 %9, 6
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = sext i32 %9 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.write_to_console to i8*), i64 %13)
br label %15
15: ; preds = %8, %11
%16 = phi i8* [ %14, %11 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), %8 ]
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %16, i8* %0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%19 = icmp eq i32 %3, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* @stdout
%22 = tail call i32 @fflush(i32 %21)
br label %23
23: ; preds = %20, %15
ret void
}