#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
unsigned int countLines(char *filename) {
  FILE *myFile = fopen(filename, "r");
  if (myFile == NULL) {
    fprintf(stderr, "Can't read the job descriptor %s\n", filename);
    exit(1);
  }
  int ch, nol = 0;
  do {
    ch = fgetc(myFile);
    if (ch == '\n')
      nol++;
  } while (ch != EOF);
  if (ch != '\n' && nol != 0)
    nol++;
  fclose(myFile);
  return nol;
}


x86 assembly (clang, -O0):
<countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <countLines+0x4e>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe73(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    11c4 <countLines+0x74>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c9 <countLines+0x79>
mov    -0x14(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    11a5 <countLines+0x55>
cmpl   $0xa,-0x14(%rbp)
je     11f8 <countLines+0xa8>
cmpl   $0x0,-0x18(%rbp)
je     11f8 <countLines+0xa8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bb <countLines+0x6b>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    0x2e74(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
cmp    (%r14),%eax
jne    1180 <countLines+0x30>
cmp    $0xa,%eax
setne  %al
test   %ebp,%ebp
setne  %cl
and    %al,%cl
movzbl %cl,%r14d
add    %ebp,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Can't read the job descriptor %s\0A\00"
@EOF = global i32 0
define i32 @countLines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%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
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
store i32 0, i32* %5
br label %16
16: ; preds = %25, %15
%17 = load i32*, i32** %3
%18 = call i32 @fgetc(i32* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %24
24: ; preds = %21, %16
br label %25
25: ; preds = %24
%26 = load i32, i32* %4
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %16, label %29
29: ; preds = %25
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35, %32, %29
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [34 x i8] c"Can't read the job descriptor %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 %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1, %8
%9 = phi i32 [ %13, %8 ], [ 0, %1 ]
%10 = tail call i32 @fgetc(i32* %2)
%11 = icmp eq i32 %10, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %9, %12
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %10, %14
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = icmp ne i32 %10, 10
%18 = icmp ne i32 %13, 0
%19 = select i1 %17, i1 %18, i1 false
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %13, %20
%22 = tail call i32 @fclose(i32* %2)
ret i32 %21
}