#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*/ *);
unsigned int count_lines(FILE *fp) {
  unsigned int count = 1;
  char character;
  while ((character = fgetc(fp))) {
    if (character == EOF) {
      break;
    }
    if (character == '\n') {
      count++;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0xd(%rbp)
cmp    $0x0,%al
je     116d <count_lines+0x5d>
movsbl -0xd(%rbp),%eax
mov    0x2ea6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1152 <count_lines+0x42>
jmp    116d <count_lines+0x5d>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1168 <count_lines+0x58>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <count_lines+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <fgetc@plt>
mov    $0x1,%ebp
test   %al,%al
je     115d <count_lines+0x4d>
mov    0x2ebc(%rip),%r14
cmp    (%r14),%al
je     115d <count_lines+0x4d>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%ecx
xor    %ebp,%ebp
cmp    $0xa,%al
sete   %bpl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1030 <fgetc@plt>
test   %al,%al
je     115d <count_lines+0x4d>
cmp    (%r14),%al
jne    1140 <count_lines+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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