#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*/ printf(char *, char *, char *, char *, char *,
                          int /*<<< orphan*/);
char *str_replace(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
void test_str_replace() {
  char *data[14][3] = {{"Simple file", "", "*/?$"},
                       {"Simple file a file 2 of file me", "", "_"},
                       {"Simple file a file 2 of file me", "ZZZ", ""},
                       {"Simple", "ZZ", "AA"},
                       {"Simple file a file 2 of file me", "!!", "AAA"},
                       {"exmaeEeple", "e", "!"},
                       {"", "", ""},
                       {"''''''", "'", "\""},
                       {"TXTSS", "", "????"},
                       {"", "Z", "AAA"},
                       {" 1  2   3    4   ", "   ", "*"},
                       {"Simple file a file 2 of file me", "file", "dir"},
                       {"Simple file a file 2 of file me", "file", ""},
                       {"Simple file a file 2 of file me", "", ""}};
  char *str;
  for (unsigned int i = 0; i < 14; ++i) {
    str = str_replace(data[i][0], data[i][1], data[i][2]);
    printf("%s | \"%s\" --> \"%s\" | %s %li\n", data[i][0], data[i][1],
           data[i][2], str, strlen(str));
  }
}


x86 assembly (clang, -O0):
<test_str_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
lea    -0x150(%rbp),%rdi
lea    0x2b77(%rip),%rsi
mov    $0x150,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x15c(%rbp)
cmpl   $0xe,-0x15c(%rbp)
jae    128e <test_str_replace+0x14e>
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rdi
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rsi
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%rdx
call   1050 <str_replace@plt>
mov    %rax,-0x158(%rbp)
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x180(%rbp)
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x178(%rbp)
mov    -0x15c(%rbp),%eax
mov    %eax,%ecx
lea    -0x150(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%rax
mov    %rax,-0x170(%rbp)
mov    -0x158(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x158(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x180(%rbp),%rsi
mov    -0x178(%rbp),%rdx
mov    -0x170(%rbp),%rcx
mov    -0x168(%rbp),%r8
mov    %eax,%r9d
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
mov    -0x15c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15c(%rbp)
jmp    116d <test_str_replace+0x2d>
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x10,%ebp
lea    0x2b89(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    -0x10(%rbp,%r14,1),%r13
mov    -0x8(%rbp,%r14,1),%r15
mov    0x0(%rbp,%r14,1),%r12
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <str_replace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
lea    0xefd(%rip),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
call   1040 <printf@plt>
add    $0x18,%rbp
cmp    $0x160,%rbp
jne    1150 <test_str_replace+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Simple file\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"*/?$\00"
@.str.3 = [32 x i8] c"Simple file a file 2 of file me\00"
@.str.4 = [2 x i8] c"_\00"
@.str.5 = [4 x i8] c"ZZZ\00"
@.str.6 = [7 x i8] c"Simple\00"
@.str.7 = [3 x i8] c"ZZ\00"
@.str.8 = [3 x i8] c"AA\00"
@.str.9 = [3 x i8] c"!!\00"
@.str.10 = [4 x i8] c"AAA\00"
@.str.11 = [11 x i8] c"exmaeEeple\00"
@.str.12 = [2 x i8] c"e\00"
@.str.13 = [2 x i8] c"!\00"
@.str.14 = [7 x i8] c"''''''\00"
@.str.15 = [2 x i8] c"'\00"
@.str.16 = [2 x i8] c"\22\00"
@.str.17 = [6 x i8] c"TXTSS\00"
@.str.18 = [5 x i8] c"????\00"
@.str.19 = [2 x i8] c"Z\00"
@.str.20 = [18 x i8] c" 1 2 3 4 \00"
@.str.21 = [4 x i8] c" \00"
@.str.22 = [2 x i8] c"*\00"
@.str.23 = [5 x i8] c"file\00"
@.str.24 = [4 x i8] c"dir\00"
@__const.test_str_replace.data = [14 x [3 x i8*]] [[3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.22, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.24, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)]]
@.str.25 = [29 x i8] c"%s | \22%s\22 --> \22%s\22 | %s %li\0A\00"
define void @test_str_replace() {
%1 = alloca [14 x [3 x i8*]]
%2 = alloca i8*
%3 = alloca i32
%4 = bitcast [14 x [3 x i8*]]* %1 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %44, %0
%6 = load i32, i32* %3
%7 = icmp ult i32 %6, 14
br i1 %7, label %8, label %47
8: ; preds = %5
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %10
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %11, i64 0, i64 0
%13 = load i8*, i8** %12
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %15
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %16, i64 0, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %20
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %21, i64 0, i64 2
%23 = load i8*, i8** %22
%24 = call i8* @str_replace(i8* %13, i8* %18, i8* %23)
store i8* %24, i8** %2
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %26
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %27, i64 0, i64 0
%29 = load i8*, i8** %28
%30 = load i32, i32* %3
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %31
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %32, i64 0, i64 1
%34 = load i8*, i8** %33
%35 = load i32, i32* %3
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* %1, i64 0, i64 %36
%38 = getelementptr inbounds [3 x i8*], [3 x i8*]* %37, i64 0, i64 2
%39 = load i8*, i8** %38
%40 = load i8*, i8** %2
%41 = load i8*, i8** %2
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.25, i64 0, i64 0), i8* %29, i8* %34, i8* %39, i8* %40, i32 %42)
br label %44
44: ; preds = %8
%45 = load i32, i32* %3
%46 = add i32 %45, 1
store i32 %46, i32* %3
br label %5
47: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Simple file\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"*/?$\00"
@.str.3 = [32 x i8] c"Simple file a file 2 of file me\00"
@.str.4 = [2 x i8] c"_\00"
@.str.5 = [4 x i8] c"ZZZ\00"
@.str.6 = [7 x i8] c"Simple\00"
@.str.7 = [3 x i8] c"ZZ\00"
@.str.8 = [3 x i8] c"AA\00"
@.str.9 = [3 x i8] c"!!\00"
@.str.10 = [4 x i8] c"AAA\00"
@.str.11 = [11 x i8] c"exmaeEeple\00"
@.str.12 = [2 x i8] c"e\00"
@.str.13 = [2 x i8] c"!\00"
@.str.14 = [7 x i8] c"''''''\00"
@.str.15 = [2 x i8] c"'\00"
@.str.16 = [2 x i8] c"\22\00"
@.str.17 = [6 x i8] c"TXTSS\00"
@.str.18 = [5 x i8] c"????\00"
@.str.19 = [2 x i8] c"Z\00"
@.str.20 = [18 x i8] c" 1 2 3 4 \00"
@.str.21 = [4 x i8] c" \00"
@.str.22 = [2 x i8] c"*\00"
@.str.23 = [5 x i8] c"file\00"
@.str.24 = [4 x i8] c"dir\00"
@__const.test_str_replace.data = [14 x [3 x i8*]] [[3 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.22, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.24, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)], [3 x i8*] [i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)]]
@.str.25 = [29 x i8] c"%s | \22%s\22 --> \22%s\22 | %s %li\0A\00"
define void @test_str_replace() {
br label %2
1: ; preds = %2
ret void
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %13, %2 ]
%4 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* @__const.test_str_replace.data, i64 0, i64 %3, i64 0
%5 = load i8*, i8** %4
%6 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* @__const.test_str_replace.data, i64 0, i64 %3, i64 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds [14 x [3 x i8*]], [14 x [3 x i8*]]* @__const.test_str_replace.data, i64 0, i64 %3, i64 2
%9 = load i8*, i8** %8
%10 = tail call i8* @str_replace(i8* %5, i8* %7, i8* %9)
%11 = tail call i32 @strlen(i8* %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.25, i64 0, i64 0), i8* %5, i8* %7, i8* %9, i8* %10, i32 %11)
%13 = add nuw nsw i64 %3, 1
%14 = icmp eq i64 %13, 14
br i1 %14, label %1, label %2
}