#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 *, char *, char *);
int /*<<< orphan*/ strings_replace(char *, char *, char *, char *);
void example_replace() {
  char *src = "this is a simple example";
  char *sub = "mp";
  char *rep = "**";
  char dst[100] = {0};
  strings_replace(dst, src, sub, rep);
  printf("replace '%s' in '%s' with '%s': '%s'\n", sub, src, rep, dst);
}


x86 assembly (clang, -O0):
<example_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xecc(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec4(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <strings_replace@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x80(%rbp),%r8
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example_replace>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xea6(%rip),%r14
lea    0xeb8(%rip),%rbx
lea    0xeb4(%rip),%r15
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <strings_replace@plt>
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"this is a simple example\00"
@.str.1 = [3 x i8] c"mp\00"
@.str.2 = [3 x i8] c"**\00"
@.str.3 = [38 x i8] c"replace '%s' in '%s' with '%s': '%s'\0A\00"
define void @example_replace() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [100 x i8]
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3
%5 = bitcast [100 x i8]* %4 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %1
%8 = load i8*, i8** %2
%9 = load i8*, i8** %3
%10 = call i32 @strings_replace(i8* %6, i8* %7, i8* %8, i8* %9)
%11 = load i8*, i8** %2
%12 = load i8*, i8** %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %12, i8* %13, i8* %14)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"this is a simple example\00"
@.str.1 = [3 x i8] c"mp\00"
@.str.2 = [3 x i8] c"**\00"
@.str.3 = [38 x i8] c"replace '%s' in '%s' with '%s': '%s'\0A\00"
define void @example_replace() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @strings_replace(i8* %2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret void
}