#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*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ svd_closeFile(int /*<<< orphan*/ *);
void svd_error(char *, char *);
int /*<<< orphan*/ svd_writeBinFloat(int /*<<< orphan*/ *, float);
int /*<<< orphan*/ svd_writeBinInt(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *svd_writeFile(char *, int /*<<< orphan*/);
void svdWriteDenseArray(double *a, int n, char *filename, char binary) {
  int i;
  FILE *file = svd_writeFile(filename, 0);
  if (!file)
    return svd_error("svdWriteDenseArray: failed to write %s", filename);
  if (binary) {
    svd_writeBinInt(file, n);
    for (i = 0; i < n; i++)
      svd_writeBinFloat(file, (float)a[i]);
  } else {
    fprintf(file, "%d\n", n);
    for (i = 0; i < n; i++)
      fprintf(file, "%g\n", a[i]);
  }
  svd_closeFile(file);
}


x86 assembly (clang, -O0):
<svdWriteDenseArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1070 <svd_writeFile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a7 <svdWriteDenseArray+0x47>
mov    -0x18(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1040 <svd_error@plt>
jmp    125e <svdWriteDenseArray+0xfe>
cmpb   $0x0,-0x19(%rbp)
je     11fd <svdWriteDenseArray+0x9d>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <svd_writeBinInt@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f8 <svdWriteDenseArray+0x98>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <svd_writeBinFloat@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c4 <svdWriteDenseArray+0x64>
jmp    1255 <svdWriteDenseArray+0xf5>
mov    -0x28(%rbp),%rdi
cvtsi2sdl -0xc(%rbp),%xmm0
lea    0xe1a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1250 <svdWriteDenseArray+0xf0>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdee(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1219 <svdWriteDenseArray+0xb9>
jmp    1255 <svdWriteDenseArray+0xf5>
mov    -0x28(%rbp),%rdi
call   1080 <svd_closeFile@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svdWriteDenseArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %esi,%r12d
mov    %rdi,%r14
mov    %rdx,%rdi
xor    %esi,%esi
call   1070 <svd_writeFile@plt>
test   %rax,%rax
je     11cd <svdWriteDenseArray+0x6d>
mov    %rax,%r13
test   %r15b,%r15b
je     11ea <svdWriteDenseArray+0x8a>
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <svd_writeBinInt@plt>
test   %r12d,%r12d
jle    122a <svdWriteDenseArray+0xca>
mov    %r12d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  (%r14,%rbx,8),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %r13,%rdi
call   1050 <svd_writeBinFloat@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <svdWriteDenseArray+0x50>
jmp    122a <svdWriteDenseArray+0xca>
lea    0xe2c(%rip),%rdi
mov    %rbp,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <svd_error@plt>
cvtsi2sd %r12d,%xmm0
lea    0xe31(%rip),%rsi
mov    %r13,%rdi
call   1060 <fprintf@plt>
test   %r12d,%r12d
jle    122a <svdWriteDenseArray+0xca>
mov    %r12d,%r12d
xor    %ebp,%ebp
lea    0xe1c(%rip),%r15
nop
movsd  (%r14,%rbp,8),%xmm0
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1210 <svdWriteDenseArray+0xb0>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <svd_closeFile@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"svdWriteDenseArray: failed to write %s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%g\0A\00"
define void @svdWriteDenseArray(double* %0, i32 %1, i8* %2, i8 signext %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32*
store double* %0, double** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%11 = load i8*, i8** %7
%12 = call i32* @svd_writeFile(i8* %11, i32 0)
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %4
%16 = load i8*, i8** %7
br label %65
17: ; preds = %4
%18 = load i8, i8* %8
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load i32*, i32** %10
%22 = load i32, i32* %6
%23 = call i32 @svd_writeBinInt(i32* %21, i32 %22)
store i32 0, i32* %9
br label %24
24: ; preds = %37, %20
%25 = load i32, i32* %9
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32*, i32** %10
%30 = load double*, double** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fptrunc double %34 to float
%36 = call i32 @svd_writeBinFloat(i32* %29, float %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %24
40: ; preds = %24
br label %62
41: ; preds = %17
%42 = load i32*, i32** %10
%43 = load i32, i32* %6
%44 = sitofp i32 %43 to double
%45 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %44)
store i32 0, i32* %9
br label %46
46: ; preds = %58, %41
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = load i32*, i32** %10
%52 = load double*, double** %5
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = call i32 @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %56)
br label %58
58: ; preds = %50
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
br label %46
61: ; preds = %46
br label %62
62: ; preds = %61, %40
%63 = load i32*, i32** %10
%64 = call i32 @svd_closeFile(i32* %63)
br label %65
65: ; preds = %62, %15
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"svdWriteDenseArray: failed to write %s\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%g\0A\00"
define void @svdWriteDenseArray(double* nocapture %0, i32 %1, i8* %2, i8 signext %3) {
%5 = tail call i32* @svd_writeFile(i8* %2, i32 0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %4
tail call void @svd_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %38
8: ; preds = %4
%9 = icmp eq i8 %3, 0
br i1 %9, label %23, label %10
10: ; preds = %8
%11 = tail call i32 @svd_writeBinInt(i32* %5, i32 %1)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %36
13: ; preds = %10
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %21, %15 ]
%17 = getelementptr inbounds double, double* %0, i64 %16
%18 = load double, double* %17
%19 = fptrunc double %18 to float
%20 = tail call i32 @svd_writeBinFloat(i32* %5, float %19)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %14
br i1 %22, label %36, label %15
23: ; preds = %8
%24 = sitofp i32 %1 to double
%25 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = icmp sgt i32 %1, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = zext i32 %1 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %34, %29 ]
%31 = getelementptr inbounds double, double* %0, i64 %30
%32 = load double, double* %31
%33 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = add nuw nsw i64 %30, 1
%35 = icmp eq i64 %34, %28
br i1 %35, label %36, label %29
36: ; preds = %15, %29, %10, %23
%37 = tail call i32 @svd_closeFile(i32* %5)
br label %38
38: ; preds = %36, %7
ret void
}