#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, char);
int strlen(char *);
void colorize(char *string) {
  int i, n;
  for (i = 0, n = 0; i < strlen(string); i++, n++) {
    if (i == (strlen(string) - 1))
      printf("\e[%d;3%dm%c\e[0m", ((n < 8) ? 0 : 1), ((n < 8) ? n : (n - 7)),
             string[i]);
    else
      printf("\e[%d;3%dm%c", ((n < 8) ? 0 : 1), ((n < 8) ? n : (n - 7)),
             string[i]);
    if (n == 14)
      n -= 14;
  }
}


x86 assembly (clang, -O0):
<colorize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1247 <colorize+0x127>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11c9 <colorize+0xa9>
mov    -0x10(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x8,%edx
cmovl  %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    119d <colorize+0x7d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11a6 <colorize+0x86>
mov    -0x10(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xe45(%rip),%rdi
movsbl (%rax,%rcx,1),%ecx
call   1040 <printf@plt>
jmp    1218 <colorize+0xf8>
mov    -0x10(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x8,%edx
cmovl  %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11f1 <colorize+0xd1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11fa <colorize+0xda>
mov    -0x10(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xe01(%rip),%rdi
movsbl (%rax,%rcx,1),%ecx
call   1040 <printf@plt>
cmpl   $0xe,-0x10(%rbp)
jne    122b <colorize+0x10b>
mov    -0x10(%rbp),%eax
sub    $0xe,%eax
mov    %eax,-0x10(%rbp)
jmp    1230 <colorize+0x110>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <colorize+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colorize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a6 <colorize+0x86>
xor    %ebx,%ebx
lea    0xed0(%rip),%r12
mov    $0x1,%r13d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
lea    -0x7(%rbp),%edx
xor    %esi,%esi
cmp    $0x8,%ebp
setge  %sil
cmovl  %ebp,%edx
cmp    %rax,%rbx
movsbl (%r14,%rbx,1),%ecx
mov    %r12,%rdi
lea    0xe84(%rip),%rax
cmove  %rax,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
lea    0x1(%rbp),%r15d
cmp    $0xe,%ebp
cmove  %r13d,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
mov    %r15d,%ebp
cmp    %rax,%rbx
jl     1150 <colorize+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"\1B[%d;3%dm%c\1B[0m\00"
@.str.1 = [12 x i8] c"\1B[%d;3%dm%c\00"
define void @colorize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %63, %1
%6 = load i32, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %68
10: ; preds = %5
%11 = load i32, i32* %3
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = icmp eq i32 %11, %14
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 8
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 0, i32 1
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = load i32, i32* %4
br label %28
25: ; preds = %16
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 7
br label %28
28: ; preds = %25, %23
%29 = phi i32 [ %24, %23 ], [ %27, %25 ]
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %29, i8 signext %34)
br label %56
36: ; preds = %10
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 8
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 0, i32 1
%41 = load i32, i32* %4
%42 = icmp slt i32 %41, 8
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = load i32, i32* %4
br label %48
45: ; preds = %36
%46 = load i32, i32* %4
%47 = sub nsw i32 %46, 7
br label %48
48: ; preds = %45, %43
%49 = phi i32 [ %44, %43 ], [ %47, %45 ]
%50 = load i8*, i8** %2
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %49, i8 signext %54)
br label %56
56: ; preds = %48, %28
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 14
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %4
%61 = sub nsw i32 %60, 14
store i32 %61, i32* %4
br label %62
62: ; preds = %59, %56
br label %63
63: ; preds = %62
%64 = load i32, i32* %3
%65 = add nsw i32 %64, 1
store i32 %65, i32* %3
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
br label %5
68: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"\1B[%d;3%dm%c\1B[0m\00"
@.str.1 = [12 x i8] c"\1B[%d;3%dm%c\00"
define void @colorize(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %1, %4
%5 = phi i64 [ %21, %4 ], [ 0, %1 ]
%6 = phi i32 [ %23, %4 ], [ 0, %1 ]
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = zext i32 %8 to i64
%10 = icmp eq i64 %5, %9
%11 = icmp slt i32 %6, 8
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
%14 = add nsw i32 %6, -7
%15 = select i1 %11, i32 %6, i32 %14
%16 = getelementptr inbounds i8, i8* %0, i64 %5
%17 = load i8, i8* %16
%18 = select i1 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%19 = tail call i32 @printf(i8* %18, i32 %13, i32 %15, i8 signext %17)
%20 = icmp eq i32 %6, 14
%21 = add nuw nsw i64 %5, 1
%22 = add nsw i32 %6, 1
%23 = select i1 %20, i32 1, i32 %22
%24 = tail call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %21, %25
br i1 %26, label %4, label %27
27: ; preds = %4, %1
ret void
}