#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 */
char **calloc(int, int);
char *copy_string(char *);
int /*<<< orphan*/ find_replace(char *, char *, char *, char *);
char **find_replace_paths(char **paths, int n, char *find, char *replace) {
  char **replace_paths = calloc(n, sizeof(char *));
  int i;
  for (i = 0; i < n; ++i) {
    char replaced[4096];
    find_replace(paths[i], find, replace, replaced);
    replace_paths[i] = copy_string(replaced);
  }
  return replace_paths;
}


x86 assembly (clang, -O0):
<find_replace_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b7 <find_replace_paths+0x87>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%rcx
call   1050 <find_replace@plt>
lea    -0x1030(%rbp),%rdi
call   1030 <copy_string@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1162 <find_replace_paths+0x32>
mov    -0x28(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_replace_paths>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r12
mov    %esi,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    119a <find_replace_paths+0x6a>
mov    %ebx,%ebp
xor    %r14d,%r14d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%r14,8),%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%rdx
mov    %rbx,%rcx
call   1050 <find_replace@plt>
mov    %rbx,%rdi
call   1030 <copy_string@plt>
mov    %rax,0x0(%r13,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1170 <find_replace_paths+0x40>
mov    %r13,%rax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @find_replace_paths(i8** %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
%11 = alloca [4096 x i8]
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i32, i32* %6
%13 = call i8** @calloc(i32 %12, i32 8)
store i8** %13, i8*** %9
store i32 0, i32* %10
br label %14
14: ; preds = %34, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%27 = call i32 @find_replace(i8* %23, i8* %24, i8* %25, i8* %26)
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%29 = call i8* @copy_string(i8* %28)
%30 = load i8**, i8*** %9
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
br label %34
34: ; preds = %18
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %14
37: ; preds = %14
%38 = load i8**, i8*** %9
ret i8** %38
}

LLVM IR (-O2):
define noalias i8** @find_replace_paths(i8** nocapture %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [4096 x i8]
%6 = tail call i8** @calloc(i32 %1, i32 8)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %18, %11 ]
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @find_replace(i8* %14, i8* %2, i8* %3, i8* %9)
%16 = call i8* @copy_string(i8* %9)
%17 = getelementptr inbounds i8*, i8** %6, i64 %12
store i8* %16, i8** %17
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %11
20: ; preds = %11, %4
ret i8** %6
}