void substitute(in, repl, with, out) char *in, *repl, *with, *out;
{
  char out2[80 + 1];
  char *pos;
  if ((pos = strstr(in, repl)) != 0) {
    substitute(pos + strlen(repl), repl, with, out2);
    *pos = 0;
    strcat(in, with);
    strcat(in, out2);
  }
  strcpy(out, in);
  return;
}


x86 assembly (clang, -O0):
<substitute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
je     11df <substitute+0x8f>
mov    -0x88(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x80(%rbp),%rcx
call   1050 <substitute@plt>
mov    -0x88(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substitute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
call   1070 <strstr@plt>
test   %rax,%rax
je     11af <substitute+0x5f>
mov    %rax,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
add    %rax,%rdi
mov    %rsp,%rbp
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   1050 <substitute@plt>
movb   $0x0,(%rbx)
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @substitute(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [81 x i8]
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %10
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %30
15: ; preds = %4
%16 = load i8*, i8** %10
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%23 = load i8*, i8** %10
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = load i8*, i8** %7
%26 = call i8* @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%29 = call i8* @strcat(i8* %27, i8* %28)
br label %30
30: ; preds = %15, %4
%31 = load i8*, i8** %8
%32 = load i8*, i8** %5
%33 = call i8* @strcpy(i8* %31, i8* %32)
ret void
}

LLVM IR (-O2):
define void @substitute(i8* %0, i8* nocapture %1, i8* nocapture %2, i8* %3) {
%5 = alloca [81 x i8]
%6 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 0, i8* %7
%12 = call i8* @strcat(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%13 = call i8* @strcat(i8* dereferenceable(1) %0, i8* %6)
br label %14
14: ; preds = %9, %4
%15 = call i8* @strcpy(i8* dereferenceable(1) %3, i8* dereferenceable(1) %0)
ret void
}