#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double const);
scalar_t__ time(int /*<<< orphan*/ *);
int write_file_ascii(const char *fname, const double *data, const int ndata) {
  FILE *fp;
  time_t start, end;
  int i;
  fp = fopen(fname, "wb");
  assert(fp);
  start = time(NULL);
  for (i = 0; i < ndata; i++) {
    fprintf(fp, "%lf\n", data[i]);
  }
  end = time(NULL);
  fclose(fp);
  return (int)(end - start);
}


x86 assembly (clang, -O0):
<write_file_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cb <write_file_ascii+0x7b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1194 <write_file_ascii+0x44>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file_ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <assert@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    11aa <write_file_ascii+0x5a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe73(%rip),%r12
movsd  (%r14,%rbx,8),%xmm0
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <write_file_ascii+0x40>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1030 <fclose@plt>
sub    %r15d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [5 x i8] c"%lf\0A\00"
define i32 @write_file_ascii(i8* nocapture %0, double* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @assert(i32* %4)
%6 = tail call i64 @time(i32* null)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds double, double* %1, i64 %11
%13 = load double, double* %12
%14 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %13)
%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 i64 @time(i32* null)
%19 = tail call i32 @fclose(i32* %4)
%20 = sub nsw i64 %18, %6
%21 = trunc i64 %20 to i32
ret i32 %21
}