#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 */
int ReplaceStringsInMatchingFiles(char *, char *, char *, int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ testit();
int main(int argc, char **argv) {
  int nchanged;
  int old_oldroot_len;
  if (argc == 2 && strcmp(argv[1], "--test") == 0) {
    testit();
    exit(0);
  }
  if (argc < 4)
    do {
      fprintf(stderr,
              "Usage: %s <old root> <new root> <directoryToSearch> "
              "[<old_oldrootlen>]\n",
              argv[0]);
      fprintf(stderr, "Failed at line %d\n", 435);
      exit(1);
    } while (0);
  old_oldroot_len = strlen(argv[1]);
  if (argc == 5)
    old_oldroot_len = atoi(argv[4]);
  nchanged =
      ReplaceStringsInMatchingFiles(argv[1], argv[2], argv[3], old_oldroot_len);
  if (nchanged > 0) {
    printf("%d files updated.\n", nchanged);
    return 0;
  }
  printf("No files changed!\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11cc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11cc <main+0x4c>
mov    $0x0,%al
call   1080 <testit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jge    121f <main+0x9f>
jmp    11db <main+0x5b>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
mov    $0x1b3,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x5,-0x8(%rbp)
jne    1249 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x18(%rbp),%ecx
call   1070 <ReplaceStringsInMatchingFiles@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1293 <main+0x113>
mov    -0x14(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <main+0x128>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11fe <main+0x6e>
mov    %edi,%ebp
cmp    $0x3,%edi
jle    1221 <main+0x91>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0x5,%ebp
jne    11b9 <main+0x29>
mov    0x20(%rbx),%rdi
call   10a0 <atoi@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
mov    %eax,%ecx
call   1080 <ReplaceStringsInMatchingFiles@plt>
test   %eax,%eax
jle    11e4 <main+0x54>
lea    0xe8b(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f5 <main+0x65>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1221 <main+0x91>
xor    %eax,%eax
call   1090 <testit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2db8(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe09(%rip),%rsi
mov    $0x1b3,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--test\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"Usage: %s <old root> <new root> <directoryToSearch> [<old_oldrootlen>]\0A\00"
@.str.2 = [19 x i8] c"Failed at line %d\0A\00"
@.str.3 = [19 x i8] c"%d files updated.\0A\00"
@.str.4 = [19 x i8] c"No files changed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = call i32 (...) @testit()
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %10, %2
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %33
22: ; preds = %19
br label %23
23: ; preds = %22
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 435)
%31 = call i32 @exit(i32 1)
unreachable
32: ; No predecessors!
br label %33
33: ; preds = %32, %19
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %7
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 5
br i1 %39, label %40, label %45
40: ; preds = %33
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 4
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %7
br label %45
45: ; preds = %40, %33
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = load i32, i32* %7
%56 = call i32 @ReplaceStringsInMatchingFiles(i8* %48, i8* %51, i8* %54, i32 %55)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %45
%60 = load i32, i32* %6
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %60)
store i32 0, i32* %3
br label %64
62: ; preds = %45
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %64
64: ; preds = %62, %59
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [7 x i8] c"--test\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"Usage: %s <old root> <new root> <directoryToSearch> [<old_oldrootlen>]\0A\00"
@.str.2 = [19 x i8] c"Failed at line %d\0A\00"
@.str.3 = [19 x i8] c"%d files updated.\0A\00"
@str = [18 x i8] c"No files changed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = tail call i32 (...) @testit()
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = icmp slt i32 %0, 4
br i1 %13, label %14, label %21
14: ; preds = %4, %12
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 435)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 @strlen(i8* %23)
%25 = icmp eq i32 %0, 5
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
br label %30
30: ; preds = %26, %21
%31 = phi i32 [ %29, %26 ], [ %24, %21 ]
%32 = load i8*, i8** %22
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call i32 @ReplaceStringsInMatchingFiles(i8* %32, i8* %34, i8* %36, i32 %31)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %43
41: ; preds = %30
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
%44 = phi i32 [ 0, %39 ], [ 1, %41 ]
ret i32 %44
}