#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 char *pch_src;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char const *);
void G_CleanPlayerName(const char *source, char *dest) {
  const char *pch_src = source;
  char *pch_dst = dest;
  int count = strlen(pch_src);
  memset(pch_dst, 0, 32);
  while (count > 0) {
    if ((pch_src && *(pch_src) == '^' && *((pch_src) + 1) &&
         *((pch_src) + 1) != '^')) {
      pch_src += 2;
      count -= 2;
    } else {
      *pch_dst++ = *pch_src | 0x80;
      ++pch_src;
      --count;
    }
  }
}


x86 assembly (clang, -O0):
<G_CleanPlayerName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
cmpl   $0x0,-0x24(%rbp)
jle    11f6 <G_CleanPlayerName+0xd6>
cmpq   $0x0,-0x18(%rbp)
je     11bd <G_CleanPlayerName+0x9d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5e,%eax
jne    11bd <G_CleanPlayerName+0x9d>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11bd <G_CleanPlayerName+0x9d>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x5e,%eax
je     11bd <G_CleanPlayerName+0x9d>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    11f1 <G_CleanPlayerName+0xd1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
or     $0x80,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    115c <G_CleanPlayerName+0x3c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<G_CleanPlayerName>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
test   %ebp,%ebp
jg     116a <G_CleanPlayerName+0x4a>
pop    %rbx
pop    %r14
pop    %rbp
ret
nopl   0x0(%rax)
or     $0x80,%al
mov    %al,(%r14)
add    $0x1,%r14
mov    $0xffffffff,%eax
mov    $0x1,%ecx
add    %rcx,%rbx
add    %eax,%ebp
jle    1144 <G_CleanPlayerName+0x24>
test   %rbx,%rbx
je     1150 <G_CleanPlayerName+0x30>
movzbl (%rbx),%eax
cmp    $0x5e,%al
jne    1150 <G_CleanPlayerName+0x30>
movzbl 0x1(%rbx),%ecx
mov    $0x5e,%al
cmp    $0x5e,%cl
je     1150 <G_CleanPlayerName+0x30>
test   %cl,%cl
je     1150 <G_CleanPlayerName+0x30>
mov    $0xfffffffe,%eax
mov    $0x2,%ecx
jmp    1163 <G_CleanPlayerName+0x43>

LLVM IR (-O0):
define void @G_CleanPlayerName(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %6
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %6
%13 = call i32 @memset(i8* %12, i32 0, i32 32)
br label %14
14: ; preds = %54, %2
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %55
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %42
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 94
br i1 %24, label %25, label %42
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 94
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 2
store i8* %39, i8** %5
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, 2
store i32 %41, i32* %7
br label %54
42: ; preds = %31, %25, %20, %17
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = or i32 %45, 128
%47 = trunc i32 %46 to i8
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %6
store i8 %47, i8* %48
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
%52 = load i32, i32* %7
%53 = add nsw i32 %52, -1
store i32 %53, i32* %7
br label %54
54: ; preds = %42, %37
br label %14
55: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @G_CleanPlayerName(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @memset(i8* %1, i32 0, i32 32)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %28
6: ; preds = %2, %21
%7 = phi i32 [ %26, %21 ], [ %3, %2 ]
%8 = phi i8* [ %24, %21 ], [ %1, %2 ]
%9 = phi i8* [ %25, %21 ], [ %0, %2 ]
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 94
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = load i8, i8* %15
switch i8 %16, label %21 [
i8 0, label %17
i8 94, label %17
]
17: ; preds = %6, %14, %14, %11
%18 = phi i8 [ 94, %14 ], [ 94, %14 ], [ %12, %11 ], [ undef, %6 ]
%19 = or i8 %18, -128
%20 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %19, i8* %8
br label %21
21: ; preds = %14, %17
%22 = phi i64 [ 1, %17 ], [ 2, %14 ]
%23 = phi i32 [ -1, %17 ], [ -2, %14 ]
%24 = phi i8* [ %20, %17 ], [ %8, %14 ]
%25 = getelementptr inbounds i8, i8* %9, i64 %22
%26 = add nsw i32 %7, %23
%27 = icmp sgt i32 %26, 0
br i1 %27, label %6, label %28
28: ; preds = %21, %2
ret void
}