#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int numOfLines(char *filename) {
  FILE *fp;
  int n = 0;
  char line[100];
  if ((fp = fopen(filename, "r")) == NULL) {
    printf("\nError opening file\n");
    exit(1);
  }
  do {
    fgets(line, 100, fp);
    if (strlen(line) > 2)
      n++;
  } while (!feof(fp));
  fclose(fp);
  return n;
}


x86 assembly (clang, -O0):
<numOfLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ba <numOfLines+0x4a>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11bf <numOfLines+0x4f>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jle    11ec <numOfLines+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <numOfLines+0x81>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bf <numOfLines+0x4f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numOfLines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e1 <numOfLines+0x71>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x3,%eax
setge  %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11a0 <numOfLines+0x30>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"\0AError opening file\0A\00"
define i32 @numOfLines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [100 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
br label %13
13: ; preds = %24, %12
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %3
%16 = call i32 @fgets(i8* %14, i32 100, i32* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %13
br label %24
24: ; preds = %23
%25 = load i32*, i32** %3
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %13, label %29
29: ; preds = %24
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@str = [20 x i8] c"\0AError opening file\00"
define i32 @numOfLines(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1, %9
%10 = phi i32 [ %15, %9 ], [ 0, %1 ]
%11 = call i32 @fgets(i8* %3, i32 100, i32* %4)
%12 = call i32 @strlen(i8* %3)
%13 = icmp sgt i32 %12, 2
%14 = zext i1 %13 to i32
%15 = add nuw nsw i32 %10, %14
%16 = call i32 @feof(i32* %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %9
%19 = call i32 @fclose(i32* %4)
ret i32 %15
}