char *search_replace(search_str, replace_str, looking_string)
char *search_str, *replace_str, *looking_string;
{
  int here, len_search = strlen(search_str);
  while (1) {
    if ((here = instr(search_str, looking_string, 1)) == -1)
      return looking_string;
    delete_str(looking_string, here, len_search);
    insert_str(replace_str, looking_string, here);
  }
}


x86 assembly (clang, -O0):
<search_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <instr@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    118a <search_replace+0x4a>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1060 <delete_str@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1050 <insert_str@plt>
jmp    1160 <search_replace+0x20>

x86 assembly (clang, -O2):
<search_replace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <instr@plt>
cmp    $0xffffffff,%eax
je     11b7 <search_replace+0x77>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <delete_str@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <insert_str@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <instr@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1180 <search_replace+0x40>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @search_replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %8
br label %12
12: ; preds = %3, %19
%13 = load i8*, i8** %4
%14 = load i8*, i8** %6
%15 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @instr to i32 (i8*, i8*, i32, ...)*)(i8* %13, i8* %14, i32 1)
store i32 %15, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i8*, i8** %6
ret i8* %18
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @delete_str to i32 (i8*, i32, i32, ...)*)(i8* %20, i32 %21, i32 %22)
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @insert_str to i32 (i8*, i8*, i32, ...)*)(i8* %24, i8* %25, i32 %26)
br label %12
}

LLVM IR (-O2):
define i8* @search_replace(i8* %0, i8* %1, i8* returned %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @instr to i32 (i8*, i8*, i32, ...)*)(i8* %0, i8* %2, i32 1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %9, %3
ret i8* %2
9: ; preds = %3, %9
%10 = phi i32 [ %13, %9 ], [ %6, %3 ]
%11 = tail call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @delete_str to i32 (i8*, i32, i32, ...)*)(i8* %2, i32 %10, i32 %5)
%12 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @insert_str to i32 (i8*, i8*, i32, ...)*)(i8* %1, i8* %2, i32 %10)
%13 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @instr to i32 (i8*, i8*, i32, ...)*)(i8* %0, i8* %2, i32 1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %8, label %9
}