#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*/ *);
int /*<<< orphan*/ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int FileOfDoublesSize(FILE *fin) {
  int z = -1;
  double x;
  while (!feof(fin)) {
    fread(&x, sizeof(double), 1, fin);
    z++;
  }
  fseek(fin, 0, SEEK_SET);
  return z;
}


x86 assembly (clang, -O0):
<FileOfDoublesSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1161 <FileOfDoublesSize+0x31>
jmp    1186 <FileOfDoublesSize+0x56>
mov    -0x8(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <FileOfDoublesSize+0x13>
mov    -0x8(%rbp),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <fseek@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileOfDoublesSize>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <feof@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
jne    1184 <FileOfDoublesSize+0x54>
mov    $0xffffffff,%ebp
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %eax,%eax
je     1160 <FileOfDoublesSize+0x30>
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @FileOfDoublesSize(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca double
store i32* %0, i32** %2
store i32 -1, i32* %3
br label %5
5: ; preds = %10, %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 %15
10: ; preds = %5
%11 = load i32*, i32** %2
%12 = call i32 @fread(double* %4, i32 8, i32 1, i32* %11)
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %5
15: ; preds = %5
%16 = load i32*, i32** %2
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @FileOfDoublesSize(i32* nocapture %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = tail call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ -1, %1 ]
%8 = call i32 @fread(double* %2, i32 8, i32 1, i32* %0)
%9 = add nsw i32 %7, 1
%10 = tail call i32 @feof(i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %6, %1
%13 = phi i32 [ -1, %1 ], [ %9, %6 ]
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %0, i32 0, i32 %14)
ret i32 %13
}