#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int count_lines(FILE *ptr) {
  rewind(ptr);
  char ch;
  int count = 0;
  while (1) {
    ch = getc(ptr);
    if (ch == EOF)
      break;
    if (ch == '\n')
      count++;
  }
  return (count);
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    0x2e95(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1163 <count_lines+0x43>
jmp    117e <count_lines+0x5e>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1179 <count_lines+0x59>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <count_lines+0x1c>
mov    -0x10(%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 <rewind@plt>
mov    %rbx,%rdi
call   1040 <getc@plt>
mov    0x2ead(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%al
je     1166 <count_lines+0x46>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <getc@plt>
cmp    (%r14),%al
jne    1150 <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 i8
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @rewind(i32* %5)
store i32 0, i32* %4
br label %7
7: ; preds = %1, %23
%8 = load i32*, i32** %2
%9 = call signext i8 @getc(i32* %8)
store i8 %9, i8* %3
%10 = load i8, i8* %3
%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 = %7
br label %24
16: ; preds = %7
%17 = load i8, i8* %3
%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* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %16
br label %7
24: ; preds = %15
%25 = load i32, i32* %4
ret i32 %25
}

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