#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 **CreateMat(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int Lab2_loadinput(int ***A, int *size) {
  FILE *ip;
  int i, j;
  if ((ip = fopen("data_input", "r")) == NULL) {
    printf("error opening the input data.\n");
    return 1;
  }
  fscanf(ip, "%d\n", size);
  *A = CreateMat(*size);
  for (i = 0; i < *size; ++i) {
    for (j = 0; j < *size; ++j) {
      fscanf(ip, "%d\t", &(*A)[i][j]);
    }
  }
  fclose(ip);
  return 0;
}


x86 assembly (clang, -O0):
<Lab2_loadinput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe99(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1199 <Lab2_loadinput+0x49>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <Lab2_loadinput+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <CreateMat@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1239 <Lab2_loadinput+0xe9>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1226 <Lab2_loadinput+0xd6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe1d(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11df <Lab2_loadinput+0x8f>
jmp    122b <Lab2_loadinput+0xdb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c9 <Lab2_loadinput+0x79>
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):
<Lab2_loadinput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122a <Lab2_loadinput+0xda>
lea    0xe86(%rip),%rsi
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
mov    (%rbx),%edi
call   1070 <CreateMat@plt>
mov    %rbp,0x8(%rsp)
mov    %rax,0x0(%rbp)
mov    %rbx,0x10(%rsp)
mov    (%rbx),%eax
test   %eax,%eax
jle    121d <Lab2_loadinput+0xcd>
xor    %r15d,%r15d
lea    0xe56(%rip),%r14
mov    0x8(%rsp),%r13
mov    (%rsp),%rbx
jmp    11dc <Lab2_loadinput+0x8c>
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%rcx
add    $0x1,%r15
cmp    %rcx,%r15
jge    121d <Lab2_loadinput+0xcd>
test   %eax,%eax
jle    11d0 <Lab2_loadinput+0x80>
xor    %ebp,%ebp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%rax
mov    (%rax,%r15,8),%rdx
add    %rbp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
add    $0x1,%r12
mov    0x10(%rsp),%rax
movslq (%rax),%rax
add    $0x4,%rbp
cmp    %rax,%r12
jl     11f0 <Lab2_loadinput+0xa0>
jmp    11d0 <Lab2_loadinput+0x80>
mov    (%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    123b <Lab2_loadinput+0xeb>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"data_input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"error opening the input data.\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
define i32 @Lab2_loadinput(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 ([11 x i8], [11 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 ([31 x i8], [31 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 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %15)
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = call i32** @CreateMat(i32 %18)
%20 = load i32***, i32**** %4
store i32** %19, i32*** %20
store i32 0, i32* %7
br label %21
21: ; preds = %48, %13
%22 = load i32, i32* %7
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %51
26: ; preds = %21
store i32 0, i32* %8
br label %27
27: ; preds = %44, %26
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %47
32: ; preds = %27
%33 = load i32*, i32** %6
%34 = load i32***, i32**** %4
%35 = load i32**, i32*** %34
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32*, i32** %35, i64 %37
%39 = load i32*, i32** %38
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %42)
br label %44
44: ; preds = %32
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %27
47: ; preds = %27
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %21
51: ; preds = %21
%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 = [11 x i8] c"data_input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
@str = [30 x i8] c"error opening the input data.\00"
define i32 @Lab2_loadinput(i32*** nocapture %0, i32* %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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 ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %35
7: ; preds = %2
%8 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = tail call i32** @CreateMat(i32 %9)
store i32** %10, i32*** %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %7, %28
%14 = phi i32 [ %29, %28 ], [ %11, %7 ]
%15 = phi i64 [ %31, %28 ], [ 0, %7 ]
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %28
17: ; preds = %13, %17
%18 = phi i64 [ %24, %17 ], [ 0, %13 ]
%19 = load i32**, i32*** %0
%20 = getelementptr inbounds i32*, i32** %19, i64 %15
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 %18
%23 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %18, 1
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %17, label %28
28: ; preds = %17, %13
%29 = phi i32 [ %14, %13 ], [ %25, %17 ]
%30 = sext i32 %29 to i64
%31 = add nuw nsw i64 %15, 1
%32 = icmp slt i64 %31, %30
br i1 %32, label %13, 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
}