#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*/ free(char *);
scalar_t__ isnumber(char);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
void printColor(char *colored) {
  int i = 0;
  while (isnumber(colored[i]) &&
         ((isnumber(colored[i + 1]) && colored[i + 2] == ';') ||
          colored[i + 1] == ';')) {
    if (colored[i + 1] == ';') {
      i += 2;
    } else {
      i += 3;
    }
  }
  colored[i - 1] = 'm';
  printf("%s%s%s", "\x1b[", colored, "\x1b[0m\x1b[K");
  free(colored);
}


x86 assembly (clang, -O0):
<printColor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isnumber@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
je     11c5 <printColor+0x95>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isnumber@plt>
cmp    $0x0,%rax
je     11a5 <printColor+0x75>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x3b,%ecx
mov    %al,-0xe(%rbp)
je     11bf <printColor+0x8f>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3b,%eax
sete   %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11d5 <printColor+0xa5>
jmp    120b <printColor+0xdb>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3b,%eax
jne    11fd <printColor+0xcd>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    1206 <printColor+0xd6>
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <printColor+0x13>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x6d,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdx
lea    0xdd9(%rip),%rdi
lea    0xdd9(%rip),%rsi
lea    0xdd5(%rip),%rcx
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printColor>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1050 <isnumber@plt>
xor    %ebp,%ebp
jmp    116e <printColor+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x3b,0x1(%r14,%rbx,1)
jne    119c <printColor+0x6c>
mov    $0x2,%eax
mov    %eax,%eax
add    %rax,%rbx
movsbl (%r14,%rbx,1),%edi
call   1050 <isnumber@plt>
mov    %ebx,%ebp
test   %rax,%rax
je     119c <printColor+0x6c>
mov    %ebp,%ebx
movsbl 0x1(%rbx,%r14,1),%edi
call   1050 <isnumber@plt>
test   %rax,%rax
je     1150 <printColor+0x20>
cmpb   $0x3b,0x2(%rbx,%r14,1)
jne    1150 <printColor+0x20>
mov    $0x3,%eax
cmpb   $0x3b,0x1(%r14,%rbx,1)
je     1158 <printColor+0x28>
jmp    115d <printColor+0x2d>
movslq %ebp,%rax
movb   $0x6d,-0x1(%rax,%r14,1)
lea    0xe54(%rip),%rdi
lea    0xe54(%rip),%rsi
lea    0xe50(%rip),%rcx
mov    %r14,%rdx
call   1040 <printf@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [3 x i8] c"\1B[\00"
@.str.2 = [8 x i8] c"\1B[0m\1B[K\00"
define void @printColor(i8* %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @isnumber(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %34, label %5
5: ; preds = %1, %26
%6 = phi i32 [ %28, %26 ], [ 0, %1 ]
%7 = add nuw nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @isnumber(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %5
%14 = add nuw nsw i32 %6, 2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 59
br i1 %18, label %22, label %19
19: ; preds = %13, %5
%20 = load i8, i8* %9
%21 = icmp eq i8 %20, 59
br i1 %21, label %25, label %34
22: ; preds = %13
%23 = load i8, i8* %9
%24 = icmp eq i8 %23, 59
br i1 %24, label %25, label %26
25: ; preds = %19, %22
br label %26
26: ; preds = %22, %25
%27 = phi i32 [ 2, %25 ], [ 3, %22 ]
%28 = add nuw nsw i32 %27, %6
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = tail call i64 @isnumber(i8 signext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %5
34: ; preds = %19, %26, %1
%35 = phi i32 [ 0, %1 ], [ %28, %26 ], [ %6, %19 ]
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
store i8 109, i8* %38
%39 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%40 = tail call i32 @free(i8* %0)
ret void
}