#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*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ printf(char *);
int Lab3SaveOutput(double *x, int size, double Time) {
  FILE *op;
  int i;
  if ((op = fopen("data_output", "w")) == NULL) {
    printf("Error opening the output file.\n");
    return 1;
  }
  fprintf(op, "%d\n", size);
  for (i = 0; i < size; ++i)
    fprintf(op, "%e\t", x[i]);
  fprintf(op, "\n%lf", Time);
  fclose(op);
  return 0;
}


x86 assembly (clang, -O0):
<Lab3SaveOutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
lea    0xea5(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118d <Lab3SaveOutput+0x4d>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <Lab3SaveOutput+0xc5>
mov    -0x28(%rbp),%rdi
cvtsi2sdl -0x14(%rbp),%xmm0
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e0 <Lab3SaveOutput+0xa0>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe65(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a9 <Lab3SaveOutput+0x69>
mov    -0x28(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Lab3SaveOutput>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11db <Lab3SaveOutput+0x9b>
mov    %rax,%r12
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
test   %ebp,%ebp
jle    11ba <Lab3SaveOutput+0x7a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe7b(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <Lab3SaveOutput+0x60>
lea    0xe55(%rip),%rsi
mov    %r12,%rdi
movsd  0x8(%rsp),%xmm0
call   1050 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11ec <Lab3SaveOutput+0xac>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"data_output\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [32 x i8] c"Error opening the output file.\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"%e\09\00"
@.str.5 = [5 x i8] c"\0A%lf\00"
define i32 @Lab3SaveOutput(double* %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32*
%9 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %40
14: ; preds = %3
%15 = load i32*, i32** %8
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to double
%18 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %17)
store i32 0, i32* %9
br label %19
19: ; preds = %31, %14
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32*, i32** %8
%25 = load double*, double** %5
%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 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %19
34: ; preds = %19
%35 = load i32*, i32** %8
%36 = load double, double* %7
%37 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %36)
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %4
br label %40
40: ; preds = %34, %12
%41 = load i32, i32* %4
ret i32 %41
}

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