#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 Lab4_saveoutput(double *R, int nodecount, double Time) {
  FILE *op;
  int i;
  if ((op = fopen("data_output", "w")) == NULL) {
    printf("Error opening the input file.\n");
    return 1;
  }
  fprintf(op, "%d\n%f\n", nodecount, Time);
  for (i = 0; i < nodecount; ++i)
    fprintf(op, "%e\n", R[i]);
  fclose(op);
  return 0;
}


x86 assembly (clang, -O0):
<Lab4_saveoutput>:
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 <Lab4_saveoutput+0x4d>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <Lab4_saveoutput+0xb9>
mov    -0x28(%rbp),%rdi
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe8b(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <Lab4_saveoutput+0xa9>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe60(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b0 <Lab4_saveoutput+0x70>
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):
<Lab4_saveoutput>:
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     11c8 <Lab4_saveoutput+0x88>
mov    %rax,%r12
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1050 <fprintf@plt>
test   %ebp,%ebp
jle    11bc <Lab4_saveoutput+0x7c>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe76(%rip),%r15
nop
movsd  (%r14,%rbx,8),%xmm0
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <Lab4_saveoutput+0x60>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11d9 <Lab4_saveoutput+0x99>
lea    0xe4a(%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 = [31 x i8] c"Error opening the input file.\0A\00"
@.str.3 = [7 x i8] c"%d\0A%f\0A\00"
@.str.4 = [4 x i8] c"%e\0A\00"
define i32 @Lab4_saveoutput(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 ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %38
14: ; preds = %3
%15 = load i32*, i32** %8
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to double
%18 = load double, double* %7
%19 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %17, double %18)
store i32 0, i32* %9
br label %20
20: ; preds = %32, %14
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32*, i32** %8
%26 = load double*, double** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = call i32 (i32*, i8*, double, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %20
35: ; preds = %20
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %4
br label %38
38: ; preds = %35, %12
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [12 x i8] c"data_output\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"%d\0A%f\0A\00"
@.str.4 = [4 x i8] c"%e\0A\00"
@str = [30 x i8] c"Error opening the input file.\00"
define i32 @Lab4_saveoutput(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 ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %23
8: ; preds = %3
%9 = sitofp i32 %1 to double
%10 = tail call i32 (i32*, i8*, double, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %9, double %2)
%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 (i32*, i8*, double, ...) @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 @fclose(i32* %4)
br label %23
23: ; preds = %21, %6
%24 = phi i32 [ 1, %6 ], [ 0, %21 ]
ret i32 %24
}