#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;
scalar_t__ ferror(int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int readNDoubles(FILE *fp, double *vals, int nvals) {
  register int i;
  int n, j;
  for (i = n = 0; i < nvals; ++i) {
    j = fscanf(fp, "%lf", vals + i);
    if (j == EOF)
      return EOF;
    if (j != 1 || ferror(fp))
      return EOF - 1;
    n += j;
  }
  return n;
}


x86 assembly (clang, -O0):
<readNDoubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11da <readNDoubles+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xe99(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%eax
jne    1192 <readNDoubles+0x72>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <readNDoubles+0xc0>
cmpl   $0x1,-0x28(%rbp)
jne    11af <readNDoubles+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11c3 <readNDoubles+0xa3>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <readNDoubles+0xc0>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1141 <readNDoubles+0x21>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readNDoubles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1189 <readNDoubles+0x69>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %edx,%ebp
mov    0x2ea7(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
lea    0xea6(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
mov    0x0(%r13),%r14d
cmp    %r14d,%eax
je     1197 <readNDoubles+0x77>
cmp    $0x1,%eax
jne    118e <readNDoubles+0x6e>
mov    %r12,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    118e <readNDoubles+0x6e>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1150 <readNDoubles+0x30>
jmp    119a <readNDoubles+0x7a>
xor    %r15d,%r15d
jmp    119a <readNDoubles+0x7a>
add    $0xffffffff,%r14d
mov    %r14d,%r15d
jmp    119a <readNDoubles+0x7a>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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