#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*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int count_lines_in_file(FILE *file) {
  int count = 0;
  while (!feof(file)) {
    int current_char = fgetc(file);
    if (current_char == '\n') {
      count++;
    }
  }
  rewind(file);
  return count;
}


x86 assembly (clang, -O0):
<count_lines_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1161 <count_lines_in_file+0x31>
jmp    1185 <count_lines_in_file+0x55>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jne    1180 <count_lines_in_file+0x50>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <count_lines_in_file+0x13>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines_in_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    116e <count_lines_in_file+0x3e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1150 <count_lines_in_file+0x20>
mov    %rbx,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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