#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 *, int);
int reduce8(unsigned char const, unsigned char const, unsigned char const);
void render_ansi(const unsigned char *c, const unsigned char *d) {
  int fg = 0;
  int color = reduce8(c[0], c[1], c[2]);
  if (color == -1)
    return;
  printf("\x1b[%dm", color + (fg ? 30 : 40));
}


x86 assembly (clang, -O0):
<render_ansi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x8(%rbp),%rax
movzbl %dl,%edi
movzbl %cl,%esi
movzbl 0x2(%rax),%edx
call   1040 <reduce8@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1169 <render_ansi+0x49>
jmp    118d <render_ansi+0x6d>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x28,%eax
mov    $0x1e,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    %eax,%esi
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<render_ansi>:
push   %rax
movzbl (%rdi),%eax
movzbl 0x1(%rdi),%esi
movzbl 0x2(%rdi),%edx
mov    %eax,%edi
call   1040 <reduce8@plt>
cmp    $0xffffffff,%eax
je     114a <render_ansi+0x2a>
add    $0x28,%eax
lea    0xebe(%rip),%rdi
mov    %eax,%esi
pop    %rax
jmp    1030 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\1B[%dm\00"
define void @render_ansi(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = call i32 @reduce8(i8 zeroext %9, i8 zeroext %12, i8 zeroext %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %2
br label %28
20: ; preds = %2
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 30, i32 40
%26 = add nsw i32 %21, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %20, %19
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\1B[%dm\00"
define void @render_ansi(i8* nocapture %0, i8* nocapture readnone %1) {
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = tail call i32 @reduce8(i8 zeroext %3, i8 zeroext %5, i8 zeroext %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = add nsw i32 %8, 40
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %2, %10
ret void
}