#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 fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ svd_closeFile(int /*<<< orphan*/ *);
double *svd_doubleArray(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ svd_error(char *, char *);
int /*<<< orphan*/ svd_readBinFloat(int /*<<< orphan*/ *, float *);
int /*<<< orphan*/ svd_readBinInt(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ *svd_readFile(char *);
double *svdLoadDenseArray(char *filename, int *np, char binary) {
  int i, n;
  double *a;
  FILE *file = svd_readFile(filename);
  if (!file) {
    svd_error("svdLoadDenseArray: failed to read %s", filename);
    return NULL;
  }
  if (binary) {
    svd_readBinInt(file, np);
  } else if (fscanf(file, " %d", np) != 1) {
    svd_error("svdLoadDenseArray: error reading %s", filename);
    svd_closeFile(file);
    return NULL;
  }
  n = *np;
  a = svd_doubleArray(n, 0, "svdLoadDenseArray: a");
  if (!a)
    return NULL;
  if (binary) {
    float f;
    for (i = 0; i < n; i++) {
      svd_readBinFloat(file, &f);
      a[i] = f;
    }
  } else {
    for (i = 0; i < n; i++) {
      if (fscanf(file, " %lf\n", a + i) != 1) {
        svd_error("svdLoadDenseArray: error reading %s", filename);
        break;
      }
    }
  }
  svd_closeFile(file);
  return a;
}


x86 assembly (clang, -O0):
<svdLoadDenseArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <svd_readFile@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ba <svdLoadDenseArray+0x4a>
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1030 <svd_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1324 <svdLoadDenseArray+0x1b4>
cmpb   $0x0,-0x19(%rbp)
je     11d6 <svdLoadDenseArray+0x66>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <svd_readBinInt@plt>
jmp    1220 <svdLoadDenseArray+0xb0>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     121b <svdLoadDenseArray+0xab>
mov    -0x10(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1030 <svd_error@plt>
mov    -0x38(%rbp),%rdi
call   1070 <svd_closeFile@plt>
movq   $0x0,-0x8(%rbp)
jmp    1324 <svdLoadDenseArray+0x1b4>
jmp    1220 <svdLoadDenseArray+0xb0>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
xor    %esi,%esi
lea    0xe18(%rip),%rdx
call   1050 <svd_doubleArray@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1256 <svdLoadDenseArray+0xe6>
movq   $0x0,-0x8(%rbp)
jmp    1324 <svdLoadDenseArray+0x1b4>
cmpb   $0x0,-0x19(%rbp)
je     12a9 <svdLoadDenseArray+0x139>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12a4 <svdLoadDenseArray+0x134>
mov    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
call   1060 <svd_readBinFloat@plt>
movss  -0x3c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1267 <svdLoadDenseArray+0xf7>
jmp    1313 <svdLoadDenseArray+0x1a3>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130e <svdLoadDenseArray+0x19e>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     12fb <svdLoadDenseArray+0x18b>
mov    -0x10(%rbp),%rsi
lea    0xd38(%rip),%rdi
call   1030 <svd_error@plt>
jmp    130e <svdLoadDenseArray+0x19e>
jmp    1300 <svdLoadDenseArray+0x190>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12b0 <svdLoadDenseArray+0x140>
jmp    1313 <svdLoadDenseArray+0x1a3>
mov    -0x38(%rbp),%rdi
call   1070 <svd_closeFile@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svdLoadDenseArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
call   1080 <svd_readFile@plt>
test   %rax,%rax
je     1202 <svdLoadDenseArray+0x92>
mov    %rax,%r14
test   %bpl,%bpl
je     1216 <svdLoadDenseArray+0xa6>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <svd_readBinInt@plt>
mov    (%rbx),%ebx
lea    0xea0(%rip),%rdx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <svd_doubleArray@plt>
test   %rax,%rax
je     129d <svdLoadDenseArray+0x12d>
mov    %rax,%r13
test   %ebx,%ebx
jle    11f5 <svdLoadDenseArray+0x85>
xor    %ebp,%ebp
lea    0x4(%rsp),%r15
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <svd_readBinFloat@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x0(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <svdLoadDenseArray+0x60>
mov    %r14,%rdi
call   1070 <svd_closeFile@plt>
jmp    12a0 <svdLoadDenseArray+0x130>
lea    0xdf7(%rip),%rdi
mov    %r15,%rsi
call   1030 <svd_error@plt>
jmp    129d <svdLoadDenseArray+0x12d>
lea    0xe08(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1286 <svdLoadDenseArray+0x116>
mov    (%rbx),%r12d
lea    0xe14(%rip),%rdx
mov    %r12d,%edi
xor    %esi,%esi
call   1050 <svd_doubleArray@plt>
test   %rax,%rax
je     129d <svdLoadDenseArray+0x12d>
mov    %rax,%r13
test   %r12d,%r12d
jle    11f5 <svdLoadDenseArray+0x85>
shl    $0x3,%r12
lea    0xe07(%rip),%rbx
xor    %ebp,%ebp
nopl   (%rax)
mov    %r13,%rdx
add    %rbp,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    12b2 <svdLoadDenseArray+0x142>
add    $0x8,%rbp
cmp    %rbp,%r12
jne    1260 <svdLoadDenseArray+0xf0>
jmp    11f5 <svdLoadDenseArray+0x85>
lea    0xd9c(%rip),%rdi
mov    %r15,%rsi
call   1030 <svd_error@plt>
mov    %r14,%rdi
call   1070 <svd_closeFile@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd70(%rip),%rdi
mov    %r15,%rsi
call   1030 <svd_error@plt>
jmp    11f5 <svdLoadDenseArray+0x85>

LLVM IR (-O0):
@.str = [37 x i8] c"svdLoadDenseArray: failed to read %s\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [36 x i8] c"svdLoadDenseArray: error reading %s\00"
@.str.3 = [21 x i8] c"svdLoadDenseArray: a\00"
@.str.4 = [6 x i8] c" %lf\0A\00"
define double* @svdLoadDenseArray(i8* %0, i32* %1, i8 signext %2) {
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32*
%12 = alloca float
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8 %2, i8* %7
%13 = load i8*, i8** %5
%14 = call i32* @svd_readFile(i8* %13)
store i32* %14, i32** %11
%15 = load i32*, i32** %11
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32 @svd_error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %18)
store double* null, double** %4
br label %92
20: ; preds = %3
%21 = load i8, i8* %7
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32*, i32** %11
%25 = load i32*, i32** %6
%26 = call i32 @svd_readBinInt(i32* %24, i32* %25)
br label %38
27: ; preds = %20
%28 = load i32*, i32** %11
%29 = load i32*, i32** %6
%30 = call i32 (i32*, i8*, ...) @fscanf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = icmp ne i32 %30, 1
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i32 @svd_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %11
%36 = call i32 @svd_closeFile(i32* %35)
store double* null, double** %4
br label %92
37: ; preds = %27
br label %38
38: ; preds = %37, %23
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = call double* @svd_doubleArray(i32 %41, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store double* %42, double** %10
%43 = load double*, double** %10
%44 = icmp ne double* %43, null
br i1 %44, label %46, label %45
45: ; preds = %38
store double* null, double** %4
br label %92
46: ; preds = %38
%47 = load i8, i8* %7
%48 = icmp ne i8 %47, 0
br i1 %48, label %49, label %67
49: ; preds = %46
store i32 0, i32* %8
br label %50
50: ; preds = %63, %49
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i32*, i32** %11
%56 = call i32 @svd_readBinFloat(i32* %55, float* %12)
%57 = load float, float* %12
%58 = fpext float %57 to double
%59 = load double*, double** %10
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double %58, double* %62
br label %63
63: ; preds = %54
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %50
66: ; preds = %50
br label %88
67: ; preds = %46
store i32 0, i32* %8
br label %68
68: ; preds = %84, %67
%69 = load i32, i32* %8
%70 = load i32, i32* %9
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %87
72: ; preds = %68
%73 = load i32*, i32** %11
%74 = load double*, double** %10
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %74, i64 %76
%78 = call i32 (i32*, i8*, ...) @fscanf(i32* %73, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double* %77)
%79 = icmp ne i32 %78, 1
br i1 %79, label %80, label %83
80: ; preds = %72
%81 = load i8*, i8** %5
%82 = call i32 @svd_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %81)
br label %87
83: ; preds = %72
br label %84
84: ; preds = %83
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
store i32 %86, i32* %8
br label %68
87: ; preds = %80, %68
br label %88
88: ; preds = %87, %66
%89 = load i32*, i32** %11
%90 = call i32 @svd_closeFile(i32* %89)
%91 = load double*, double** %10
store double* %91, double** %4
br label %92
92: ; preds = %88, %45, %32, %17
%93 = load double*, double** %4
ret double* %93
}

LLVM IR (-O2):
@.str = [37 x i8] c"svdLoadDenseArray: failed to read %s\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [36 x i8] c"svdLoadDenseArray: error reading %s\00"
@.str.3 = [21 x i8] c"svdLoadDenseArray: a\00"
@.str.4 = [6 x i8] c" %lf\0A\00"
define double* @svdLoadDenseArray(i8* %0, i32* %1, i8 signext %2) {
%4 = alloca float
%5 = tail call i32* @svd_readFile(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @svd_error(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %57
9: ; preds = %3
%10 = icmp eq i8 %2, 0
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @svd_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 @svd_closeFile(i32* %5)
br label %57
17: ; preds = %11
%18 = load i32, i32* %1
%19 = tail call double* @svd_doubleArray(i32 %18, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq double* %19, null
br i1 %20, label %57, label %21
21: ; preds = %17
%22 = icmp sgt i32 %18, 0
br i1 %22, label %23, label %54
23: ; preds = %21
%24 = zext i32 %18 to i64
br label %46
25: ; preds = %9
%26 = tail call i32 @svd_readBinInt(i32* %5, i32* %1)
%27 = load i32, i32* %1
%28 = tail call double* @svd_doubleArray(i32 %27, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq double* %28, null
br i1 %29, label %57, label %30
30: ; preds = %25
%31 = bitcast float* %4 to i8*
%32 = icmp sgt i32 %27, 0
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = zext i32 %27 to i64
br label %35
35: ; preds = %33, %35
%36 = phi i64 [ 0, %33 ], [ %41, %35 ]
%37 = call i32 @svd_readBinFloat(i32* %5, float* %4)
%38 = load float, float* %4
%39 = fpext float %38 to double
%40 = getelementptr inbounds double, double* %28, i64 %36
store double %39, double* %40
%41 = add nuw nsw i64 %36, 1
%42 = icmp eq i64 %41, %34
br i1 %42, label %43, label %35
43: ; preds = %35, %30
br label %54
44: ; preds = %46
%45 = icmp eq i64 %51, %24
br i1 %45, label %54, label %46
46: ; preds = %23, %44
%47 = phi i64 [ 0, %23 ], [ %51, %44 ]
%48 = getelementptr inbounds double, double* %19, i64 %47
%49 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double* %48)
%50 = icmp eq i32 %49, 1
%51 = add nuw nsw i64 %47, 1
br i1 %50, label %44, label %52
52: ; preds = %46
%53 = tail call i32 @svd_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %54
54: ; preds = %44, %21, %52, %43
%55 = phi double* [ %19, %52 ], [ %28, %43 ], [ %19, %21 ], [ %19, %44 ]
%56 = call i32 @svd_closeFile(i32* %5)
br label %57
57: ; preds = %25, %17, %54, %14, %7
%58 = phi double* [ %55, %54 ], [ null, %14 ], [ null, %7 ], [ null, %17 ], [ null, %25 ]
ret double* %58
}