#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void snPrintArrayDouble(const char *fn, const double *x, int size) {
  FILE *f;
  int i;
  f = fopen(fn, "w");
  for (i = 0; i < size; i++) {
    if (i % 10 == 0)
      fprintf(f, "\n");
    fprintf(f, "%f ", x[i]);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<snPrintArrayDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bd <snPrintArrayDouble+0x8d>
mov    -0x24(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1190 <snPrintArrayDouble+0x60>
mov    -0x20(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe5c(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <snPrintArrayDouble+0x2e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snPrintArrayDouble>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11c7 <snPrintArrayDouble+0x87>
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe93(%rip),%r15
xor    %r13d,%r13d
jmp    119f <snPrintArrayDouble+0x5f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%r13,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r13
add    $0xffffffff,%ebp
cmp    %r13,%r12
je     11c7 <snPrintArrayDouble+0x87>
mov    %r13d,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
add    %eax,%eax
add    %ebp,%eax
jne    1180 <snPrintArrayDouble+0x40>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    1180 <snPrintArrayDouble+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c"%f \00"
define void @snPrintArrayDouble(i8* %0, double* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
store i32 0, i32* %8
br label %11
11: ; preds = %30, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %8
%17 = srem i32 %16, 10
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32*, i32** %7
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %15
%23 = load i32*, i32** %7
%24 = load double*, double** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %11
33: ; preds = %11
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
ret void
}

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