#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned long int fcountline(char *infile) {
  register unsigned long int lines = 0;
  FILE *fp = fopen(infile, "rb");
  char c = '\0';
  while (c != EOF) {
    c = fgetc(fp);
    if (c == '\n') {
      lines++;
    }
  }
  fclose(fp);
  return lines;
}


x86 assembly (clang, -O0):
<fcountline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e81(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     119c <fcountline+0x6c>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1197 <fcountline+0x67>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <fcountline+0x2c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcountline>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    0x2e9d(%rip),%r15
cmpb   $0x0,(%r15)
je     1179 <fcountline+0x49>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %rcx,%rbx
cmp    (%r15),%al
jne    1160 <fcountline+0x30>
jmp    117b <fcountline+0x4b>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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