#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int main(int argc, char **argv) {
  FILE *f;
  int lines = 0;
  int chr;
  if (argc > 1) {
    f = fopen(argv[1], "r");
  } else {
    f = stdin;
  }
  if (f == NULL) {
    printf("Error: %s - file not found.\n", argv[1]);
    return 1;
  }
  do {
    chr = fgetc(f);
    if (chr == '\n') {
      lines++;
    }
  } while (chr != -1);
  fclose(f);
  printf("Number of lines: %d\n", lines);
  return 0;
}


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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1192 <main+0x52>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <main+0xd3>
jmp    11c4 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jne    11e3 <main+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <main+0xa8>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11c4 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-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,%rbp
cmp    $0x2,%edi
jl     11a3 <main+0x63>
mov    0x8(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11b2 <main+0x72>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1050 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
cmp    $0xffffffff,%eax
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe89(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c9 <main+0x89>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    1163 <main+0x23>
mov    0x8(%rbp),%rsi
lea    0xe45(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [29 x i8] c"Error: %s - file not found.\0A\00"
@.str.2 = [21 x i8] c"Number of lines: %d\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
br label %18
16: ; preds = %2
%17 = load i32*, i32** @stdin
store i32* %17, i32** %6
br label %18
18: ; preds = %16, %11
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %44
26: ; preds = %18
br label %27
27: ; preds = %36, %26
%28 = load i32*, i32** %6
%29 = call i32 @fgetc(i32* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %35
35: ; preds = %32, %27
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, -1
br i1 %38, label %27, label %39
39: ; preds = %36
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %39, %21
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.1 = [29 x i8] c"Error: %s - file not found.\0A\00"
@.str.2 = [21 x i8] c"Number of lines: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %2
%9 = load i32*, i32** @stdin
br label %10
10: ; preds = %8, %4
%11 = phi i32* [ %7, %4 ], [ %9, %8 ]
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %27
17: ; preds = %10, %17
%18 = phi i32 [ %22, %17 ], [ 0, %10 ]
%19 = tail call i32 @fgetc(i32* %11)
%20 = icmp eq i32 %19, 10
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %18, %21
%23 = icmp eq i32 %19, -1
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = tail call i32 @fclose(i32* %11)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %27
27: ; preds = %24, %13
%28 = phi i32 [ 1, %13 ], [ 0, %24 ]
ret i32 %28
}