#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*/ d;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long fvecs_fsize(const char *fname, int *d_out, int *n_out) {
  int d, ret;
  long nbytes;
  FILE *f = fopen(fname, "r");
  ret = fread(&d, sizeof(d), 1, f);
  if (ret == 0) {
    return ret;
  }
  fseek(f, 0, SEEK_END);
  nbytes = ftell(f);
  fclose(f);
  assert(nbytes % (d + 1) == 0);
  *d_out = d;
  *n_out = nbytes / (4 * d + 4);
  return nbytes;
}


x86 assembly (clang, -O0):
<fvecs_fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11b9 <fvecs_fsize+0x59>
movslq -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1234 <fvecs_fsize+0xd4>
mov    -0x38(%rbp),%rdi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x2,%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
cqto
idiv   %rcx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvecs_fsize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     11df <fvecs_fsize+0x7f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%eax
movslq %eax,%rbx
lea    0x1(%rbx),%rcx
mov    %r12,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11e4 <fvecs_fsize+0x84>
mov    %r12,%rax
cqto
idiv   %rcx
jmp    11eb <fvecs_fsize+0x8b>
xor    %r12d,%r12d
jmp    1224 <fvecs_fsize+0xc4>
mov    %r12d,%eax
xor    %edx,%edx
div    %ecx
xor    %edi,%edi
test   %rdx,%rdx
sete   %dil
call   1050 <assert@plt>
mov    %ebx,(%r15)
lea    0x4(,%rbx,4),%rcx
mov    %r12,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     121a <fvecs_fsize+0xba>
mov    %r12,%rax
cqto
idiv   %rcx
jmp    1221 <fvecs_fsize+0xc1>
mov    %r12d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,(%r14)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i64 @fvecs_fsize(i8* %0, i32* %1, i32* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = call i32 @fread(i32* %8, i32 4, i32 1, i32* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
store i64 %20, i64* %4
br label %48
21: ; preds = %3
%22 = load i32*, i32** %11
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %11
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %10
%27 = load i32*, i32** %11
%28 = call i32 @fclose(i32* %27)
%29 = load i64, i64* %10
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = srem i64 %29, %32
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i32, i32* %8
%38 = load i32*, i32** %6
store i32 %37, i32* %38
%39 = load i64, i64* %10
%40 = load i32, i32* %8
%41 = mul nsw i32 4, %40
%42 = add nsw i32 %41, 4
%43 = sext i32 %42 to i64
%44 = sdiv i64 %39, %43
%45 = trunc i64 %44 to i32
%46 = load i32*, i32** %7
store i32 %45, i32* %46
%47 = load i64, i64* %10
store i64 %47, i64* %4
br label %48
48: ; preds = %21, %18
%49 = load i64, i64* %4
ret i64 %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i64 @fvecs_fsize(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @fread(i32* %4, i32 4, i32 1, i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %3
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %6, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %6)
%13 = tail call i32 @fclose(i32* %6)
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = srem i64 %12, %16
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
store i32 %14, i32* %1
%21 = shl nsw i32 %14, 2
%22 = add nsw i32 %21, 4
%23 = sext i32 %22 to i64
%24 = sdiv i64 %12, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %2
br label %26
26: ; preds = %3, %9
%27 = phi i64 [ %12, %9 ], [ 0, %3 ]
ret i64 %27
}