#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ stderr;
int load_beta(double *beta, char *filename, int p) {
  int i = 0;
  FILE *in = NULL;
  if (!(in = fopen(filename, "rt"))) {
    fprintf(stderr, "can't open file %s\n", filename);
    return 0;
  };
  while (!feof(in)) {
    if (fscanf(in, "%lf", beta + i) == EOF)
      break;
    i++;
  }
  fclose(in);
  return 1;
}


x86 assembly (clang, -O0):
<load_beta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b5 <load_beta+0x65>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122a <load_beta+0xda>
jmp    11ba <load_beta+0x6a>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d8 <load_beta+0x88>
jmp    121a <load_beta+0xca>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe25(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
jne    120c <load_beta+0xbc>
jmp    121a <load_beta+0xca>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ba <load_beta+0x6a>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_beta>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe9b(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c3 <load_beta+0x73>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11b4 <load_beta+0x64>
lea    0xe8f(%rip),%r15
mov    0x2e59(%rip),%r12
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    (%r12),%rax
je     11b4 <load_beta+0x64>
mov    %r14,%rdi
call   1060 <feof@plt>
add    $0x8,%rbx
test   %eax,%eax
je     1190 <load_beta+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11dd <load_beta+0x8d>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"can't open file %s\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@EOF = global i64 0
define i32 @load_beta(double* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store double* %0, double** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32* null, i32** %9
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %9
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %6
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 0, i32* %4
br label %39
17: ; preds = %3
br label %18
18: ; preds = %33, %17
%19 = load i32*, i32** %9
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load i32*, i32** %9
%25 = load double*, double** %5
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = call i64 @fscanf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %28)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %23
br label %36
33: ; preds = %23
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %18
36: ; preds = %32, %18
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
store i32 1, i32* %4
br label %39
39: ; preds = %36, %13
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"can't open file %s\0A\00"
@.str.2 = [4 x i8] c"%lf\00"
@EOF = global i64 0
define i32 @load_beta(double* %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %16, label %22
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %24
12: ; preds = %16
%13 = add nuw i64 %17, 1
%14 = tail call i32 @feof(i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %6, %12
%17 = phi i64 [ %13, %12 ], [ 0, %6 ]
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = tail call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double* %18)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %12
22: ; preds = %12, %16, %6
%23 = tail call i32 @fclose(i32* %4)
br label %24
24: ; preds = %22, %9
%25 = phi i32 [ 1, %22 ], [ 0, %9 ]
ret i32 %25
}