#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int **init_graph(int, int);
int /*<<< orphan*/ printf(char *);
int **text_to_graph(char *name) {
  int nodes;
  FILE *file = fopen(name, "r");
  if (file == NULL) {
    printf("Error opening file.\n");
    return NULL;
  }
  fscanf(file, "%i", &nodes);
  int **graph = init_graph(nodes, false);
  for (int i = 0; i < nodes; i++)
    for (int j = 0; j < nodes; j++)
      fscanf(file, "%i", &graph[i][j]);
  fclose(file);
  return graph;
}


x86 assembly (clang, -O0):
<text_to_graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <text_to_graph+0x44>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1235 <text_to_graph+0xe5>
mov    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1070 <init_graph@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1224 <text_to_graph+0xd4>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1211 <text_to_graph+0xc1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe19(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d0 <text_to_graph+0x80>
jmp    1216 <text_to_graph+0xc6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11bd <text_to_graph+0x6d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_to_graph>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1200 <text_to_graph+0xb0>
mov    %rax,%r14
lea    0xe88(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1070 <init_graph@plt>
mov    %rax,%r12
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    11f6 <text_to_graph+0xa6>
xor    %r13d,%r13d
lea    0xe5b(%rip),%r15
jmp    11bc <text_to_graph+0x6c>
nopl   0x0(%rax)
movslq %eax,%rcx
add    $0x1,%r13
cmp    %rcx,%r13
jge    11f6 <text_to_graph+0xa6>
test   %eax,%eax
jle    11b0 <text_to_graph+0x60>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%r13,8),%rdx
add    %rbx,%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11d0 <text_to_graph+0x80>
jmp    11b0 <text_to_graph+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    120f <text_to_graph+0xbf>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Error opening file.\0A\00"
@.str.2 = [3 x i8] c"%i\00"
define i32** @text_to_graph(i8* %0) {
%2 = alloca i32**
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32** null, i32*** %2
br label %51
15: ; preds = %1
%16 = load i32*, i32** %5
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%18 = load i32, i32* %4
%19 = call i32** @init_graph(i32 %18, i32 0)
store i32** %19, i32*** %6
store i32 0, i32* %7
br label %20
20: ; preds = %44, %15
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
store i32 0, i32* %8
br label %25
25: ; preds = %40, %24
%26 = load i32, i32* %8
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i32*, i32** %5
%31 = load i32**, i32*** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %38)
br label %40
40: ; preds = %29
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %25
43: ; preds = %25
br label %44
44: ; preds = %43
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %20
47: ; preds = %20
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
%50 = load i32**, i32*** %6
store i32** %50, i32*** %2
br label %51
51: ; preds = %47, %13
%52 = load i32**, i32*** %2
ret i32** %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%i\00"
@str = [20 x i8] c"Error opening file.\00"
define i32** @text_to_graph(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %36
8: ; preds = %1
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = call i32** @init_graph(i32 %10, i32 0)
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %8, %22
%15 = phi i32 [ %23, %22 ], [ %12, %8 ]
%16 = phi i64 [ %25, %22 ], [ 0, %8 ]
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = getelementptr inbounds i32*, i32** %11, i64 %16
br label %27
20: ; preds = %22, %8
%21 = call i32 @fclose(i32* %4)
br label %36
22: ; preds = %27, %14
%23 = phi i32 [ %15, %14 ], [ %33, %27 ]
%24 = sext i32 %23 to i64
%25 = add nuw nsw i64 %16, 1
%26 = icmp slt i64 %25, %24
br i1 %26, label %14, label %20
27: ; preds = %18, %27
%28 = phi i64 [ 0, %18 ], [ %32, %27 ]
%29 = load i32*, i32** %19
%30 = getelementptr inbounds i32, i32* %29, i64 %28
%31 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %30)
%32 = add nuw nsw i64 %28, 1
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %27, label %22
36: ; preds = %20, %6
%37 = phi i32** [ null, %6 ], [ %11, %20 ]
ret i32** %37
}