#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 size_t uint32_t;
typedef size_t int64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double atof(char *);
char *calloc(size_t, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int64_t _load_file_scalar(char *fname, uint32_t len, double *data) {
  int64_t i;
  FILE *f;
  char *line;
  size_t linelen;
  f = NULL;
  line = NULL;
  linelen = 200;
  i = 0;
  line = calloc(linelen, sizeof(char));
  if (line == NULL)
    goto fail;
  f = fopen(fname, "rt");
  if (f == NULL)
    goto fail;
  while (getline(&line, &linelen, f) > 0 && i < len) {
    data[i] = atof(line);
    i++;
  }
  free(line);
  fclose(f);
  return i;
fail:
  if (f != NULL)
    fclose(f);
  if (line != NULL)
    free(line);
  return -1;
}


x86 assembly (clang, -O0):
<_load_file_scalar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0xc8,-0x40(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b6 <_load_file_scalar+0x56>
jmp    1266 <_load_file_scalar+0x106>
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11da <_load_file_scalar+0x7a>
jmp    1266 <_load_file_scalar+0x106>
jmp    11df <_load_file_scalar+0x7f>
mov    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <getline@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x41(%rbp)
jle    1210 <_load_file_scalar+0xb0>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1220 <_load_file_scalar+0xc0>
jmp    1247 <_load_file_scalar+0xe7>
mov    -0x38(%rbp),%rdi
call   1040 <atof@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11df <_load_file_scalar+0x7f>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1296 <_load_file_scalar+0x136>
cmpq   $0x0,-0x30(%rbp)
je     127a <_load_file_scalar+0x11a>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x38(%rbp)
je     128e <_load_file_scalar+0x12e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_load_file_scalar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movq   $0xc8,0x10(%rsp)
mov    $0xc8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,0x8(%rsp)
mov    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1238 <_load_file_scalar+0xd8>
mov    %rax,%rbp
lea    0xe52(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1230 <_load_file_scalar+0xd0>
mov    %rax,%r12
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    121c <_load_file_scalar+0xbc>
test   %r15,%r15
je     121c <_load_file_scalar+0xbc>
xor    %ebx,%ebx
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1040 <atof@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1080 <getline@plt>
test   %rax,%rax
jle    121c <_load_file_scalar+0xbc>
cmp    %r15,%rbx
jb     11f0 <_load_file_scalar+0x90>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
jmp    1238 <_load_file_scalar+0xd8>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
define i64 @_load_file_scalar(i8* %0, i64 %1, double* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca double*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store double* %2, double** %7
store i32* null, i32** %9
store i8* null, i8** %10
store i64 200, i64* %11
store i64 0, i64* %8
%12 = load i64, i64* %11
%13 = call i8* @calloc(i64 %12, i32 1)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
br label %48
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
br label %48
23: ; preds = %17
br label %24
24: ; preds = %34, %23
%25 = load i32*, i32** %9
%26 = call i64 @getline(i8** %10, i64* %11, i32* %25)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i64, i64* %8
%30 = load i64, i64* %6
%31 = icmp ult i64 %29, %30
br label %32
32: ; preds = %28, %24
%33 = phi i1 [ false, %24 ], [ %31, %28 ]
br i1 %33, label %34, label %42
34: ; preds = %32
%35 = load i8*, i8** %10
%36 = call double @atof(i8* %35)
%37 = load double*, double** %7
%38 = load i64, i64* %8
%39 = getelementptr inbounds double, double* %37, i64 %38
store double %36, double* %39
%40 = load i64, i64* %8
%41 = add i64 %40, 1
store i64 %41, i64* %8
br label %24
42: ; preds = %32
%43 = load i8*, i8** %10
%44 = call i32 @free(i8* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
%47 = load i64, i64* %8
store i64 %47, i64* %4
br label %61
48: ; preds = %22, %16
%49 = load i32*, i32** %9
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %48
%55 = load i8*, i8** %10
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i8*, i8** %10
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %57, %54
store i64 -1, i64* %4
br label %61
61: ; preds = %60, %42
%62 = load i64, i64* %4
ret i64 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i64 @_load_file_scalar(i8* nocapture %0, i64 %1, double* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
%7 = bitcast i64* %5 to i8*
store i64 200, i64* %5
%8 = tail call i8* @calloc(i64 200, i32 1)
store i8* %8, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %35, label %10
10: ; preds = %3
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %13
13: ; preds = %10
%14 = call i64 @getline(i8** %4, i64* %5, i32* %11)
%15 = icmp sgt i64 %14, 0
%16 = icmp ne i64 %1, 0
%17 = and i1 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %13, %18
%19 = phi i64 [ %23, %18 ], [ 0, %13 ]
%20 = load i8*, i8** %4
%21 = call double @atof(i8* %20)
%22 = getelementptr inbounds double, double* %2, i64 %19
store double %21, double* %22
%23 = add nuw i64 %19, 1
%24 = call i64 @getline(i8** %4, i64* %5, i32* %11)
%25 = icmp sgt i64 %24, 0
%26 = icmp ult i64 %23, %1
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %18, label %28
28: ; preds = %18, %13
%29 = phi i64 [ 0, %13 ], [ %23, %18 ]
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
%32 = call i32 @fclose(i32* %11)
br label %35
33: ; preds = %10
%34 = tail call i32 @free(i8* %8)
br label %35
35: ; preds = %3, %33, %28
%36 = phi i64 [ %29, %28 ], [ -1, %33 ], [ -1, %3 ]
ret i64 %36
}