#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int countLines(FILE *fpin) {
  int numlines, pos;
  char line[100];
  pos = ftell(fpin);
  fseek(fpin, 0, SEEK_SET);
  numlines = 0;
  while (fgets(line, 100, fpin) != NULL)
    numlines++;
  fseek(fpin, pos, SEEK_SET);
  return (numlines);
}


x86 assembly (clang, -O0):
<countLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
movl   $0x0,-0xc(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1190 <countLines+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <countLines+0x36>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countLines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %eax,%r14d
mov    0x2e92(%rip),%r12
mov    (%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    $0xffffffff,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1170 <countLines+0x40>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <fseek@plt>
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @countLines(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @ftell(i32* %6)
store i32 %7, i32* %4
%8 = load i32*, i32** %2
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %8, i32 0, i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %16, %1
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32* @fgets(i8* %12, i32 100, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %11
19: ; preds = %11
%20 = load i32*, i32** %2
%21 = load i32, i32* %4
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %20, i32 %21, i32 %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @countLines(i32* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @ftell(i32* %0)
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 0, i32 %5)
br label %7
7: ; preds = %7, %1
%8 = phi i32 [ 0, %1 ], [ %11, %7 ]
%9 = call i32* @fgets(i8* %3, i32 100, i32* %0)
%10 = icmp eq i32* %9, null
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %12, label %7
12: ; preds = %7
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %0, i32 %4, i32 %13)
ret i32 %8
}