#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);
void write_x_y_to_file(char *name, double *x, double *y, 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\n", x[i], y[i]);
  }
  fclose(out);
}


x86 assembly (clang, -O0):
<write_x_y_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1186 <write_x_y_to_file+0x46>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1040 <ewe@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d1 <write_x_y_to_file+0x91>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118d <write_x_y_to_file+0x4d>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_x_y_to_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
je     1172 <write_x_y_to_file+0x32>
test   %r12d,%r12d
jg     1186 <write_x_y_to_file+0x46>
jmp    11c0 <write_x_y_to_file+0x80>
lea    0xe89(%rip),%rdi
mov    %rbp,%rsi
call   1040 <ewe@plt>
test   %r12d,%r12d
jle    11c0 <write_x_y_to_file+0x80>
mov    %r12d,%ebp
xor    %ebx,%ebx
lea    0xe87(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <write_x_y_to_file+0x60>
mov    %r13,%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 = [9 x i8] c"%le %le\0A\00"
define void @write_x_y_to_file(i8* %0, double* %1, double* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i32 @ewe(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %4
store i32 0, i32* %9
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = load i32*, i32** %10
%25 = load double*, double** %6
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load double*, double** %7
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %29, double %34)
br label %36
36: ; preds = %23
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %19
39: ; preds = %19
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
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 = [9 x i8] c"%le %le\0A\00"
define void @write_x_y_to_file(i8* %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @ewe(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %4
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %22
11: ; preds = %9
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = getelementptr inbounds double, double* %1, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %2, i64 %14
%18 = load double, double* %17
%19 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), double %16, double %18)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13, %9
%23 = tail call i32 @fclose(i32* %5)
ret void
}