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


x86 assembly (clang, -O0):
<Lab2_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 <Lab2_saveoutput+0x4d>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1242 <Lab2_saveoutput+0x102>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe81(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1232 <Lab2_saveoutput+0xf2>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1212 <Lab2_saveoutput+0xd2>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d3 <Lab2_saveoutput+0x93>
mov    -0x28(%rbp),%rdi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c0 <Lab2_saveoutput+0x80>
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):
<Lab2_saveoutput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %esi,%r15d
mov    %rdi,%r12
lea    0xe93(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1210 <Lab2_saveoutput+0xc0>
mov    %rax,%r13
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe73(%rip),%rsi
mov    %r13,%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    1204 <Lab2_saveoutput+0xb4>
mov    %r15d,%ebx
lea    0xe5b(%rip),%r15
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbp,8),%rax
mov    (%rax,%r14,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    11d0 <Lab2_saveoutput+0x80>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbp
cmp    %rbx,%rbp
jne    11c0 <Lab2_saveoutput+0x70>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1221 <Lab2_saveoutput+0xd1>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [5 x i8] c"%d\0A\0A\00"
@.str.4 = [6 x i8] c"%lf\0A\0A\00"
@.str.5 = [4 x i8] c"%d\09\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @Lab2_saveoutput(i32** %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca double
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store double %2, double* %7
%11 = 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* %11, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = 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 %55
15: ; preds = %3
%16 = load i32*, i32** %8
%17 = load i32, i32* %6
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32*, i32** %8
%20 = load double, double* %7
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %20)
store i32 0, i32* %9
br label %22
22: ; preds = %49, %15
%23 = load i32, i32* %9
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %52
26: ; preds = %22
store i32 0, i32* %10
br label %27
27: ; preds = %43, %26
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = load i32**, i32*** %5
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %27
46: ; preds = %27
%47 = load i32*, i32** %8
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %46
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %22
52: ; preds = %22
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %4
br label %55
55: ; preds = %52, %13
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"data_output\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [5 x i8] c"%d\0A\0A\00"
@.str.4 = [6 x i8] c"%lf\0A\0A\00"
@.str.5 = [4 x i8] c"%d\09\00"
@str = [31 x i8] c"Error opening the output file.\00"
define i32 @Lab2_saveoutput(i32** 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 %31
8: ; preds = %3
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), double %2)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %25, %12
%15 = phi i64 [ 0, %12 ], [ %27, %25 ]
%16 = getelementptr inbounds i32*, i32** %0, i64 %15
br label %17
17: ; preds = %14, %17
%18 = phi i64 [ 0, %14 ], [ %23, %17 ]
%19 = load i32*, i32** %16
%20 = getelementptr inbounds i32, i32* %19, i64 %18
%21 = load i32, i32* %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %17
25: ; preds = %17
%26 = tail call i32 @fputc(i32 10, i32* %4)
%27 = add nuw nsw i64 %15, 1
%28 = icmp eq i64 %27, %13
br i1 %28, label %29, label %14
29: ; preds = %25, %8
%30 = tail call i32 @fclose(i32* %4)
br label %31
31: ; preds = %29, %6
%32 = phi i32 [ 1, %6 ], [ 0, %29 ]
ret i32 %32
}