#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 *, char *);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
void write_double_array(double array[], int size, char *fileName) {
  FILE *file = fopen(fileName, "wb");
  int i;
  for (i = 0; i < size; i++) {
    double f = array[i];
    fwrite(&f, sizeof(double), 1, file);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<write_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a1 <write_double_array+0x71>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <write_double_array+0x2e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_double_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeb8(%rip),%rsi
mov    %rdx,%rdi
call   1040 <fopen@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    118a <write_double_array+0x5a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1050 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <write_double_array+0x30>
mov    %r12,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

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