#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 */
scalar_t__ is_subst_here(char *, char const *);
int /*<<< orphan*/ replst(char *, int, int, char const *);
int strlen(char const *);
int strrep(char *str, const char *srch, const char *repl) {
  int i, n = strlen(str);
  for (i = 0; i < n; i++) {
    if (is_subst_here(&str[i], srch)) {
      replst(str, i, strlen(srch), repl);
      i += strlen(repl);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<strrep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11cc <strrep+0x9c>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <is_subst_here@plt>
cmp    $0x0,%rax
je     11b9 <strrep+0x89>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
call   1040 <replst@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <strrep+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <strrep+0x27>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    119e <strrep+0x6e>
mov    %eax,%r12d
xor    %ebp,%ebp
jmp    1168 <strrep+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r12d,%ebp
jge    119e <strrep+0x6e>
movslq %ebp,%rdi
add    %rbx,%rdi
mov    %r15,%rsi
call   1050 <is_subst_here@plt>
test   %rax,%rax
je     1160 <strrep+0x30>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <replst@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%ebp
jmp    1160 <strrep+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strrep(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 i32 @strlen(i8* %9)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %35, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8*, i8** %5
%21 = call i64 @is_subst_here(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = load i8*, i8** %5
%27 = call i32 @strlen(i8* %26)
%28 = load i8*, i8** %6
%29 = call i32 @replst(i8* %24, i32 %25, i32 %27, i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = load i32, i32* %7
%33 = add nsw i32 %32, %31
store i32 %33, i32* %7
br label %34
34: ; preds = %23, %15
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %11
38: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
define i32 @strrep(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %3, %17
%7 = phi i32 [ %19, %17 ], [ 0, %3 ]
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i64 @is_subst_here(i8* %9, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = tail call i32 @strlen(i8* %1)
%14 = tail call i32 @replst(i8* %0, i32 %7, i32 %13, i8* %2)
%15 = tail call i32 @strlen(i8* %2)
%16 = add nsw i32 %15, %7
br label %17
17: ; preds = %6, %12
%18 = phi i32 [ %16, %12 ], [ %7, %6 ]
%19 = add nsw i32 %18, 1
%20 = icmp slt i32 %19, %4
br i1 %20, label %6, label %21
21: ; preds = %17, %3
ret i32 0
}