#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 graph_to_text(int **graph, int nodes, char *path) {
  FILE *file = fopen(path, "w");
  if (file == NULL) {
    printf("Error opening file.\n");
    return -1;
  }
  fprintf(file, "%i\n", nodes);
  for (int i = 0; i < nodes; i++) {
    for (int j = 0; j < nodes; j++)
      fprintf(file, "%3i\t", graph[i][j]);
    fprintf(file, "\n");
  }
  fclose(file);
  return nodes;
}


x86 assembly (clang, -O0):
<graph_to_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118a <graph_to_text+0x4a>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <graph_to_text+0xe7>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1218 <graph_to_text+0xd8>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f8 <graph_to_text+0xb8>
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    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b9 <graph_to_text+0x79>
mov    -0x28(%rbp),%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a6 <graph_to_text+0x66>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<graph_to_text>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xe99(%rip),%rsi
mov    %rdx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f2 <graph_to_text+0xa2>
mov    %rax,%r13
lea    0xe84(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
jle    11e4 <graph_to_text+0x94>
mov    0x4(%rsp),%ebx
lea    0xe69(%rip),%r15
xor    %ebp,%ebp
nop
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    11b0 <graph_to_text+0x60>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbp
cmp    %rbx,%rbp
jne    11a0 <graph_to_text+0x50>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%eax
jmp    1203 <graph_to_text+0xb3>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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