#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 strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
char *str_replace(char *orig, char *rep, char *with) {
  int len_orig;
  int len_rep;
  int len_with;
  int count;
  if (!orig)
    return NULL;
  if (strstr(orig, rep) != NULL) {
    if (!rep) {
      rep = "";
    }
    if (!with) {
      with = "";
    }
    len_rep = strlen(rep);
    len_with = strlen(with);
    len_orig = strlen(orig);
    for (int i = 0; i < len_orig; i++) {
    }
  } else {
    return orig;
  }
  return orig;
}


x86 assembly (clang, -O0):
<str_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <str_replace+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <str_replace+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     11de <str_replace+0xbe>
cmpq   $0x0,-0x18(%rbp)
jne    1179 <str_replace+0x59>
lea    0xe8b(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <str_replace+0x6f>
lea    0xe75(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d9 <str_replace+0xb9>
jmp    11cb <str_replace+0xab>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <str_replace+0x9a>
jmp    11eb <str_replace+0xcb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f3 <str_replace+0xd3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_replace>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     116d <str_replace+0x4d>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rbx,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     116d <str_replace+0x4d>
test   %r15,%r15
lea    0xeb6(%rip),%rax
cmove  %rax,%r15
test   %r14,%r14
cmove  %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @str_replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store i8* null, i8** %4
br label %49
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32* @strstr(i8* %17, i8* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %45
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %21
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %25
25: ; preds = %24, %21
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %25
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
br label %29
29: ; preds = %28, %25
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %9
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %10
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %8
store i32 0, i32* %12
br label %36
36: ; preds = %41, %29
%37 = load i32, i32* %12
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %36
br label %41
41: ; preds = %40
%42 = load i32, i32* %12
%43 = add nsw i32 %42, 1
store i32 %43, i32* %12
br label %36
44: ; preds = %36
br label %47
45: ; preds = %16
%46 = load i8*, i8** %5
store i8* %46, i8** %4
br label %49
47: ; preds = %44
%48 = load i8*, i8** %5
store i8* %48, i8** %4
br label %49
49: ; preds = %47, %45, %15
%50 = load i8*, i8** %4
ret i8* %50
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @str_replace(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i32* @strstr(i8* %0, i8* dereferenceable(1) %1)
%7 = icmp eq i32* %6, null
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = icmp eq i8* %1, null
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%11 = icmp eq i8* %2, null
%12 = select i1 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %2
%13 = tail call i32 @strlen(i8* %10)
%14 = tail call i32 @strlen(i8* %12)
%15 = tail call i32 @strlen(i8* %0)
br label %16
16: ; preds = %8, %5, %3
ret i8* %0
}