#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ Q_strncpyz(char *, char *, int);
int /*<<< orphan*/ Scr_AddString(char *);
int /*<<< orphan*/ Scr_Error(char *);
int Scr_GetNumParam();
char *Scr_GetString(int /*<<< orphan*/);
void GScr_StrColorStrip() {
  char buffer[2048];
  if (Scr_GetNumParam() != 1) {
    Scr_Error("Usage: StrColorStrip(<string>)\n");
  }
  char *string = Scr_GetString(0);
  int i;
  Q_strncpyz(buffer, string, sizeof(buffer));
  for (i = 0; buffer[i]; i++) {
    if (buffer[i] == '^' && buffer[i + 1] >= '0' && buffer[i + 1] <= '9') {
      buffer[i + 1] = '7';
    }
  }
  Scr_AddString(buffer);
}


x86 assembly (clang, -O0):
<GScr_StrColorStrip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    $0x0,%al
call   1030 <Scr_GetNumParam@plt>
cmp    $0x1,%eax
je     1177 <GScr_StrColorStrip+0x27>
lea    0xe8e(%rip),%rdi
call   1050 <Scr_Error@plt>
xor    %edi,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,-0x808(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x808(%rbp),%rsi
mov    $0x800,%edx
call   1070 <Q_strncpyz@plt>
movl   $0x0,-0x80c(%rbp)
movslq -0x80c(%rbp),%rax
cmpb   $0x0,-0x800(%rbp,%rax,1)
je     1238 <GScr_StrColorStrip+0xe8>
movslq -0x80c(%rbp),%rax
movsbl -0x800(%rbp,%rax,1),%eax
ff
cmp    $0x5e,%eax
jne    121f <GScr_StrColorStrip+0xcf>
mov    -0x80c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x800(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jl     121f <GScr_StrColorStrip+0xcf>
mov    -0x80c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x800(%rbp,%rax,1),%eax
ff
cmp    $0x39,%eax
jg     121f <GScr_StrColorStrip+0xcf>
mov    -0x80c(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x37,-0x800(%rbp,%rax,1)
37
jmp    1224 <GScr_StrColorStrip+0xd4>
mov    -0x80c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80c(%rbp)
jmp    11a7 <GScr_StrColorStrip+0x57>
lea    -0x800(%rbp),%rdi
call   1060 <Scr_AddString@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GScr_StrColorStrip>:
push   %rbx
sub    $0x800,%rsp
xor    %eax,%eax
call   1030 <Scr_GetNumParam@plt>
cmp    $0x1,%eax
je     1170 <GScr_StrColorStrip+0x20>
lea    0xe95(%rip),%rdi
call   1050 <Scr_Error@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <Scr_GetString@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x800,%edx
call   1070 <Q_strncpyz@plt>
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%eax
cmp    $0x5e,%al
je     11b0 <GScr_StrColorStrip+0x60>
test   %al,%al
je     11c5 <GScr_StrColorStrip+0x75>
add    $0x1,%rbx
jmp    1190 <GScr_StrColorStrip+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x1(%rsp,%rbx,1),%eax
add    $0x1,%rbx
add    $0xd0,%al
cmp    $0x9,%al
ja     1190 <GScr_StrColorStrip+0x40>
movb   $0x37,(%rsp,%rbx,1)
jmp    1190 <GScr_StrColorStrip+0x40>
mov    %rsp,%rdi
call   1060 <Scr_AddString@plt>
add    $0x800,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: StrColorStrip(<string>)\0A\00"
define void @GScr_StrColorStrip() {
%1 = alloca [2048 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = call i32 (...) @Scr_GetNumParam()
%5 = icmp ne i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @Scr_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i8* @Scr_GetString(i32 0)
store i8* %9, i8** %2
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @Q_strncpyz(i8* %10, i8* %11, i32 2048)
store i32 0, i32* %3
br label %13
13: ; preds = %48, %8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %51
19: ; preds = %13
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 94
br i1 %25, label %26, label %47
26: ; preds = %19
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sge i32 %32, 48
br i1 %33, label %34, label %47
34: ; preds = %26
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp sle i32 %40, 57
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %45
store i8 55, i8* %46
br label %47
47: ; preds = %42, %34, %26, %19
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %13
51: ; preds = %13
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%53 = call i32 @Scr_AddString(i8* %52)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Usage: StrColorStrip(<string>)\0A\00"
define void @GScr_StrColorStrip() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @Scr_GetNumParam()
%4 = icmp eq i32 %3, 1
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @Scr_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i8* @Scr_GetString(i32 0)
%9 = call i32 @Q_strncpyz(i8* %2, i8* %8, i32 2048)
br label %10
10: ; preds = %16, %7
%11 = phi i64 [ 0, %7 ], [ %17, %16 ]
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 0, label %25
i8 94, label %18
]
14: ; preds = %10
%15 = add nuw i64 %11, 1
br label %16
16: ; preds = %14, %18, %24
%17 = phi i64 [ %15, %14 ], [ %19, %18 ], [ %19, %24 ]
br label %10
18: ; preds = %10
%19 = add nuw i64 %11, 1
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = add i8 %21, -48
%23 = icmp ult i8 %22, 10
br i1 %23, label %24, label %16
24: ; preds = %18
store i8 55, i8* %20
br label %16
25: ; preds = %10
%26 = call i32 @Scr_AddString(i8* %2)
ret void
}