#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 EOF;
int fscanf(int /*<<< orphan*/ *, char *, double *);
int ReadVectorFromOpenFile(double *x, int n, FILE *fp) {
  int i, e;
  if (NULL == x || NULL == fp)
    return EOF;
  for (i = 0; i < n; i++) {
    e = fscanf(fp, "%le", &x[i]);
    if (EOF == e)
      return e;
  }
  return i;
}


x86 assembly (clang, -O0):
<ReadVectorFromOpenFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     113b <ReadVectorFromOpenFile+0x2b>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    114c <ReadVectorFromOpenFile+0x3c>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <ReadVectorFromOpenFile+0xa7>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b1 <ReadVectorFromOpenFile+0xa1>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe87(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
cmp    -0x28(%rbp),%eax
jne    119e <ReadVectorFromOpenFile+0x8e>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <ReadVectorFromOpenFile+0xa7>
jmp    11a3 <ReadVectorFromOpenFile+0x93>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1153 <ReadVectorFromOpenFile+0x43>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadVectorFromOpenFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <ReadVectorFromOpenFile+0x60>
mov    %rdx,%r12
test   %rdx,%rdx
je     1170 <ReadVectorFromOpenFile+0x60>
mov    %esi,%r14d
test   %esi,%esi
jle    117c <ReadVectorFromOpenFile+0x6c>
mov    %rdi,%rbp
mov    %r14d,%ebx
lea    0xec4(%rip),%r15
mov    0x2ea5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <fscanf@plt>
cmp    %eax,0x0(%r13)
je     1181 <ReadVectorFromOpenFile+0x71>
add    $0x8,%rbp
add    $0xffffffffffffffff,%rbx
jne    1150 <ReadVectorFromOpenFile+0x40>
jmp    1184 <ReadVectorFromOpenFile+0x74>
mov    0x2e71(%rip),%rax
mov    (%rax),%r14d
jmp    1184 <ReadVectorFromOpenFile+0x74>
xor    %r14d,%r14d
jmp    1184 <ReadVectorFromOpenFile+0x74>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%le\00"
define i32 @ReadVectorFromOpenFile(double* %0, i32 %1, i32* %2) {
%4 = icmp eq double* %0, null
%5 = icmp eq i32* %2, null
%6 = or i1 %4, %5
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %22
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %13
11: ; preds = %3
%12 = load i32, i32* @EOF
br label %22
13: ; preds = %9, %19
%14 = phi i64 [ 0, %9 ], [ %20, %19 ]
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %17, %16
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %13
22: ; preds = %13, %19, %7, %11
%23 = phi i32 [ %12, %11 ], [ 0, %7 ], [ %16, %13 ], [ %1, %19 ]
ret i32 %23
}