#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int countLines(const char *filename) {
  FILE *fp;
  int count = 0;
  int temp;
  if ((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "Can not open the file:%s\n", filename);
    return 0;
  }
  while ((temp = fgetc(fp)) != EOF) {
    if (temp == '\n') {
      count++;
    }
  }
  fclose(fp);
  return count;
}


x86 assembly (clang, -O0):
<countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1196 <countLines+0x56>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dd <countLines+0x9d>
jmp    119b <countLines+0x5b>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
je     11ce <countLines+0x8e>
cmpl   $0xa,-0x20(%rbp)
jne    11c9 <countLines+0x89>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119b <countLines+0x5b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a1 <countLines+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e7e(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     1197 <countLines+0x57>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%eax
jne    1180 <countLines+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11bb <countLines+0x7b>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Can not open the file:%s\0A\00"
@EOF = global i32 0
define i32 @countLines(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 0, i32* %2
br label %31
14: ; preds = %1
br label %15
15: ; preds = %26, %14
%16 = load i32*, i32** %4
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %6
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %20
br label %15
27: ; preds = %15
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %5
store i32 %30, i32* %2
br label %31
31: ; preds = %27, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Can not open the file:%s\0A\00"
@EOF = global i32 0
define i32 @countLines(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %20, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %23
11: ; preds = %4, %11
%12 = phi i32 [ %17, %11 ], [ %5, %4 ]
%13 = phi i32 [ %16, %11 ], [ 0, %4 ]
%14 = icmp eq i32 %12, 10
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %13, %15
%17 = tail call i32 @fgetc(i32* %2)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %11
20: ; preds = %11, %4
%21 = phi i32 [ 0, %4 ], [ %16, %11 ]
%22 = tail call i32 @fclose(i32* %2)
br label %23
23: ; preds = %20, %8
%24 = phi i32 [ 0, %8 ], [ %21, %20 ]
ret i32 %24
}