#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*/ SEEK_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int contarighe(FILE *dove) {
  char ch;
  int ret = 0;
  while (!feof(dove)) {
    ch = fgetc(dove);
    if (ch == '\n')
      ret++;
  }
  fseek(dove, 0, SEEK_SET);
  return ret;
}


x86 assembly (clang, -O0):
<contarighe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1161 <contarighe+0x31>
jmp    1188 <contarighe+0x58>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1183 <contarighe+0x53>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <contarighe+0x13>
mov    -0x8(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<contarighe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    116d <contarighe+0x3d>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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     1150 <contarighe+0x20>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @contarighe(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
br label %5
5: ; preds = %19, %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 %20
10: ; preds = %5
%11 = load i32*, i32** %2
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %3
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %10
br label %5
20: ; preds = %5
%21 = load i32*, i32** %2
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @contarighe(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 signext i8 @fgetc(i32* %0)
%7 = icmp eq i8 %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 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %0, i32 0, i32 %14)
ret i32 %13
}