#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int readNbInst(char *fname) {
  FILE *inFile = fopen(fname, "r");
  char line[2097152];
  int nbInst = 0;
  if (!inFile) {
    fprintf(stderr, "File %s does not exist\n", fname);
    exit(EXIT_FAILURE);
  }
  while (fgets(line, 2097152, inFile)) {
    if (line != NULL && strlen(line) > 5)
      nbInst++;
  }
  fclose(inFile);
  return nbInst;
}


x86 assembly (clang, -O0):
<readNbInst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200020,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x200014(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <readNbInst+0x5f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11c4 <readNbInst+0x64>
lea    -0x200010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120c <readNbInst+0xac>
lea    -0x200010(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x5,%eax
jle    1207 <readNbInst+0xa7>
mov    -0x200014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x200014(%rbp)
jmp    11c4 <readNbInst+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x200014(%rbp),%eax
add    $0x200020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNbInst>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200000,%rsp
mov    %rdi,%rbx
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11dd <readNbInst+0x7d>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x200000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11c7 <readNbInst+0x67>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
setge  %cl
add    %ecx,%ebp
mov    %rbx,%rdi
mov    $0x200000,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <readNbInst+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"File %s does not exist\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @readNbInst(i8* %0) {
%2 = alloca [2097152 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 [2097152 x i8], [2097152 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %4, i32 2097152, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %14
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6, %14
%15 = phi i32 [ %19, %14 ], [ 0, %6 ]
%16 = call i32 @strlen(i8* %4)
%17 = icmp sgt i32 %16, 5
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %15, %18
%20 = call i64 @fgets(i8* %4, i32 2097152, i32* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %14
22: ; preds = %14, %6
%23 = phi i32 [ 0, %6 ], [ %19, %14 ]
%24 = call i32 @fclose(i32* %3)
ret i32 %23
}