#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__ CFCUtil_wrapped_malloc(int, char *, int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ strlen(char const *);
char *strstr(char *, char const *);
char *S_global_replace(const char *string, const char *match,
                       const char *replacement) {
  char *found = (char *)string;
  int string_len = (int)strlen(string);
  int match_len = (int)strlen(match);
  int replacement_len = (int)strlen(replacement);
  int len_diff = replacement_len - match_len;
  unsigned count = 0;
  while (NULL != (found = strstr(found, match))) {
    count++;
    found += match_len;
  }
  int size = string_len + count * len_diff + 1;
  char *modified = (char *)CFCUtil_wrapped_malloc(
      (size),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/gitpan/Clownfish-CFC/refs/heads/master/src/"
      "CFCPerlPod.c",
      241);
  modified[size - 1] = 0;
  found = (char *)string;
  char *target = modified;
  size_t last_end = 0;
  if (count) {
    while (NULL != (found = strstr(found, match))) {
      size_t pos = found - string;
      size_t unchanged_len = pos - last_end;
      found += match_len;
      memcpy(target, string + last_end, unchanged_len);
      target += unchanged_len;
      last_end = pos + match_len;
      memcpy(target, replacement, replacement_len);
      target += replacement_len;
    }
  }
  size_t remaining = string_len - last_end;
  memcpy(target, string + string_len - remaining, remaining);
  return modified;
}


x86 assembly (clang, -O0):
<S_global_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11ce <S_global_replace+0x8e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1190 <S_global_replace+0x50>
mov    -0x24(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   -0x30(%rbp),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
lea    0xe16(%rip),%rsi
mov    $0xf1,%edx
call   1040 <CFCUtil_wrapped_malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12d7 <S_global_replace+0x197>
jmp    1230 <S_global_replace+0xf0>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     12d2 <S_global_replace+0x192>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
sub    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x50(%rbp),%rsi
mov    -0x60(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x60(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x58(%rbp),%rax
movslq -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x2c(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    1230 <S_global_replace+0xf0>
jmp    12d7 <S_global_replace+0x197>
movslq -0x24(%rbp),%rax
sub    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
xor    %eax,%eax
sub    -0x68(%rbp),%rax
add    %rax,%rsi
mov    -0x68(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x40(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<S_global_replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,0x10(%rsp)
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %ebp,%r15d
sub    %ebx,%r15d
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
mov    %r14,0x30(%rsp)
mov    %rbx,0x8(%rsp)
mov    %rbp,(%rsp)
je     11c8 <S_global_replace+0x88>
movslq %ebx,%rbx
mov    %r13,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %rbx,%rax
add    $0x1,%ebp
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
jne    11b0 <S_global_replace+0x70>
jmp    11cd <S_global_replace+0x8d>
mov    %r13,%r14
xor    %ebp,%ebp
imul   %ebp,%r15d
mov    0x10(%rsp),%rax
lea    (%r15,%rax,1),%r13d
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
lea    0xe18(%rip),%rsi
mov    $0xf1,%edx
call   1040 <CFCUtil_wrapped_malloc@plt>
mov    %rax,%r15
movslq %r13d,%rax
movb   $0x0,(%r15,%rax,1)
test   %ebp,%ebp
mov    %r15,0x20(%rsp)
mov    %r12,0x18(%rsp)
je     12a8 <S_global_replace+0x168>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     12a8 <S_global_replace+0x168>
mov    %rax,%r12
movslq 0x8(%rsp),%rax
mov    %rax,0x8(%rsp)
movslq (%rsp),%rax
mov    %rax,(%rsp)
xor    %esi,%esi
mov    %r14,0x28(%rsp)
mov    0x8(%rsp),%r13
mov    (%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r12,%r14
mov    0x18(%rsp),%rax
sub    %rax,%r14
mov    %r14,%rbp
sub    %rsi,%rbp
add    %r13,%r12
add    %rax,%rsi
mov    %r15,%rdi
mov    %rbp,%rdx
call   1050 <memcpy@plt>
add    %r15,%rbp
add    %r13,%r14
mov    %rbp,%rdi
mov    0x30(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
add    %rbx,%rbp
mov    %r12,%rdi
mov    0x28(%rsp),%rsi
call   1060 <strstr@plt>
mov    %rax,%r12
mov    %rbp,%r15
mov    %r14,%rsi
test   %rax,%rax
jne    1250 <S_global_replace+0x110>
jmp    12ae <S_global_replace+0x16e>
xor    %r14d,%r14d
mov    %r15,%rbp
movslq 0x10(%rsp),%rdx
mov    0x18(%rsp),%rsi
add    %rdx,%rsi
sub    %r14,%rdx
sub    %rdx,%rsi
mov    %rbp,%rdi
call   1050 <memcpy@plt>
mov    0x20(%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gitpan/Clownfish-CFC/refs/heads/master/src/CFCPerlPod.c\00"
define i8* @S_global_replace(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%20 = load i8*, i8** %4
store i8* %20, i8** %7
%21 = load i8*, i8** %4
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %8
%24 = load i8*, i8** %5
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i8*, i8** %6
%28 = call i64 @strlen(i8* %27)
%29 = trunc i64 %28 to i32
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = load i32, i32* %9
%32 = sub nsw i32 %30, %31
store i32 %32, i32* %11
store i32 0, i32* %12
br label %33
33: ; preds = %38, %3
%34 = load i8*, i8** %7
%35 = load i8*, i8** %5
%36 = call i8* @strstr(i8* %34, i8* %35)
store i8* %36, i8** %7
%37 = icmp ne i8* null, %36
br i1 %37, label %38, label %45
38: ; preds = %33
%39 = load i32, i32* %12
%40 = add i32 %39, 1
store i32 %40, i32* %12
%41 = load i32, i32* %9
%42 = load i8*, i8** %7
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %7
br label %33
45: ; preds = %33
%46 = load i32, i32* %8
%47 = load i32, i32* %12
%48 = load i32, i32* %11
%49 = mul i32 %47, %48
%50 = add i32 %46, %49
%51 = add i32 %50, 1
store i32 %51, i32* %13
%52 = load i32, i32* %13
%53 = call i64 @CFCUtil_wrapped_malloc(i32 %52, i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 241)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %14
%55 = load i8*, i8** %14
%56 = load i32, i32* %13
%57 = sub nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %4
store i8* %60, i8** %7
%61 = load i8*, i8** %14
store i8* %61, i8** %15
store i64 0, i64* %16
%62 = load i32, i32* %12
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %106
64: ; preds = %45
br label %65
65: ; preds = %70, %64
%66 = load i8*, i8** %7
%67 = load i8*, i8** %5
%68 = call i8* @strstr(i8* %66, i8* %67)
store i8* %68, i8** %7
%69 = icmp ne i8* null, %68
br i1 %69, label %70, label %105
70: ; preds = %65
%71 = load i8*, i8** %7
%72 = load i8*, i8** %4
%73 = ptrtoint i8* %71 to i64
%74 = ptrtoint i8* %72 to i64
%75 = sub i64 %73, %74
store i64 %75, i64* %17
%76 = load i64, i64* %17
%77 = load i64, i64* %16
%78 = sub i64 %76, %77
store i64 %78, i64* %18
%79 = load i32, i32* %9
%80 = load i8*, i8** %7
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds i8, i8* %80, i64 %81
store i8* %82, i8** %7
%83 = load i8*, i8** %15
%84 = load i8*, i8** %4
%85 = load i64, i64* %16
%86 = getelementptr inbounds i8, i8* %84, i64 %85
%87 = load i64, i64* %18
%88 = call i32 @memcpy(i8* %83, i8* %86, i64 %87)
%89 = load i64, i64* %18
%90 = load i8*, i8** %15
%91 = getelementptr inbounds i8, i8* %90, i64 %89
store i8* %91, i8** %15
%92 = load i64, i64* %17
%93 = load i32, i32* %9
%94 = sext i32 %93 to i64
%95 = add i64 %92, %94
store i64 %95, i64* %16
%96 = load i8*, i8** %15
%97 = load i8*, i8** %6
%98 = load i32, i32* %10
%99 = sext i32 %98 to i64
%100 = call i32 @memcpy(i8* %96, i8* %97, i64 %99)
%101 = load i32, i32* %10
%102 = load i8*, i8** %15
%103 = sext i32 %101 to i64
%104 = getelementptr inbounds i8, i8* %102, i64 %103
store i8* %104, i8** %15
br label %65
105: ; preds = %65
br label %106
106: ; preds = %105, %45
%107 = load i32, i32* %8
%108 = sext i32 %107 to i64
%109 = load i64, i64* %16
%110 = sub i64 %108, %109
store i64 %110, i64* %19
%111 = load i8*, i8** %15
%112 = load i8*, i8** %4
%113 = load i32, i32* %8
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %112, i64 %114
%116 = load i64, i64* %19
%117 = sub i64 0, %116
%118 = getelementptr inbounds i8, i8* %115, i64 %117
%119 = load i64, i64* %19
%120 = call i32 @memcpy(i8* %111, i8* %118, i64 %119)
%121 = load i8*, i8** %14
ret i8* %121
}

LLVM IR (-O2):
@.str = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/gitpan/Clownfish-CFC/refs/heads/master/src/CFCPerlPod.c\00"
define i8* @S_global_replace(i8* %0, i8* nocapture %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = trunc i64 %6 to i32
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = trunc i64 %8 to i32
%10 = sub nsw i32 %9, %7
%11 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %3
%14 = shl i64 %6, 32
%15 = ashr exact i64 %14, 32
br label %16
16: ; preds = %13, %16
%17 = phi i8* [ %11, %13 ], [ %21, %16 ]
%18 = phi i32 [ 0, %13 ], [ %19, %16 ]
%19 = add i32 %18, 1
%20 = getelementptr inbounds i8, i8* %17, i64 %15
%21 = tail call i8* @strstr(i8* dereferenceable(1) %20, i8* dereferenceable(1) %1)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %16
23: ; preds = %16, %3
%24 = phi i32 [ 0, %3 ], [ %19, %16 ]
%25 = mul i32 %24, %10
%26 = add i32 %25, %5
%27 = add i32 %26, 1
%28 = tail call i64 @CFCUtil_wrapped_malloc(i32 %27, i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str, i64 0, i64 0), i32 241)
%29 = inttoptr i64 %28 to i8*
%30 = sext i32 %26 to i64
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 0, i8* %31
%32 = icmp eq i32 %24, 0
br i1 %32, label %58, label %33
33: ; preds = %23
%34 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%35 = icmp eq i8* %34, null
br i1 %35, label %58, label %36
36: ; preds = %33
%37 = ptrtoint i8* %0 to i64
%38 = shl i64 %6, 32
%39 = ashr exact i64 %38, 32
%40 = shl i64 %8, 32
%41 = ashr exact i64 %40, 32
br label %42
42: ; preds = %36, %42
%43 = phi i8* [ %34, %36 ], [ %56, %42 ]
%44 = phi i8* [ %29, %36 ], [ %55, %42 ]
%45 = phi i64 [ 0, %36 ], [ %53, %42 ]
%46 = ptrtoint i8* %43 to i64
%47 = sub i64 %46, %37
%48 = sub i64 %47, %45
%49 = getelementptr inbounds i8, i8* %43, i64 %39
%50 = getelementptr inbounds i8, i8* %0, i64 %45
%51 = tail call i32 @memcpy(i8* %44, i8* %50, i64 %48)
%52 = getelementptr inbounds i8, i8* %44, i64 %48
%53 = add i64 %47, %39
%54 = tail call i32 @memcpy(i8* %52, i8* %2, i64 %41)
%55 = getelementptr inbounds i8, i8* %52, i64 %41
%56 = tail call i8* @strstr(i8* dereferenceable(1) %49, i8* dereferenceable(1) %1)
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %42
58: ; preds = %42, %33, %23
%59 = phi i64 [ 0, %23 ], [ 0, %33 ], [ %53, %42 ]
%60 = phi i8* [ %29, %23 ], [ %29, %33 ], [ %55, %42 ]
%61 = shl i64 %4, 32
%62 = ashr exact i64 %61, 32
%63 = sub i64 %62, %59
%64 = getelementptr inbounds i8, i8* %0, i64 %62
%65 = sub i64 0, %63
%66 = getelementptr inbounds i8, i8* %64, i64 %65
%67 = tail call i32 @memcpy(i8* %60, i8* %66, i64 %63)
ret i8* %29
}