#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int filecount(char filename[500]) {
  FILE *filecount = fopen(filename, "r");
  int filecountnumber;
  filecountnumber = 0;
  char ncline;
  ncline = getc(filecount);
  while (ncline != EOF) {
    if (ncline == '\n') {
      filecountnumber = filecountnumber + 1;
    }
    ncline = getc(filecount);
  }
  fclose(filecount);
  return filecountnumber;
}


x86 assembly (clang, -O0):
<filecount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
mov    0x2e7a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11a0 <filecount+0x70>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
jne    118f <filecount+0x5f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x15(%rbp)
jmp    1163 <filecount+0x33>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filecount>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <getc@plt>
mov    0x2e96(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%al
je     1176 <filecount+0x46>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r14),%al
jne    1160 <filecount+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @filecount(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%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
store i32 0, i32* %4
%8 = load i32*, i32** %3
%9 = call signext i8 @getc(i32* %8)
store i8 %9, i8* %5
br label %10
10: ; preds = %23, %1
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %16
%24 = load i32*, i32** %3
%25 = call signext i8 @getc(i32* %24)
store i8 %25, i8* %5
br label %10
26: ; preds = %10
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @filecount(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call signext i8 @getc(i32* %2)
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %15, label %6
6: ; preds = %1, %6
%7 = phi i8 [ %12, %6 ], [ %3, %1 ]
%8 = phi i32 [ %11, %6 ], [ 0, %1 ]
%9 = icmp eq i8 %7, 10
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %8, %10
%12 = tail call signext i8 @getc(i32* %2)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %6
15: ; preds = %6, %1
%16 = phi i32 [ 0, %1 ], [ %11, %6 ]
%17 = tail call i32 @fclose(i32* %2)
ret i32 %16
}