#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 countLines(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  for (int i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "count")) {
      if (!(i + 1 < argc)) {
        return 1;
      }
      i++;
      int lines = countLines(argv[i]);
      FILE *file;
      file = fopen("./lineCounter.cfg", "r");
      int lastlines = 0;
      fread(&lastlines, sizeof(int), 1, file);
      fclose(file);
      printf("Number of lines now: %i\nNumber of lines earlier: %i\nNumber of "
             "lines added: %i\n",
             lines, lastlines, lines - lastlines);
    } else if (!strcmp(argv[i], "reset")) {
      if (!(i + 1 < argc)) {
        return 1;
      }
      i++;
      FILE *file;
      file = fopen("./lineCounter.cfg", "w");
      int lines = countLines(argv[i]);
      fwrite(&lines, sizeof(int), 1, file);
      fclose(file);
      printf("Number of lines: %i\n", lines);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1308 <main+0x198>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe54(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    124f <main+0xdf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     11d5 <main+0x65>
movl   $0x1,-0x4(%rbp)
jmp    130f <main+0x19f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <countLines@plt>
mov    %eax,-0x18(%rbp)
lea    0xe0d(%rip),%rdi
lea    0xe18(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    -0x24(%rbp),%ecx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f5 <main+0x185>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe07(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12f0 <main+0x180>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     128b <main+0x11b>
movl   $0x1,-0x4(%rbp)
jmp    130f <main+0x19f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    0xd6b(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <countLines@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x34(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f5 <main+0x185>
jmp    12fa <main+0x18a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x2,%edi
jl     12c0 <main+0x150>
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x1,%r14d
lea    0xe67(%rip),%rbp
jmp    11ad <main+0x3d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    %r13d,%r14d
jge    12b7 <main+0x147>
movslq %r14d,%rax
mov    (%r15,%rax,8),%r12
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1240 <main+0xd0>
mov    %r12,%rdi
lea    0xe9c(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11a0 <main+0x30>
add    $0x1,%r14d
cmp    %r13d,%r14d
jge    12bb <main+0x14b>
lea    0xe1c(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
movslq %r14d,%rax
mov    (%r15,%rax,8),%rdi
call   1070 <countLines@plt>
mov    %eax,(%rsp)
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%esi
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <main+0x30>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    %r13d,%r14d
jge    12bb <main+0x14b>
movslq %r14d,%rax
mov    (%r15,%rax,8),%rdi
call   1070 <countLines@plt>
mov    %eax,%ebx
lea    0xda8(%rip),%rdi
lea    0xdb3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rbp,%r12
mov    %rax,%rbp
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
mov    %r12,%rbp
call   1040 <fclose@plt>
mov    0x4(%rsp),%edx
mov    %ebx,%ecx
sub    %edx,%ecx
lea    0xd71(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a0 <main+0x30>
xor    %eax,%eax
jmp    12c0 <main+0x150>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"count\00"
@.str.1 = [18 x i8] c"./lineCounter.cfg\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [79 x i8] c"Number of lines now: %i\0ANumber of lines earlier: %i\0ANumber of lines added: %i\0A\00"
@.str.4 = [6 x i8] c"reset\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [21 x i8] c"Number of lines: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %12
12: ; preds = %82, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %85
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %50, label %24
24: ; preds = %16
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %30, label %29
29: ; preds = %24
store i32 1, i32* %3
br label %86
30: ; preds = %24
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @countLines(i8* %37)
store i32 %38, i32* %7
%39 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %39, i32** %8
store i32 0, i32* %9
%40 = load i32*, i32** %8
%41 = call i32 @fread(i32* %9, i32 4, i32 1, i32* %40)
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %7
%45 = load i32, i32* %9
%46 = load i32, i32* %7
%47 = load i32, i32* %9
%48 = sub nsw i32 %46, %47
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %45, i32 %48)
br label %81
50: ; preds = %16
%51 = load i8**, i8*** %5
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %80, label %58
58: ; preds = %50
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = load i32, i32* %4
%62 = icmp slt i32 %60, %61
br i1 %62, label %64, label %63
63: ; preds = %58
store i32 1, i32* %3
br label %86
64: ; preds = %58
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
%67 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %67, i32** %10
%68 = load i8**, i8*** %5
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @countLines(i8* %72)
store i32 %73, i32* %11
%74 = load i32*, i32** %10
%75 = call i32 @fwrite(i32* %11, i32 4, i32 1, i32* %74)
%76 = load i32*, i32** %10
%77 = call i32 @fclose(i32* %76)
%78 = load i32, i32* %11
%79 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %64, %50
br label %81
81: ; preds = %80, %30
br label %82
82: ; preds = %81
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %12
85: ; preds = %12
store i32 0, i32* %3
br label %86
86: ; preds = %85, %63, %29
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [6 x i8] c"count\00"
@.str.1 = [18 x i8] c"./lineCounter.cfg\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [79 x i8] c"Number of lines now: %i\0ANumber of lines earlier: %i\0ANumber of lines added: %i\0A\00"
@.str.4 = [6 x i8] c"reset\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [21 x i8] c"Number of lines: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %50
6: ; preds = %2
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %3 to i8*
br label %9
9: ; preds = %6, %46
%10 = phi i32 [ 1, %6 ], [ %48, %46 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %9
%17 = add nsw i32 %10, 1
%18 = icmp slt i32 %17, %0
br i1 %18, label %19, label %50
19: ; preds = %16
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32 @countLines(i8* %22)
%24 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
%25 = call i32 @fread(i32* %3, i32 4, i32 1, i32* %24)
%26 = tail call i32 @fclose(i32* %24)
%27 = load i32, i32* %3
%28 = sub nsw i32 %23, %27
%29 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %27, i32 %28)
br label %46
30: ; preds = %9
%31 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = add nsw i32 %10, 1
%35 = icmp slt i32 %34, %0
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%38 = sext i32 %34 to i64
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = tail call i32 @countLines(i8* %40)
store i32 %41, i32* %4
%42 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %37)
%43 = tail call i32 @fclose(i32* %37)
%44 = load i32, i32* %4
%45 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %19, %36, %30
%47 = phi i32 [ %10, %30 ], [ %34, %36 ], [ %17, %19 ]
%48 = add nsw i32 %47, 1
%49 = icmp slt i32 %48, %0
br i1 %49, label %9, label %50
50: ; preds = %46, %16, %33, %2
%51 = phi i32 [ 0, %2 ], [ 1, %33 ], [ 1, %16 ], [ 0, %46 ]
ret i32 %51
}