#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*/ memcpy(char *, char *, int);
int strlen(char *);
char *replace(char *str) {
  static char tmp[255];
  memcpy(tmp, str, (strlen(str) > 255 ? 255 : strlen(str)));
  char *ptr = tmp;
  while (*ptr != 0) {
    if (*ptr == 0x2F)
      *ptr = 0x5C;
    ptr++;
  }
  return tmp;
}


x86 assembly (clang, -O0):
<replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xff,%eax
jle    1155 <replace+0x35>
mov    $0xff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1161 <replace+0x41>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2ed1(%rip),%rdi
call   1040 <memcpy@plt>
lea    0x2ec5(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b7 <replace+0x97>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11a6 <replace+0x86>
mov    -0x10(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117f <replace+0x5f>
lea    0x2e82(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    $0xff,%edx
cmp    $0xff,%eax
jg     1142 <replace+0x22>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
lea    0x2ef7(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
jmp    1167 <replace+0x47>
cs nopw 0x0(%rax,%rax,1)
movb   $0x5c,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     1160 <replace+0x40>
test   %al,%al
jne    1163 <replace+0x43>
lea    0x2ec7(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@replace.tmp = internal global [255 x i8] zeroinitializer
define i8* @replace(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 255
br i1 %7, label %8, label %9
8: ; preds = %1
br label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
br label %12
12: ; preds = %9, %8
%13 = phi i32 [ 255, %8 ], [ %11, %9 ]
%14 = call i32 @memcpy(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0), i8* %4, i32 %13)
store i8* getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0), i8** %3
br label %15
15: ; preds = %27, %12
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i8*, i8** %3
store i8 92, i8* %26
br label %27
27: ; preds = %25, %20
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %15
30: ; preds = %15
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0)
}

LLVM IR (-O2):
@replace.tmp = internal global [255 x i8] zeroinitializer
define i8* @replace(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 255
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
br label %6
6: ; preds = %1, %4
%7 = phi i32 [ %5, %4 ], [ 255, %1 ]
%8 = tail call i32 @memcpy(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0), i8* %0, i32 %7)
br label %9
9: ; preds = %13, %6
%10 = phi i8* [ getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0), %6 ], [ %14, %13 ]
%11 = load i8, i8* %10
switch i8 %11, label %13 [
i8 0, label %15
i8 47, label %12
]
12: ; preds = %9
store i8 92, i8* %10
br label %13
13: ; preds = %9, %12
%14 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
15: ; preds = %9
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @replace.tmp, i64 0, i64 0)
}