#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int countLines(char *filename) {
  FILE *fp;
  char line[100];
  int lineCount = 0;
  if ((fp = fopen(filename, "r"))) {
    while (fgets(line, 100, fp)) {
      if (strlen(line) > 1)
        ++lineCount;
    }
  } else {
    printf("Missing file %s\n", filename);
    exit(1);
  }
  fclose(fp);
  return lineCount;
}


x86 assembly (clang, -O0):
<countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11e3 <countLines+0x83>
jmp    119c <countLines+0x3c>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11de <countLines+0x7e>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jle    11d9 <countLines+0x79>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    119c <countLines+0x3c>
jmp    11fd <countLines+0x9d>
mov    -0x8(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x84(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%rbx
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11da <countLines+0x7a>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11c7 <countLines+0x67>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
add    %ecx,%ebp
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <countLines+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [17 x i8] c"Missing file %s\0A\00"
define i32 @countLines(i8* %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 %17, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %14, %9 ], [ 0, %6 ]
%11 = call i32 @strlen(i8* %3)
%12 = icmp sgt i32 %11, 1
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %10, %13
%15 = call i64 @fgets(i8* %3, i32 100, i32* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %9
17: ; preds = %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %9, %6
%21 = phi i32 [ 0, %6 ], [ %14, %9 ]
%22 = call i32 @fclose(i32* %4)
ret i32 %21
}