#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*/ free(char *);
char *replace(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *replaceall(char *str, char *find, char *repl) {
  char *newstr;
  char *tmp;
  tmp = strdup(str);
  newstr = replace(tmp, find, repl);
  while (strcmp(newstr, tmp) != 0) {
    free(tmp);
    tmp = strdup(newstr);
    free(newstr);
    newstr = replace(tmp, find, repl);
  }
  free(tmp);
  return newstr;
}


x86 assembly (clang, -O0):
<replaceall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <replace@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11c6 <replaceall+0x86>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <replace@plt>
mov    %rax,-0x20(%rbp)
jmp    1176 <replaceall+0x36>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceall>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1060 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
nopl   0x0(%rax)
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <replace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcmp@plt>
mov    %r12,%rdi
test   %rax,%rax
je     119e <replaceall+0x5e>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
jmp    1160 <replaceall+0x20>
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @replaceall(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = call i8* @replace(i8* %11, i8* %12, i8* %13)
store i8* %14, i8** %7
br label %15
15: ; preds = %20, %3
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = call i64 @strcmp(i8* %16, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i8*, i8** %8
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %7
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %7
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %8
%28 = load i8*, i8** %5
%29 = load i8*, i8** %6
%30 = call i8* @replace(i8* %27, i8* %28, i8* %29)
store i8* %30, i8** %7
br label %15
31: ; preds = %15
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %7
ret i8* %34
}

LLVM IR (-O2):
define i8* @replaceall(i8* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @replace(i8* %4, i8* %1, i8* %2)
%6 = tail call i64 @strcmp(i8* %5, i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %3, %8
%9 = phi i8* [ %12, %8 ], [ %4, %3 ]
%10 = phi i8* [ %14, %8 ], [ %5, %3 ]
%11 = tail call i32 @free(i8* %9)
%12 = tail call i8* @strdup(i8* %10)
%13 = tail call i32 @free(i8* %10)
%14 = tail call i8* @replace(i8* %12, i8* %1, i8* %2)
%15 = tail call i64 @strcmp(i8* %14, i8* %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %3
%18 = phi i8* [ %5, %3 ], [ %14, %8 ]
%19 = phi i8* [ %4, %3 ], [ %12, %8 ]
%20 = tail call i32 @free(i8* %19)
ret i8* %18
}