#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 EOF;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int line_count(FILE *f) {
  int c = 0, n = 0;
  for (c = getc(f); c != EOF; c = getc(f))
    if (c == '\n')
      n++;
  rewind(f);
  printf("lines=%d\n", n);
  return n;
}


x86 assembly (clang, -O0):
<line_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
je     1191 <line_count+0x61>
cmpl   $0xa,-0xc(%rbp)
jne    117b <line_count+0x4b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <line_count+0x50>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
jmp    1156 <line_count+0x26>
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line_count>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <getc@plt>
mov    0x2ea5(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%eax
je     1167 <line_count+0x37>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r14),%eax
jne    1150 <line_count+0x20>
mov    %rbx,%rdi
call   1040 <rewind@plt>
lea    0xe8a(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [10 x i8] c"lines=%d\0A\00"
define i32 @line_count(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = load i32*, i32** %2
%6 = call i32 @getc(i32* %5)
store i32 %6, i32* %3
br label %7
7: ; preds = %18, %1
%8 = load i32, i32* %3
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %17
%19 = load i32*, i32** %2
%20 = call i32 @getc(i32* %19)
store i32 %20, i32* %3
br label %7
21: ; preds = %7
%22 = load i32*, i32** %2
%23 = call i32 @rewind(i32* %22)
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [10 x i8] c"lines=%d\0A\00"
define i32 @line_count(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %14, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %10, %5 ], [ 0, %1 ]
%7 = phi i32 [ %11, %5 ], [ %2, %1 ]
%8 = icmp eq i32 %7, 10
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = tail call i32 @getc(i32* %0)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %5
14: ; preds = %5, %1
%15 = phi i32 [ 0, %1 ], [ %10, %5 ]
%16 = tail call i32 @rewind(i32* %0)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 %15
}