#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*/ ewe(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double,
                           double);
void write_x_y_z_to_file(char *name, double *x, double *y, double *z, int len) {
  int i;
  FILE *out;
  out = fopen(name, "w");
  if (out == NULL) {
    ewe("Error writing file %s\n", name);
  }
  for (i = 0; i < len; i++) {
    fprintf(out, "%le %le %le\n", x[i], y[i], z[i]);
  }
  fclose(out);
}


x86 assembly (clang, -O0):
<write_x_y_z_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118b <write_x_y_z_to_file+0x4b>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <ewe@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11e3 <write_x_y_z_to_file+0xa3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1192 <write_x_y_z_to_file+0x52>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_x_y_z_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1175 <write_x_y_z_to_file+0x35>
test   %r13d,%r13d
jg     1189 <write_x_y_z_to_file+0x49>
jmp    11ba <write_x_y_z_to_file+0x7a>
lea    0xe86(%rip),%rdi
mov    %rbp,%rsi
call   1040 <ewe@plt>
test   %r13d,%r13d
jle    11ba <write_x_y_z_to_file+0x7a>
mov    %r13d,%ebp
xor    %r13d,%r13d
nop
movsd  (%r12,%r13,8),%xmm0
movsd  (%r15,%r13,8),%xmm1
movsd  (%r14,%r13,8),%xmm2
mov    %rbx,%rdi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
jne    1190 <write_x_y_z_to_file+0x50>
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 = [23 x i8] c"Error writing file %s\0A\00"
@.str.2 = [13 x i8] c"%le %le %le\0A\00"
define void @write_x_y_z_to_file(i8* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i8*, i8** %6
%19 = call i32 @ewe(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %5
store i32 0, i32* %11
br label %21
21: ; preds = %43, %20
%22 = load i32, i32* %11
%23 = load i32, i32* %10
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = load i32*, i32** %12
%27 = load double*, double** %7
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double*, double** %8
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %9
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), double %31, double %36, double %41)
br label %43
43: ; preds = %25
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %21
46: ; preds = %21
%47 = load i32*, i32** %12
%48 = call i32 @fclose(i32* %47)
ret void
}

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