#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 Lab1_saveoutput(int *C, int *n) {
  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", *n);
  for (i = 0; i < *n; i++) {
    for (j = 0; j < *n; j++)
      fprintf(op, "%d\t", C[*n * i + j]);
    fprintf(op, "\n");
  }
  fclose(op);
  return 0;
}


x86 assembly (clang, -O0):
<Lab1_saveoutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1189 <Lab1_saveoutput+0x49>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1234 <Lab1_saveoutput+0xf4>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1224 <Lab1_saveoutput+0xe4>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1204 <Lab1_saveoutput+0xc4>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
imul   -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11be <Lab1_saveoutput+0x7e>
mov    -0x20(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a8 <Lab1_saveoutput+0x68>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Lab1_saveoutput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe98(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1203 <Lab1_saveoutput+0xb3>
mov    %rax,%rbx
mov    (%r15),%edx
lea    0xe84(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%eax
test   %eax,%eax
jle    11f7 <Lab1_saveoutput+0xa7>
lea    0xe71(%rip),%r13
xor    %ebp,%ebp
jmp    11c7 <Lab1_saveoutput+0x77>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
mov    (%r15),%eax
cmp    %eax,%ebp
jge    11f7 <Lab1_saveoutput+0xa7>
test   %eax,%eax
jle    11b0 <Lab1_saveoutput+0x60>
xor    %r12d,%r12d
xchg   %ax,%ax
imul   %ebp,%eax
cltq
add    %r12,%rax
mov    (%r14,%rax,4),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r15),%eax
add    $0x1,%r12
cmp    %eax,%r12d
jl     11d0 <Lab1_saveoutput+0x80>
jmp    11b0 <Lab1_saveoutput+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1214 <Lab1_saveoutput+0xc4>
lea    0xe0d(%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 = [4 x i8] c"%d\09\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @Lab1_saveoutput(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = 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* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %54
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %16)
store i32 0, i32* %7
br label %18
18: ; preds = %48, %13
%19 = load i32, i32* %7
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %51
23: ; preds = %18
store i32 0, i32* %8
br label %24
24: ; preds = %42, %23
%25 = load i32, i32* %8
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %45
29: ; preds = %24
%30 = load i32*, i32** %6
%31 = load i32*, i32** %4
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = load i32, i32* %7
%35 = mul nsw i32 %33, %34
%36 = load i32, i32* %8
%37 = add nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %31, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %29
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %24
45: ; preds = %24
%46 = load i32*, i32** %6
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %45
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %18
51: ; preds = %18
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %51, %11
%55 = load i32, i32* %3
ret i32 %55
}

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 = [4 x i8] c"%d\09\00"
@str = [31 x i8] c"Error opening the output file.\00"
define i32 @Lab1_saveoutput(i32* nocapture %0, i32* nocapture %1) {
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %35
7: ; preds = %2
%8 = load i32, i32* %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %7, %28
%13 = phi i32 [ %31, %28 ], [ %10, %7 ]
%14 = phi i32 [ %30, %28 ], [ 0, %7 ]
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %28
16: ; preds = %12, %16
%17 = phi i32 [ %26, %16 ], [ %13, %12 ]
%18 = phi i32 [ %25, %16 ], [ 0, %12 ]
%19 = mul nsw i32 %17, %14
%20 = add nsw i32 %19, %18
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i32 %18, 1
%26 = load i32, i32* %1
%27 = icmp slt i32 %25, %26
br i1 %27, label %16, label %28
28: ; preds = %16, %12
%29 = tail call i32 @fputc(i32 10, i32* %3)
%30 = add nuw nsw i32 %14, 1
%31 = load i32, i32* %1
%32 = icmp slt i32 %30, %31
br i1 %32, label %12, label %33
33: ; preds = %28, %7
%34 = tail call i32 @fclose(i32* %3)
br label %35
35: ; preds = %33, %5
%36 = phi i32 [ 1, %5 ], [ 0, %33 ]
ret i32 %36
}