#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*/ *);
unsigned get_line_count(FILE *fp) {
  unsigned line_count = 1;
  char c = '\0';
  while ((c = fgetc(fp)) != EOF) {
    if (c == '\n') {
      line_count++;
    }
  }
  rewind(fp);
  return line_count;
}


x86 assembly (clang, -O0):
<get_line_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
mov    0x2e9b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1173 <get_line_count+0x53>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    116e <get_line_count+0x4e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1137 <get_line_count+0x17>
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line_count>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <fgetc@plt>
mov    0x2eb5(%rip),%r14
mov    $0x1,%ebp
cmp    (%r14),%al
je     1166 <get_line_count+0x46>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%al
jne    1150 <get_line_count+0x30>
mov    %rbx,%rdi
call   1030 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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