#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 find_string(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace_string(char *, char *, char *);
int main(void) {
  int loop;
  char text1[81] = "derp de derp de derp de derp";
  char text2[81] = "abcabcabcabc";
  char text3[81] = "123";
  printf("%s\n", text1);
  do {
    loop = find_string(text1, "derp");
    replace_string(text1, "derp", "herp");
  } while (loop != -1);
  printf("%s\n", text1);
  printf("%s\n", text2);
  do {
    loop = find_string(text2, "abc");
    replace_string(text2, "abc", "def");
  } while (loop != -1);
  printf("%s\n", text2);
  printf("%s\n", text3);
  do {
    loop = find_string(text3, "123");
    replace_string(text3, "123", "456");
  } while (loop != -1);
  printf("%s\n", text3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x51,%edx
call   1060 <memcpy@plt>
lea    -0xc0(%rbp),%rdi
lea    0xedb(%rip),%rsi
mov    $0x51,%edx
call   1060 <memcpy@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1050 <memset@plt>
movb   $0x31,-0x120(%rbp)
movb   $0x32,-0x11f(%rbp)
movb   $0x33,-0x11e(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xeef(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    0xee3(%rip),%rsi
call   1070 <find_string@plt>
mov    %eax,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xed0(%rip),%rsi
lea    0xece(%rip),%rdx
call   1030 <replace_string@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c7 <main+0x77>
lea    -0x60(%rbp),%rsi
lea    0xeab(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc0(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1070 <find_string@plt>
mov    %eax,-0x8(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    0xe7a(%rip),%rdx
call   1030 <replace_string@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    121e <main+0xce>
lea    -0xc0(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <find_string@plt>
mov    %eax,-0x8(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe25(%rip),%rsi
lea    0xe22(%rip),%rdx
call   1030 <replace_string@plt>
cmpl   $0xffffffff,-0x8(%rbp)
jne    127e <main+0x12e>
lea    -0x120(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
movaps 0xefc(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xebe(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe80(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movb   $0x0,0x110(%rsp)
movaps 0xf09(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xeea(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movb   $0x0,0xb0(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
movw   $0x3231,(%rsp)
movb   $0x33,0x2(%rsp)
lea    0xea2(%rip),%rdi
lea    0xc0(%rsp),%r14
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe8f(%rip),%rbx
lea    0xe8d(%rip),%r15
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <find_string@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <replace_string@plt>
cmp    $0xffffffff,%ebp
jne    1230 <main+0x100>
lea    0xe5a(%rip),%rbx
lea    0xc0(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <printf@plt>
lea    0x60(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xe41(%rip),%rbx
lea    0xe3e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <find_string@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <replace_string@plt>
cmp    $0xffffffff,%ebp
jne    1290 <main+0x160>
lea    0xdfa(%rip),%rbx
lea    0x60(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xdee(%rip),%rbx
lea    0xdeb(%rip),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <find_string@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <replace_string@plt>
cmp    $0xffffffff,%ebp
jne    12e0 <main+0x1b0>
lea    0xdaa(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.text1 = [81 x i8] c"derp de derp de derp de derp\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.text2 = [81 x i8] c"abcabcabcabc\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"derp\00"
@.str.2 = [5 x i8] c"herp\00"
@.str.3 = [4 x i8] c"abc\00"
@.str.4 = [4 x i8] c"def\00"
@.str.5 = [4 x i8] c"123\00"
@.str.6 = [4 x i8] c"456\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [81 x i8]
%4 = alloca [81 x i8]
%5 = alloca [81 x i8]
store i32 0, i32* %1
%6 = bitcast [81 x i8]* %3 to i8*
%7 = bitcast [81 x i8]* %4 to i8*
%8 = bitcast [81 x i8]* %5 to i8*
%9 = bitcast i8* %8 to [81 x i8]*
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i32 0, i32 0
store i8 49, i8* %10
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i32 0, i32 1
store i8 50, i8* %11
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i32 0, i32 2
store i8 51, i8* %12
%13 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %20, %0
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%17 = call i32 @find_string(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %17, i32* %2
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%19 = call i32 @replace_string(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %15
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, -1
br i1 %22, label %15, label %23
23: ; preds = %20
%24 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %33, %23
%29 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%30 = call i32 @find_string(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 %30, i32* %2
%31 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%32 = call i32 @replace_string(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %28
%34 = load i32, i32* %2
%35 = icmp ne i32 %34, -1
br i1 %35, label %28, label %36
36: ; preds = %33
%37 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %46, %36
%42 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%43 = call i32 @find_string(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 %43, i32* %2
%44 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%45 = call i32 @replace_string(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %41
%47 = load i32, i32* %2
%48 = icmp ne i32 %47, -1
br i1 %48, label %41, label %49
49: ; preds = %46
%50 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %50)
ret i32 0
}

LLVM IR (-O2):
@__const.main.text1 = [81 x i8] c"derp de derp de derp de derp\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.text2 = [81 x i8] c"abcabcabcabc\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [5 x i8] c"derp\00"
@.str.2 = [5 x i8] c"herp\00"
@.str.3 = [4 x i8] c"abc\00"
@.str.4 = [4 x i8] c"def\00"
@.str.5 = [4 x i8] c"123\00"
@.str.6 = [4 x i8] c"456\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = alloca [81 x i8]
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
store i8 49, i8* %6
%7 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 1
store i8 50, i8* %7
%8 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 2
store i8 51, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %10
10: ; preds = %10, %0
%11 = call i32 @find_string(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @replace_string(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %17
17: ; preds = %17, %14
%18 = call i32 @find_string(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @replace_string(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32 %18, -1
br i1 %20, label %21, label %17
21: ; preds = %17
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %24
24: ; preds = %24, %21
%25 = call i32 @find_string(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @replace_string(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32 %25, -1
br i1 %27, label %28, label %24
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
ret i32 0
}