#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*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
char *get_next_line_from_file(int /*<<< orphan*/ *);
int get_lines_total_from_file(FILE *fp) {
  int t = 0;
  char *line = NULL;
  if (fp == NULL) {
    return 0;
  }
  fseek(fp, 0L, SEEK_SET);
  line = get_next_line_from_file(fp);
  while (line != NULL) {
    t++;
    line = get_next_line_from_file(fp);
    free(line);
  }
  fseek(fp, 0L, SEEK_SET);
  return t;
}


x86 assembly (clang, -O0):
<get_lines_total_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1162 <get_lines_total_from_file+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <get_lines_total_from_file+0xa0>
mov    -0x10(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <get_next_line_from_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b4 <get_lines_total_from_file+0x84>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <get_next_line_from_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1185 <get_lines_total_from_file+0x55>
mov    -0x10(%rbp),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_lines_total_from_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     119c <get_lines_total_from_file+0x6c>
mov    %rdi,%r14
mov    0x2e99(%rip),%r12
mov    (%r12),%edx
xor    %r15d,%r15d
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %r14,%rdi
call   1050 <get_next_line_from_file@plt>
test   %rax,%rax
je     118c <get_lines_total_from_file+0x5c>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r15d
mov    %r14,%rdi
call   1050 <get_next_line_from_file@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
jne    1170 <get_lines_total_from_file+0x40>
mov    (%r12),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
jmp    119f <get_lines_total_from_file+0x6f>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @get_lines_total_from_file(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
store i32* %0, i32** %3
store i32 0, i32* %4
store i8* null, i8** %5
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %30
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @fseek(i32* %10, i64 0, i32 %11)
%13 = load i32*, i32** %3
%14 = call i8* @get_next_line_from_file(i32* %13)
store i8* %14, i8** %5
br label %15
15: ; preds = %18, %9
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32*, i32** %3
%22 = call i8* @get_next_line_from_file(i32* %21)
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
br label %15
25: ; preds = %15
%26 = load i32*, i32** %3
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i64 0, i32 %27)
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %8
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @get_lines_total_from_file(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %0, i64 0, i32 %4)
%6 = tail call i8* @get_next_line_from_file(i32* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %3, %8
%9 = phi i32 [ %10, %8 ], [ 0, %3 ]
%10 = add nuw nsw i32 %9, 1
%11 = tail call i8* @get_next_line_from_file(i32* %0)
%12 = tail call i32 @free(i8* %11)
%13 = icmp eq i8* %11, null
br i1 %13, label %14, label %8
14: ; preds = %8, %3
%15 = phi i32 [ 0, %3 ], [ %10, %8 ]
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %0, i64 0, i32 %16)
br label %18
18: ; preds = %1, %14
%19 = phi i32 [ %15, %14 ], [ 0, %1 ]
ret i32 %19
}