#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ yap_sysquit(char *, char *, ...);
void read_dvec(char *dfile, int N, double *d) {
  int i;
  FILE *fp = fopen(dfile, "r");
  if (!fp)
    yap_sysquit("Cannot open file '%s' for read\n", dfile);
  for (i = 0; i < N; i++) {
    if (!fscanf(fp, " %lg", &d[i])) {
      yap_sysquit("Cannot read from '%s' position %d\n", dfile, i);
    }
  }
  if (ferror(fp))
    yap_sysquit("Error on reading file '%s' ", dfile);
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_dvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <read_dvec+0x44>
mov    -0x8(%rbp),%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f7 <read_dvec+0xa7>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe61(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x0,%eax
jne    11e4 <read_dvec+0x94>
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
jmp    11e9 <read_dvec+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119b <read_dvec+0x4b>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     121c <read_dvec+0xcc>
mov    -0x8(%rbp),%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1070 <yap_sysquit@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_dvec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     117d <read_dvec+0x2d>
test   %ebp,%ebp
jg     1192 <read_dvec+0x42>
jmp    11d4 <read_dvec+0x84>
lea    0xe7e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
test   %ebp,%ebp
jle    11d4 <read_dvec+0x84>
mov    %ebp,%r13d
lea    0xe86(%rip),%r12
xor    %ebp,%ebp
jmp    11ad <read_dvec+0x5d>
add    $0x1,%rbp
add    $0x8,%rbx
cmp    %rbp,%r13
je     11d4 <read_dvec+0x84>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
test   %eax,%eax
jne    11a0 <read_dvec+0x50>
lea    0xe61(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
jmp    11a0 <read_dvec+0x50>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11f2 <read_dvec+0xa2>
lea    0xe62(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <yap_sysquit@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"Cannot open file '%s' for read\0A\00"
@.str.2 = [5 x i8] c" %lg\00"
@.str.3 = [35 x i8] c"Cannot read from '%s' position %d\0A\00"
@.str.4 = [28 x i8] c"Error on reading file '%s' \00"
define void @read_dvec(i8* %0, i32 %1, double* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store double* %2, double** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %3
store i32 0, i32* %7
br label %17
17: ; preds = %34, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load i32*, i32** %8
%23 = load double*, double** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %30, i32 %31)
br label %33
33: ; preds = %29, %21
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %17
37: ; preds = %17
%38 = load i32*, i32** %8
%39 = call i64 @ferror(i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %37
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"Cannot open file '%s' for read\0A\00"
@.str.2 = [5 x i8] c" %lg\00"
@.str.3 = [35 x i8] c"Cannot read from '%s' position %d\0A\00"
@.str.4 = [28 x i8] c"Error on reading file '%s' \00"
define void @read_dvec(i8* %0, i32 %1, double* %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %23
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %20
%13 = phi i64 [ 0, %10 ], [ %21, %20 ]
%14 = getelementptr inbounds double, double* %2, i64 %13
%15 = tail call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = trunc i64 %13 to i32
%19 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %18)
br label %20
20: ; preds = %12, %17
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %20, %8
%24 = tail call i64 @ferror(i32* %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = tail call i32 (i8*, i8*, ...) @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %26, %23
%29 = tail call i32 @fclose(i32* %4)
ret void
}