#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*/ printf(char *, char *);
char *str_replace(char *, char *, char *);
int main() {
  char name[] = "Hello, World!";
  char rep[] = "World";
  char with[] = "There";
  char *res = str_replace(name, rep, with);
  printf("\n\n\nFinal Result: %s\n\n", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xec8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xec2(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xeba(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xeb4(%rip),%ax
mov    %ax,-0x14(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xea6(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0x12(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1e(%rbp),%rdx
call   1040 <str_replace@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movabs $0x21646c726f5720,%rax
mov    %rax,0x1e(%rsp)
movabs $0x57202c6f6c6c6548,%rax
2c 20 57
mov    %rax,0x18(%rsp)
movw   $0x64,0x14(%rsp)
movl   $0x6c726f57,0x10(%rsp)
6c
movw   $0x65,0xc(%rsp)
movl   $0x72656854,0x8(%rsp)
72
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <str_replace@plt>
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.name = [14 x i8] c"Hello, World!\00"
@__const.main.rep = [6 x i8] c"World\00"
@__const.main.with = [6 x i8] c"There\00"
@.str = [22 x i8] c"\0A\0A\0AFinal Result: %s\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca [6 x i8]
%4 = alloca [6 x i8]
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [14 x i8]* %2 to i8*
%7 = bitcast [6 x i8]* %3 to i8*
%8 = bitcast [6 x i8]* %4 to i8*
%9 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%12 = call i8* @str_replace(i8* %9, i8* %10, i8* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 0
}

LLVM IR (-O2):
@__const.main.name = [14 x i8] c"Hello, World!\00"
@__const.main.rep = [6 x i8] c"World\00"
@__const.main.with = [6 x i8] c"There\00"
@.str = [22 x i8] c"\0A\0A\0AFinal Result: %s\0A\0A\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [6 x i8]
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i8* @str_replace(i8* %4, i8* %5, i8* %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
ret i32 0
}