#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int write_file_ascii(char *, double *, int);
int write_file_bin(char *, double *, int);
int main(int argc, char **argv) {
  double *data;
  int i;
  int asciitime, bintime;
  data = (double *)malloc(1024 * 1024 * 128 * sizeof(double));
  assert(data);
  for (i = 0; i < 1024 * 1024 * 128; i++) {
    data[i] = i * (double)i / 2.;
  }
  asciitime = write_file_ascii("data.txt", data, 1024 * 1024 * 128);
  bintime = write_file_bin("data.dat", data, 1024 * 1024 * 128);
  printf("Time to write files: ASCII: %d, Binary: %d\n", asciitime, bintime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x40000000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000000,-0x1c(%rbp)
jge    11c6 <main+0x76>
cvtsi2sdl -0x1c(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe59(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <main+0x34>
mov    -0x18(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x8000000,%edx
call   1030 <write_file_ascii@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x8000000,%edx
call   1070 <write_file_bin@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x40000000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
movdqa 0xe90(%rip),%xmm0
mov    $0x6,%eax
movdqa 0xe93(%rip),%xmm1
movapd 0xe9b(%rip),%xmm2
movdqa 0xea3(%rip),%xmm3
movdqa 0xeab(%rip),%xmm4
movdqa 0xeb3(%rip),%xmm5
nopl   (%rax)
movdqa %xmm0,%xmm6
cvtdq2pd %xmm0,%xmm7
paddd  %xmm1,%xmm6
cvtdq2pd %xmm6,%xmm6
mulpd  %xmm7,%xmm7
mulpd  %xmm6,%xmm6
mulpd  %xmm2,%xmm7
mulpd  %xmm2,%xmm6
movupd %xmm7,-0x30(%rbx,%rax,8)
movupd %xmm6,-0x20(%rbx,%rax,8)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
cvtdq2pd %xmm6,%xmm6
paddd  %xmm4,%xmm7
cvtdq2pd %xmm7,%xmm7
mulpd  %xmm6,%xmm6
mulpd  %xmm7,%xmm7
mulpd  %xmm2,%xmm6
mulpd  %xmm2,%xmm7
movupd %xmm6,-0x10(%rbx,%rax,8)
movupd %xmm7,(%rbx,%rax,8)
paddd  %xmm5,%xmm0
add    $0x8,%rax
cmp    $0x8000006,%rax
jne    11a0 <main+0x50>
lea    0xe4a(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000000,%edx
call   1030 <write_file_ascii@plt>
mov    %eax,%ebp
lea    0xe3d(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8000000,%edx
call   1070 <write_file_bin@plt>
lea    0xe32(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [9 x i8] c"data.dat\00"
@.str.2 = [44 x i8] c"Time to write files: ASCII: %d, Binary: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @malloc(i32 1073741824)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %6
%12 = load double*, double** %6
%13 = call i32 @assert(double* %12)
store i32 0, i32* %7
br label %14
14: ; preds = %28, %2
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 134217728
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i32, i32* %7
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
%22 = fmul double %19, %21
%23 = fdiv double %22, 2.000000e+00
%24 = load double*, double** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %23, double* %27
br label %28
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %14
31: ; preds = %14
%32 = load double*, double** %6
%33 = call i32 @write_file_ascii(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double* %32, i32 134217728)
store i32 %33, i32* %8
%34 = load double*, double** %6
%35 = call i32 @write_file_bin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double* %34, i32 134217728)
store i32 %35, i32* %9
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [9 x i8] c"data.dat\00"
@.str.2 = [44 x i8] c"Time to write files: ASCII: %d, Binary: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 1073741824)
%4 = inttoptr i64 %3 to double*
%5 = tail call i32 @assert(double* %4)
br label %6
6: ; preds = %6, %2
%7 = phi i64 [ 0, %2 ], [ %33, %6 ]
%8 = phi <2 x i32> [ <i32 0, i32 1>, %2 ], [ %34, %6 ]
%9 = add <2 x i32> %8, <i32 2, i32 2>
%10 = sitofp <2 x i32> %8 to <2 x double>
%11 = sitofp <2 x i32> %9 to <2 x double>
%12 = fmul <2 x double> %10, %10
%13 = fmul <2 x double> %11, %11
%14 = fmul <2 x double> %12, <double 5.000000e-01, double 5.000000e-01>
%15 = fmul <2 x double> %13, <double 5.000000e-01, double 5.000000e-01>
%16 = getelementptr inbounds double, double* %4, i64 %7
%17 = bitcast double* %16 to <2 x double>*
store <2 x double> %14, <2 x double>* %17
%18 = getelementptr inbounds double, double* %16, i64 2
%19 = bitcast double* %18 to <2 x double>*
store <2 x double> %15, <2 x double>* %19
%20 = or i64 %7, 4
%21 = add <2 x i32> %8, <i32 4, i32 4>
%22 = add <2 x i32> %8, <i32 6, i32 6>
%23 = sitofp <2 x i32> %21 to <2 x double>
%24 = sitofp <2 x i32> %22 to <2 x double>
%25 = fmul <2 x double> %23, %23
%26 = fmul <2 x double> %24, %24
%27 = fmul <2 x double> %25, <double 5.000000e-01, double 5.000000e-01>
%28 = fmul <2 x double> %26, <double 5.000000e-01, double 5.000000e-01>
%29 = getelementptr inbounds double, double* %4, i64 %20
%30 = bitcast double* %29 to <2 x double>*
store <2 x double> %27, <2 x double>* %30
%31 = getelementptr inbounds double, double* %29, i64 2
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> %28, <2 x double>* %32
%33 = add nuw nsw i64 %7, 8
%34 = add <2 x i32> %8, <i32 8, i32 8>
%35 = icmp eq i64 %33, 134217728
br i1 %35, label %36, label %6
36: ; preds = %6
%37 = tail call i32 @write_file_ascii(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double* %4, i32 134217728)
%38 = tail call i32 @write_file_bin(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double* %4, i32 134217728)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %37, i32 %38)
ret i32 0
}