#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 *);
char *replace(char *, char *, char *);
char *strip_colors(const char *str) {
  char *next, *current;
  current = str;
  next = replace(current,
                 "\x1b["
                 "0m",
                 "");
  current = next;
  next = replace(current,
                 "\x1b["
                 "30m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "31;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "32;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "33;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "34;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "35;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "36;1m",
                 "");
  free(current);
  current = next;
  next = replace(current,
                 "\x1b["
                 "37;1m",
                 "");
  free(current);
  current = next;
  return next;
}


x86 assembly (clang, -O0):
<strip_colors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec1(%rip),%rsi
lea    0xec4(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea3(%rip),%rsi
lea    0xea1(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    0xe75(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
lea    0xe49(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe35(%rip),%rsi
lea    0xe1d(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    0xdf1(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xded(%rip),%rsi
lea    0xdc5(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdc9(%rip),%rsi
lea    0xd99(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xda5(%rip),%rsi
lea    0xd6d(%rip),%rdx
call   1040 <replace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_colors>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%rsi
lea    0xed7(%rip),%r14
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xea9(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe7f(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe55(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe2b(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <replace@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"\1B[30m\00"
@.str.3 = [8 x i8] c"\1B[31;1m\00"
@.str.4 = [8 x i8] c"\1B[32;1m\00"
@.str.5 = [8 x i8] c"\1B[33;1m\00"
@.str.6 = [8 x i8] c"\1B[34;1m\00"
@.str.7 = [8 x i8] c"\1B[35;1m\00"
@.str.8 = [8 x i8] c"\1B[36;1m\00"
@.str.9 = [8 x i8] c"\1B[37;1m\00"
define i8* @strip_colors(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = call i8* @replace(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i8* @replace(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
%13 = load i8*, i8** %3
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i8* @replace(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %3
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = call i8* @replace(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %20, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %3
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = call i8* @replace(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %25, i8** %3
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %3
store i8* %28, i8** %4
%29 = load i8*, i8** %4
%30 = call i8* @replace(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %3
store i8* %33, i8** %4
%34 = load i8*, i8** %4
%35 = call i8* @replace(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %35, i8** %3
%36 = load i8*, i8** %4
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %3
store i8* %38, i8** %4
%39 = load i8*, i8** %4
%40 = call i8* @replace(i8* %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %3
%41 = load i8*, i8** %4
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %3
store i8* %43, i8** %4
%44 = load i8*, i8** %4
%45 = call i8* @replace(i8* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %45, i8** %3
%46 = load i8*, i8** %4
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %3
store i8* %48, i8** %4
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [6 x i8] c"\1B[30m\00"
@.str.3 = [8 x i8] c"\1B[31;1m\00"
@.str.4 = [8 x i8] c"\1B[32;1m\00"
@.str.5 = [8 x i8] c"\1B[33;1m\00"
@.str.6 = [8 x i8] c"\1B[34;1m\00"
@.str.7 = [8 x i8] c"\1B[35;1m\00"
@.str.8 = [8 x i8] c"\1B[36;1m\00"
@.str.9 = [8 x i8] c"\1B[37;1m\00"
define i8* @strip_colors(i8* %0) {
%2 = tail call i8* @replace(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @replace(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @free(i8* %2)
%5 = tail call i8* @replace(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @free(i8* %3)
%7 = tail call i8* @replace(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @free(i8* %5)
%9 = tail call i8* @replace(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @free(i8* %7)
%11 = tail call i8* @replace(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @free(i8* %9)
%13 = tail call i8* @replace(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @free(i8* %11)
%15 = tail call i8* @replace(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @free(i8* %13)
%17 = tail call i8* @replace(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @free(i8* %15)
ret i8* %17
}