#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 *mystrreplace(char *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void test4() {
  char a[6];
  char *from = "pp";
  char *to = "orange";
  strcpy(a, "apple");
  printf("original=<%s>\n", a);
  printf("from=<%s>\n", from);
  printf("to=<%s>\n", to);
  char *b = mystrreplace(a, from, to);
  printf("replace=<b=%s>\n", b);
  char *s = "Dear friend, We thank you friend for your present.\n"
            "We hope to see you friend in our next party.\n"
            "Sincerely yours.\n";
  from = "friend";
  to = "George";
  printf("original=%s\n", s);
  printf("from=<%s>\n", from);
  printf("to=<%s>\n", to);
  char *result = mystrreplace(s, from, to);
  printf("result=<%s>\n", result);
  s = "aaa bbbbb a bbbbaa bbb vvv bb fff b";
  from = "bb";
  to = " xxx ";
  printf("original=%s\n", s);
  printf("from=<%s>\n", from);
  printf("to=<%s>\n", to);
  result = mystrreplace(s, from, to);
  printf("result=<%s>\n", result);
}


x86 assembly (clang, -O0):
<test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x6(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x6(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    -0x6(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <mystrreplace@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
lea    0xe89(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xef0(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeec(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <mystrreplace@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
lea    0xead(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdb5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <mystrreplace@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xec8(%rip),%rsi
lea    0x2(%rsp),%r13
mov    %r13,%rdi
call   1030 <strcpy@plt>
lea    0xeba(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
lea    0xeba(%rip),%rbp
lea    0xe94(%rip),%r12
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
lea    0xeac(%rip),%r15
lea    0xe7e(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <mystrreplace@plt>
lea    0xe8e(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xf0f(%rip),%r12
lea    0xe88(%rip),%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
lea    0xee8(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xedd(%rip),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <mystrreplace@plt>
lea    0xed1(%rip),%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xecc(%rip),%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xede(%rip),%rbx
lea    0xdf5(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xecb(%rip),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <mystrreplace@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"pp\00"
@.str.1 = [7 x i8] c"orange\00"
@.str.2 = [6 x i8] c"apple\00"
@.str.3 = [15 x i8] c"original=<%s>\0A\00"
@.str.4 = [11 x i8] c"from=<%s>\0A\00"
@.str.5 = [9 x i8] c"to=<%s>\0A\00"
@.str.6 = [16 x i8] c"replace=<b=%s>\0A\00"
@.str.7 = [114 x i8] c"Dear friend, We thank you friend for your present.\0AWe hope to see you friend in our next party.\0ASincerely yours.\0A\00"
@.str.8 = [7 x i8] c"friend\00"
@.str.9 = [7 x i8] c"George\00"
@.str.10 = [13 x i8] c"original=%s\0A\00"
@.str.11 = [13 x i8] c"result=<%s>\0A\00"
@.str.12 = [36 x i8] c"aaa bbbbb a bbbbaa bbb vvv bb fff b\00"
@.str.13 = [3 x i8] c"bb\00"
@.str.14 = [6 x i8] c" xxx \00"
define void @test4() {
%1 = alloca [6 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %3
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
%12 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = load i8*, i8** %3
%18 = call i8* @mystrreplace(i8* %15, i8* %16, i8* %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %19)
store i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.7, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8** %3
%21 = load i8*, i8** %5
%22 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %5
%28 = load i8*, i8** %2
%29 = load i8*, i8** %3
%30 = call i8* @mystrreplace(i8* %27, i8* %28, i8* %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %31)
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0), i8** %3
%33 = load i8*, i8** %5
%34 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %2
%36 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %3
%38 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %5
%40 = load i8*, i8** %2
%41 = load i8*, i8** %3
%42 = call i8* @mystrreplace(i8* %39, i8* %40, i8* %41)
store i8* %42, i8** %6
%43 = load i8*, i8** %6
%44 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %43)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"pp\00"
@.str.1 = [7 x i8] c"orange\00"
@.str.2 = [6 x i8] c"apple\00"
@.str.3 = [15 x i8] c"original=<%s>\0A\00"
@.str.4 = [11 x i8] c"from=<%s>\0A\00"
@.str.5 = [9 x i8] c"to=<%s>\0A\00"
@.str.6 = [16 x i8] c"replace=<b=%s>\0A\00"
@.str.7 = [114 x i8] c"Dear friend, We thank you friend for your present.\0AWe hope to see you friend in our next party.\0ASincerely yours.\0A\00"
@.str.8 = [7 x i8] c"friend\00"
@.str.9 = [7 x i8] c"George\00"
@.str.10 = [13 x i8] c"original=%s\0A\00"
@.str.11 = [13 x i8] c"result=<%s>\0A\00"
@.str.12 = [36 x i8] c"aaa bbbbb a bbbbaa bbb vvv bb fff b\00"
@.str.13 = [3 x i8] c"bb\00"
@.str.14 = [6 x i8] c" xxx \00"
define void @test4() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%5 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = call i8* @mystrreplace(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.7, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%12 = call i8* @mystrreplace(i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
%17 = call i8* @mystrreplace(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %17)
ret void
}