#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 */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
void read_data(char *path, double *buff, int size) {
  FILE *fpr;
  double tmp;
  struct stat filestat;
  int ended;
  if ((fpr = fopen(path, "r")) == NULL) {
    printf("file not found\n");
    exit(1);
  }
  stat(path, &filestat);
  if (filestat.st_size != size * sizeof(double)) {
    printf("wrong file size\n");
    exit(1);
  }
  ended = 0;
  while (1) {
    ended += fread(buff + ended, 1, sizeof(double) * size - ended, fpr);
    if (ended >= sizeof(double) * size)
      break;
  }
  fclose(fpr);
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a7 <read_data+0x47>
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <stat@plt>
movslq -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
je     11df <read_data+0x7f>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
movslq -0x34(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
jb     123b <read_data+0xdb>
jmp    1240 <read_data+0xe0>
jmp    11e6 <read_data+0x86>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e7 <read_data+0x87>
mov    %rax,%r12
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <stat@plt>
movslq 0x8(%rsp),%rbp
movslq %r15d,%rax
shl    $0x3,%rax
cmp    %rbp,%rax
jne    11f0 <read_data+0x90>
xor    %eax,%eax
nopl   0x0(%rax)
movslq %eax,%rbx
lea    (%r14,%rbx,8),%rdi
mov    %ebp,%edx
sub    %ebx,%edx
mov    $0x1,%esi
mov    %r12,%rcx
call   1040 <fread@plt>
add    %rbx,%rax
movslq %eax,%rcx
cmp    %rbp,%rcx
jb     11b0 <read_data+0x50>
mov    %r12,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xe24(%rip),%rdi
jmp    11f7 <read_data+0x97>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [16 x i8] c"file not found\0A\00"
@.str.2 = [17 x i8] c"wrong file size\0A\00"
define void @read_data(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double
%9 = alloca %struct.stat
%10 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @stat(i8* %18, %struct.stat* %9)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = icmp ne i64 %22, %25
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
store i32 0, i32* %10
br label %31
31: ; preds = %30, %56
%32 = load double*, double** %5
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = mul i64 8, %37
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = sub i64 %38, %40
%42 = trunc i64 %41 to i32
%43 = load i32*, i32** %7
%44 = call i64 @fread(double* %35, i32 1, i32 %42, i32* %43)
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = add nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = sext i32 %49 to i64
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = mul i64 8, %52
%54 = icmp uge i64 %50, %53
br i1 %54, label %55, label %56
55: ; preds = %31
br label %57
56: ; preds = %31
br label %31
57: ; preds = %55
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@str = [16 x i8] c"wrong file size\00"
@str.3 = [15 x i8] c"file not found\00"
define void @read_data(i8* nocapture %0, double* nocapture %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %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 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = call i32 @stat(i8* %0, %struct.stat* %4)
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = sext i32 %2 to i64
%17 = shl nsw i64 %16, 3
%18 = icmp eq i64 %17, %15
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %11, %22
%23 = phi i64 [ %30, %22 ], [ 0, %11 ]
%24 = shl i64 %23, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = trunc i64 %23 to i32
%28 = sub i32 %14, %27
%29 = tail call i64 @fread(double* %26, i32 1, i32 %28, i32* %6)
%30 = add nsw i64 %25, %29
%31 = shl i64 %30, 32
%32 = ashr exact i64 %31, 32
%33 = icmp ult i64 %32, %15
br i1 %33, label %22, label %34
34: ; preds = %22
%35 = tail call i32 @fclose(i32* %6)
ret void
}