#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int findandreplace(char *, char *, char *, unsigned long);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
size_t fwrite(char *, int, unsigned long, int /*<<< orphan*/ *);
char *malloc(unsigned long);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int replacStrAtOrg(char **strList1, char **strList2, char *path, int count) {
  int ret = 0;
  unsigned long filesize;
  char *content;
  FILE *org_fileh = fopen(path, "r");
  if (org_fileh == NULL)
    return -1;
  fseek(org_fileh, 0L, SEEK_END);
  filesize = ftell(org_fileh);
  rewind(org_fileh);
  content = malloc(filesize);
  fread(content, 1, filesize, org_fileh);
  fclose(org_fileh);
  int i;
  for (i = 0; i < count; i++) {
    char *str_org = strList1[i];
    char *str_new = strList2[i];
    if (strlen(str_org) == 0 || strlen(str_new) == 0) {
      ret = -2;
      break;
    }
    if (strlen(str_org) != strlen(str_new)) {
      ret = -3;
      break;
    }
    int times = findandreplace(str_org, str_new, content, filesize);
    if (times < 0) {
      ret = -4;
      break;
    }
    printf("> replace '%s' %d times.\n", str_org, times);
    ret += times;
  }
  if (ret > 0) {
    FILE *new_fileh = fopen(path, "w+");
    if (new_fileh == NULL) {
      free(content);
      return -5;
    }
    size_t nbytes = fwrite(content, 1, filesize, new_fileh);
    if (nbytes != filesize) {
      free(content);
      return -6;
    }
    fclose(new_fileh);
  }
  free(content);
  return ret;
}


x86 assembly (clang, -O0):
<replacStrAtOrg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    120c <replacStrAtOrg+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e6 <replacStrAtOrg+0x226>
mov    -0x40(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10c0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <rewind@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1353 <replacStrAtOrg+0x193>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%rax
je     12bd <replacStrAtOrg+0xfd>
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%rax
jne    12c9 <replacStrAtOrg+0x109>
movl   $0xfffffffe,-0x28(%rbp)
jmp    1353 <replacStrAtOrg+0x193>
mov    -0x50(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
je     12fb <replacStrAtOrg+0x13b>
movl   $0xfffffffd,-0x28(%rbp)
jmp    1353 <replacStrAtOrg+0x193>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <findandreplace@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    1329 <replacStrAtOrg+0x169>
movl   $0xfffffffc,-0x28(%rbp)
jmp    1353 <replacStrAtOrg+0x193>
mov    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
lea    0xccb(%rip),%rdi
call   1080 <printf@plt>
mov    -0x5c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    126b <replacStrAtOrg+0xab>
cmpl   $0x0,-0x28(%rbp)
jle    13d7 <replacStrAtOrg+0x217>
mov    -0x20(%rbp),%rdi
lea    0xcb4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1391 <replacStrAtOrg+0x1d1>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    13e6 <replacStrAtOrg+0x226>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     13ce <replacStrAtOrg+0x20e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffa,-0x4(%rbp)
jmp    13e6 <replacStrAtOrg+0x226>
mov    -0x68(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replacStrAtOrg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
lea    0xe1b(%rip),%rsi
mov    %rdx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     133e <replacStrAtOrg+0x17e>
mov    %rax,%r14
mov    %rbx,0x18(%rsp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r14,%rdi
call   10a0 <ftell@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <rewind@plt>
mov    %rbx,%rdi
call   10b0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
test   %r15d,%r15d
jle    1351 <replacStrAtOrg+0x191>
mov    %r15d,%eax
mov    %rax,0x20(%rsp)
xor    %ebx,%ebx
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    0x28(%rsp),%rax
mov    (%rax,%rbx,8),%r14
mov    0x30(%rsp),%rax
mov    (%rax,%rbx,8),%r15
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
je     1351 <replacStrAtOrg+0x191>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <strlen@plt>
test   %rax,%rax
je     1351 <replacStrAtOrg+0x191>
cmp    %rax,%r12
jne    1345 <replacStrAtOrg+0x185>
mov    %r14,%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rcx
call   1040 <findandreplace@plt>
test   %eax,%eax
js     134c <replacStrAtOrg+0x18c>
mov    %eax,%ebp
lea    0xd2b(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1080 <printf@plt>
add    %ebp,%r13d
add    $0x1,%rbx
cmp    %rbx,0x20(%rsp)
jne    1270 <replacStrAtOrg+0xb0>
test   %r13d,%r13d
jle    1339 <replacStrAtOrg+0x179>
lea    0xd21(%rip),%rsi
mov    0x18(%rsp),%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     136c <replacStrAtOrg+0x1ac>
mov    %rax,%r14
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
mov    $0xfffffffa,%ebp
cmp    %rbx,%rax
jne    1351 <replacStrAtOrg+0x191>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r13d,%ebp
jmp    1351 <replacStrAtOrg+0x191>
mov    $0xffffffff,%ebp
jmp    135b <replacStrAtOrg+0x19b>
mov    $0xfffffffd,%ebp
jmp    1351 <replacStrAtOrg+0x191>
mov    $0xfffffffc,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfffffffb,%ebp
jmp    1351 <replacStrAtOrg+0x191>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.1 = [26 x i8] c"> replace '%s' %d times.\0A\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @replacStrAtOrg(i8** %0, i8** %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i64
store i8** %0, i8*** %6
store i8** %1, i8*** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
%20 = load i8*, i8** %8
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %13
%22 = load i32*, i32** %13
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
br label %119
25: ; preds = %4
%26 = load i32*, i32** %13
%27 = load i32, i32* @SEEK_END
%28 = call i32 @fseek(i32* %26, i64 0, i32 %27)
%29 = load i32*, i32** %13
%30 = call i64 @ftell(i32* %29)
store i64 %30, i64* %11
%31 = load i32*, i32** %13
%32 = call i32 @rewind(i32* %31)
%33 = load i64, i64* %11
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %12
%35 = load i8*, i8** %12
%36 = load i64, i64* %11
%37 = load i32*, i32** %13
%38 = call i32 @fread(i8* %35, i32 1, i64 %36, i32* %37)
%39 = load i32*, i32** %13
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %14
br label %41
41: ; preds = %87, %25
%42 = load i32, i32* %14
%43 = load i32, i32* %9
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %90
45: ; preds = %41
%46 = load i8**, i8*** %6
%47 = load i32, i32* %14
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
store i8* %50, i8** %15
%51 = load i8**, i8*** %7
%52 = load i32, i32* %14
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
store i8* %55, i8** %16
%56 = load i8*, i8** %15
%57 = call i64 @strlen(i8* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %45
%60 = load i8*, i8** %16
%61 = call i64 @strlen(i8* %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59, %45
store i32 -2, i32* %10
br label %90
64: ; preds = %59
%65 = load i8*, i8** %15
%66 = call i64 @strlen(i8* %65)
%67 = load i8*, i8** %16
%68 = call i64 @strlen(i8* %67)
%69 = icmp ne i64 %66, %68
br i1 %69, label %70, label %71
70: ; preds = %64
store i32 -3, i32* %10
br label %90
71: ; preds = %64
%72 = load i8*, i8** %15
%73 = load i8*, i8** %16
%74 = load i8*, i8** %12
%75 = load i64, i64* %11
%76 = call i32 @findandreplace(i8* %72, i8* %73, i8* %74, i64 %75)
store i32 %76, i32* %17
%77 = load i32, i32* %17
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %71
store i32 -4, i32* %10
br label %90
80: ; preds = %71
%81 = load i8*, i8** %15
%82 = load i32, i32* %17
%83 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %81, i32 %82)
%84 = load i32, i32* %17
%85 = load i32, i32* %10
%86 = add nsw i32 %85, %84
store i32 %86, i32* %10
br label %87
87: ; preds = %80
%88 = load i32, i32* %14
%89 = add nsw i32 %88, 1
store i32 %89, i32* %14
br label %41
90: ; preds = %79, %70, %63, %41
%91 = load i32, i32* %10
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %115
93: ; preds = %90
%94 = load i8*, i8** %8
%95 = call i32* @fopen(i8* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %95, i32** %18
%96 = load i32*, i32** %18
%97 = icmp eq i32* %96, null
br i1 %97, label %98, label %101
98: ; preds = %93
%99 = load i8*, i8** %12
%100 = call i32 @free(i8* %99)
store i32 -5, i32* %5
br label %119
101: ; preds = %93
%102 = load i8*, i8** %12
%103 = load i64, i64* %11
%104 = load i32*, i32** %18
%105 = call i64 @fwrite(i8* %102, i32 1, i64 %103, i32* %104)
store i64 %105, i64* %19
%106 = load i64, i64* %19
%107 = load i64, i64* %11
%108 = icmp ne i64 %106, %107
br i1 %108, label %109, label %112
109: ; preds = %101
%110 = load i8*, i8** %12
%111 = call i32 @free(i8* %110)
store i32 -6, i32* %5
br label %119
112: ; preds = %101
%113 = load i32*, i32** %18
%114 = call i32 @fclose(i32* %113)
br label %115
115: ; preds = %112, %90
%116 = load i8*, i8** %12
%117 = call i32 @free(i8* %116)
%118 = load i32, i32* %10
store i32 %118, i32* %5
br label %119
119: ; preds = %115, %109, %98, %24
%120 = load i32, i32* %5
ret i32 %120
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.1 = [26 x i8] c"> replace '%s' %d times.\0A\00"
@.str.2 = [3 x i8] c"w+\00"
define i32 @replacStrAtOrg(i8** nocapture %0, i8** nocapture %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %53, label %7
7: ; preds = %4
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %5, i64 0, i32 %8)
%10 = tail call i64 @ftell(i32* %5)
%11 = tail call i32 @rewind(i32* %5)
%12 = tail call i8* @malloc(i64 %10)
%13 = tail call i32 @fread(i8* %12, i32 1, i64 %10, i32* %5)
%14 = tail call i32 @fclose(i32* %5)
%15 = icmp sgt i32 %3, 0
br i1 %15, label %16, label %50
16: ; preds = %7
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %16, %35
%19 = phi i64 [ 0, %16 ], [ %38, %35 ]
%20 = phi i32 [ 0, %16 ], [ %37, %35 ]
%21 = getelementptr inbounds i8*, i8** %0, i64 %19
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %1, i64 %19
%24 = load i8*, i8** %23
%25 = tail call i64 @strlen(i8* dereferenceable(1) %22)
%26 = icmp eq i64 %25, 0
br i1 %26, label %50, label %27
27: ; preds = %18
%28 = tail call i64 @strlen(i8* dereferenceable(1) %24)
%29 = icmp eq i64 %28, 0
br i1 %29, label %50, label %30
30: ; preds = %27
%31 = icmp eq i64 %25, %28
br i1 %31, label %32, label %50
32: ; preds = %30
%33 = tail call i32 @findandreplace(i8* %22, i8* %24, i8* %12, i64 %10)
%34 = icmp slt i32 %33, 0
br i1 %34, label %50, label %35
35: ; preds = %32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %33)
%37 = add nsw i32 %33, %20
%38 = add nuw nsw i64 %19, 1
%39 = icmp eq i64 %38, %17
br i1 %39, label %40, label %18
40: ; preds = %35
%41 = icmp sgt i32 %37, 0
br i1 %41, label %42, label %50
42: ; preds = %40
%43 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %50, label %45
45: ; preds = %42
%46 = tail call i64 @fwrite(i8* %12, i32 1, i64 %10, i32* %43)
%47 = icmp eq i64 %46, %10
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 @fclose(i32* %43)
br label %50
50: ; preds = %32, %30, %18, %27, %40, %48, %7, %45, %42
%51 = phi i32 [ -5, %42 ], [ -6, %45 ], [ %37, %48 ], [ %37, %40 ], [ 0, %7 ], [ -2, %27 ], [ -2, %18 ], [ -3, %30 ], [ -4, %32 ]
%52 = tail call i32 @free(i8* %12)
br label %53
53: ; preds = %50, %4
%54 = phi i32 [ -1, %4 ], [ %51, %50 ]
ret i32 %54
}