#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int enough_lines(FILE *fp, int N) {
  char ch;
  int lines = 0;
  while (!feof(fp)) {
    ch = fgetc(fp);
    if (ch == '\n')
      lines++;
  }
  rewind(fp);
  return lines >= N;
}


x86 assembly (clang, -O0):
<enough_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1164 <enough_lines+0x34>
jmp    118b <enough_lines+0x5b>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1186 <enough_lines+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <enough_lines+0x16>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enough_lines>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    116d <enough_lines+0x3d>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1150 <enough_lines+0x20>
mov    %rbx,%rdi
call   1030 <rewind@plt>
xor    %eax,%eax
cmp    %r14d,%ebp
setge  %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @enough_lines(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %7
7: ; preds = %21, %2
%8 = load i32*, i32** %3
%9 = call i32 @feof(i32* %8)
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %5
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %21
21: ; preds = %18, %12
br label %7
22: ; preds = %7
%23 = load i32*, i32** %3
%24 = call i32 @rewind(i32* %23)
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp sge i32 %25, %26
%28 = zext i1 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
define i32 @enough_lines(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @feof(i32* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %2, %5
%6 = phi i32 [ %10, %5 ], [ 0, %2 ]
%7 = tail call signext i8 @fgetc(i32* %0)
%8 = icmp eq i8 %7, 10
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = tail call i32 @feof(i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %5, label %13
13: ; preds = %5, %2
%14 = phi i32 [ 0, %2 ], [ %10, %5 ]
%15 = tail call i32 @rewind(i32* %0)
%16 = icmp sge i32 %14, %1
%17 = zext i1 %16 to i32
ret i32 %17
}