#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 */
char *strLeft(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
char *strdup(char *);
scalar_t__ strlen(char *);
char *strReplace(char *str, char FindX, char *ReplaceX) {
  char *tmp, *tmp2, *tmp3;
  tmp = strdup(str);
  tmp2 = strchr(tmp, FindX);
  while (tmp2 != NULL) {
    tmp3 = strLeft(tmp, strlen(tmp) - strlen(tmp2));
    tmp2++;
    tmp = strdup(tmp3);
    strcat(tmp, ReplaceX);
    strcat(tmp, tmp2);
    tmp2 = strchr(tmp, FindX);
  }
  return tmp;
}


x86 assembly (clang, -O0):
<strReplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120a <strReplace+0xba>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdi
sub    %rax,%rsi
call   1050 <strLeft@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
jmp    1184 <strReplace+0x34>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strReplace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
call   1070 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d9 <strReplace+0x89>
mov    %rax,%rbp
movsbl %r15b,%r15d
nopl   (%rax)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
sub    %rax,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <strLeft@plt>
add    $0x1,%rbp
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1180 <strReplace+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strReplace(i8* %0, i8 signext %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = load i8, i8* %5
%14 = call i8* @strchr(i8* %12, i8 signext %13)
store i8* %14, i8** %8
br label %15
15: ; preds = %18, %3
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = load i8*, i8** %7
%21 = call i64 @strlen(i8* %20)
%22 = load i8*, i8** %8
%23 = call i64 @strlen(i8* %22)
%24 = sub nsw i64 %21, %23
%25 = call i8* @strLeft(i8* %19, i64 %24)
store i8* %25, i8** %9
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %8
%28 = load i8*, i8** %9
%29 = call i8* @strdup(i8* %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = load i8*, i8** %6
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %7
%37 = load i8, i8* %5
%38 = call i8* @strchr(i8* %36, i8 signext %37)
store i8* %38, i8** %8
br label %15
39: ; preds = %15
%40 = load i8*, i8** %7
ret i8* %40
}

LLVM IR (-O2):
define i8* @strReplace(i8* nocapture %0, i8 signext %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %15, %7 ], [ %4, %3 ]
%9 = phi i8* [ %18, %7 ], [ %5, %3 ]
%10 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%11 = tail call i64 @strlen(i8* %9)
%12 = sub nsw i64 %10, %11
%13 = tail call i8* @strLeft(i8* %8, i64 %12)
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = tail call i8* @strdup(i8* %13)
%16 = tail call i32 @strcat(i8* %15, i8* %2)
%17 = tail call i32 @strcat(i8* %15, i8* %14)
%18 = tail call i8* @strchr(i8* dereferenceable(1) %15, i8 signext %1)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %7
20: ; preds = %7, %3
%21 = phi i8* [ %4, %3 ], [ %15, %7 ]
ret i8* %21
}