#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*/ changeLengthString(char *, int, int, int);
scalar_t__ isSourceInStr(char *, char *, int);
int len(char *);
int /*<<< orphan*/ putTargetToStr(char *, char *, int);
void replaceStr(char *str, char *source, char *target) {
  for (int i = 0; i < len(str) - len(source); i++)
    if (isSourceInStr(str, source, i)) {
      changeLengthString(str, len(source), len(target), i);
      putTargetToStr(str, target, i);
    }
}


x86 assembly (clang, -O0):
<replaceStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <len@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <len@plt>
mov    -0x24(%rbp),%ecx
mov    %eax,%edx
mov    -0x20(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11f3 <replaceStr+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <isSourceInStr@plt>
cmp    $0x0,%rax
je     11e0 <replaceStr+0xa0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <len@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <len@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
call   1060 <changeLengthString@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <putTargetToStr@plt>
jmp    11e5 <replaceStr+0xa5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <replaceStr+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceStr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <len@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <len@plt>
cmp    %eax,%ebp
jle    11cc <replaceStr+0x8c>
xor    %ebp,%ebp
jmp    118b <replaceStr+0x4b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r12,%rdi
call   1040 <len@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <len@plt>
sub    %eax,%ebx
cmp    %ebx,%ebp
jge    11cc <replaceStr+0x8c>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <isSourceInStr@plt>
test   %rax,%rax
je     1170 <replaceStr+0x30>
mov    %r15,%rdi
call   1040 <len@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <len@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %ebp,%ecx
call   1060 <changeLengthString@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <putTargetToStr@plt>
jmp    1170 <replaceStr+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @replaceStr(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %35, %3
%9 = load i32, i32* %7
%10 = load i8*, i8** %4
%11 = call i32 @len(i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @len(i8* %12)
%14 = sub nsw i32 %11, %13
%15 = icmp slt i32 %9, %14
br i1 %15, label %16, label %38
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = call i64 @isSourceInStr(i8* %17, i8* %18, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = call i32 @len(i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @len(i8* %26)
%28 = load i32, i32* %7
%29 = call i32 @changeLengthString(i8* %23, i32 %25, i32 %27, i32 %28)
%30 = load i8*, i8** %4
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @putTargetToStr(i8* %30, i8* %31, i32 %32)
br label %34
34: ; preds = %22, %16
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %8
38: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @replaceStr(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @len(i8* %0)
%5 = tail call i32 @len(i8* %1)
%6 = icmp sgt i32 %4, %5
br i1 %6, label %8, label %7
7: ; preds = %17, %3
ret void
8: ; preds = %3, %17
%9 = phi i32 [ %18, %17 ], [ 0, %3 ]
%10 = tail call i64 @isSourceInStr(i8* %0, i8* %1, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = tail call i32 @len(i8* %1)
%14 = tail call i32 @len(i8* %2)
%15 = tail call i32 @changeLengthString(i8* %0, i32 %13, i32 %14, i32 %9)
%16 = tail call i32 @putTargetToStr(i8* %0, i8* %2, i32 %9)
br label %17
17: ; preds = %8, %12
%18 = add nuw nsw i32 %9, 1
%19 = tail call i32 @len(i8* %0)
%20 = tail call i32 @len(i8* %1)
%21 = sub nsw i32 %19, %20
%22 = icmp slt i32 %18, %21
br i1 %22, label %8, label %7
}