#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*/ 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
    fscanf(file, " %d", np);
  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++)
      fscanf(file, " %lf\n", a + i);
  }
  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    12cd <svdLoadDenseArray+0x15d>
cmpb   $0x0,-0x19(%rbp)
je     11d6 <svdLoadDenseArray+0x66>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <svd_readBinInt@plt>
jmp    11ec <svdLoadDenseArray+0x7c>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
xor    %esi,%esi
lea    0xe28(%rip),%rdx
call   1050 <svd_doubleArray@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1222 <svdLoadDenseArray+0xb2>
movq   $0x0,-0x8(%rbp)
jmp    12cd <svdLoadDenseArray+0x15d>
cmpb   $0x0,-0x19(%rbp)
je     1275 <svdLoadDenseArray+0x105>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1270 <svdLoadDenseArray+0x100>
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    1233 <svdLoadDenseArray+0xc3>
jmp    12bc <svdLoadDenseArray+0x14c>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12b7 <svdLoadDenseArray+0x147>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127c <svdLoadDenseArray+0x10c>
jmp    12bc <svdLoadDenseArray+0x14c>
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   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1080 <svd_readFile@plt>
test   %rax,%rax
je     11f5 <svdLoadDenseArray+0x85>
mov    %rax,%r14
test   %bpl,%bpl
je     1208 <svdLoadDenseArray+0x98>
mov    %r14,%rdi
mov    %r15,%rsi
call   1090 <svd_readBinInt@plt>
mov    (%r15),%r15d
lea    0xe7e(%rip),%rdx
mov    %r15d,%edi
xor    %esi,%esi
call   1050 <svd_doubleArray@plt>
test   %rax,%rax
je     1204 <svdLoadDenseArray+0x94>
mov    %rax,%rbx
test   %r15d,%r15d
jle    126a <svdLoadDenseArray+0xfa>
xor    %ebp,%ebp
lea    0xc(%rsp),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <svd_readBinFloat@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    11d0 <svdLoadDenseArray+0x60>
jmp    126a <svdLoadDenseArray+0xfa>
lea    0xe04(%rip),%rdi
mov    %rbx,%rsi
call   1030 <svd_error@plt>
xor    %ebx,%ebx
jmp    1272 <svdLoadDenseArray+0x102>
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%r15),%r15d
lea    0xe03(%rip),%rdx
mov    %r15d,%edi
xor    %esi,%esi
call   1050 <svd_doubleArray@plt>
test   %rax,%rax
je     1204 <svdLoadDenseArray+0x94>
mov    %rax,%rbx
test   %r15d,%r15d
jle    126a <svdLoadDenseArray+0xfa>
shl    $0x3,%r15
lea    0xdf6(%rip),%r12
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x8,%rbp
cmp    %rbp,%r15
jne    1250 <svdLoadDenseArray+0xe0>
mov    %r14,%rdi
call   1070 <svd_closeFile@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"svdLoadDenseArray: failed to read %s\00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [21 x i8] c"svdLoadDenseArray: a\00"
@.str.3 = [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 %80
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 %31
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)
br label %31
31: ; preds = %27, %23
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = call double* @svd_doubleArray(i32 %34, i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store double* %35, double** %10
%36 = load double*, double** %10
%37 = icmp ne double* %36, null
br i1 %37, label %39, label %38
38: ; preds = %31
store double* null, double** %4
br label %80
39: ; preds = %31
%40 = load i8, i8* %7
%41 = icmp ne i8 %40, 0
br i1 %41, label %42, label %60
42: ; preds = %39
store i32 0, i32* %8
br label %43
43: ; preds = %56, %42
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %59
47: ; preds = %43
%48 = load i32*, i32** %11
%49 = call i32 @svd_readBinFloat(i32* %48, float* %12)
%50 = load float, float* %12
%51 = fpext float %50 to double
%52 = load double*, double** %10
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %51, double* %55
br label %56
56: ; preds = %47
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %43
59: ; preds = %43
br label %76
60: ; preds = %39
store i32 0, i32* %8
br label %61
61: ; preds = %72, %60
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %75
65: ; preds = %61
%66 = load i32*, i32** %11
%67 = load double*, double** %10
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = call i32 (i32*, i8*, ...) @fscanf(i32* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* %70)
br label %72
72: ; preds = %65
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %61
75: ; preds = %61
br label %76
76: ; preds = %75, %59
%77 = load i32*, i32** %11
%78 = call i32 @svd_closeFile(i32* %77)
%79 = load double*, double** %10
store double* %79, double** %4
br label %80
80: ; preds = %76, %38, %17
%81 = load double*, double** %4
ret double* %81
}

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