#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 count_lines(FILE *fp) {
  int n_lines;
  char ch;
  if (fp) {
    while (!feof(fp)) {
      ch = fgetc(fp);
      if (ch == '\n') {
        n_lines++;
      }
    }
  }
  return n_lines;
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1186 <count_lines+0x66>
jmp    113c <count_lines+0x1c>
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    115a <count_lines+0x3a>
jmp    1181 <count_lines+0x61>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    117c <count_lines+0x5c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113c <count_lines+0x1c>
jmp    1186 <count_lines+0x66>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     115f <count_lines+0x3f>
mov    %rdi,%rbx
call   1040 <feof@plt>
test   %eax,%eax
jne    115f <count_lines+0x3f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     1140 <count_lines+0x20>
jmp    115f <count_lines+0x3f>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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