#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;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int NumLines(FILE *file, int *longline) {
  int i = 0, j = 0;
  char c;
  *longline = 0;
  do {
    c = fgetc(file);
    j++;
    if (c == '\n') {
      i++;
      if (j > *longline)
        *longline = j;
      j = 0;
    }
  } while (c != EOF);
  *longline += 1;
  rewind(file);
  return i;
}


x86 assembly (clang, -O0):
<NumLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1192 <NumLines+0x72>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    118b <NumLines+0x6b>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x18(%rbp)
jmp    1197 <NumLines+0x77>
movsbl -0x19(%rbp),%eax
mov    0x2e46(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1148 <NumLines+0x28>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NumLines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
movl   $0x0,(%rsi)
xor    %ebx,%ebx
mov    0x2eab(%rip),%r15
xor    %ebp,%ebp
jmp    1159 <NumLines+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %edx,%ecx
mov    %ecx,%ebx
cmp    (%r15),%al
je     1177 <NumLines+0x57>
mov    %r12,%rdi
call   1040 <fgetc@plt>
lea    0x1(%rbx),%edx
cmp    $0xa,%al
jne    1150 <NumLines+0x30>
add    $0x1,%ebp
xor    %ecx,%ecx
cmp    (%r14),%ebx
jl     1152 <NumLines+0x32>
mov    %edx,(%r14)
jmp    1152 <NumLines+0x32>
addl   $0x1,(%r14)
mov    %r12,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @NumLines(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i32*, i32** %4
store i32 0, i32* %8
br label %9
9: ; preds = %29, %2
%10 = load i32*, i32** %3
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %7
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
%14 = load i8, i8* %7
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %28
17: ; preds = %9
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i32, i32* %6
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = icmp sgt i32 %20, %22
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %6
%26 = load i32*, i32** %4
store i32 %25, i32* %26
br label %27
27: ; preds = %24, %17
store i32 0, i32* %6
br label %28
28: ; preds = %27, %9
br label %29
29: ; preds = %28
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %9, label %35
35: ; preds = %29
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
%39 = load i32*, i32** %3
%40 = call i32 @rewind(i32* %39)
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @NumLines(i32* nocapture %0, i32* nocapture %1) {
store i32 0, i32* %1
br label %3
3: ; preds = %14, %2
%4 = phi i32 [ 0, %2 ], [ %15, %14 ]
%5 = phi i32 [ 0, %2 ], [ %16, %14 ]
%6 = tail call signext i8 @fgetc(i32* %0)
%7 = add nsw i32 %4, 1
%8 = icmp eq i8 %6, 10
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = add nsw i32 %5, 1
%11 = load i32, i32* %1
%12 = icmp slt i32 %4, %11
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 %7, i32* %1
br label %14
14: ; preds = %9, %13, %3
%15 = phi i32 [ %7, %3 ], [ 0, %13 ], [ 0, %9 ]
%16 = phi i32 [ %5, %3 ], [ %10, %13 ], [ %10, %9 ]
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %6, %17
br i1 %18, label %19, label %3
19: ; preds = %14
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
%22 = tail call i32 @rewind(i32* %0)
ret i32 %16
}