#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 /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int flen(char fname[]) {
  FILE *inFile;
  int lineCount, inputError;
  inFile = fopen(fname, "r");
  char word[128];
  lineCount = 0;
  while (inputError != EOF) {
    inputError = fscanf(inFile, "%s\n", word);
    lineCount++;
  }
  fclose(inFile);
  return (lineCount - 1);
}


x86 assembly (clang, -O0):
<flen>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%eax
je     1194 <flen+0x64>
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115a <flen+0x2a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flen>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebx
lea    0xea7(%rip),%r15
mov    %rsp,%r12
mov    0x2e83(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
add    $0x1,%ebx
cmp    0x0(%r13),%eax
jne    1170 <flen+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @flen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [128 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
store i32 0, i32* %4
br label %9
9: ; preds = %13, %1
%10 = load i32, i32* %5
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32*, i32** %3
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%16 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %9
19: ; preds = %9
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @flen(i8* nocapture %0) {
%2 = alloca [128 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ %8, %5 ], [ 0, %1 ]
%7 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = add nuw nsw i32 %6, 1
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %7, %9
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = call i32 @fclose(i32* %3)
ret i32 %6
}