#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 *, ...);
void save_graph(char *mgph, int size, char *name) {
  FILE *f = fopen(name, "w");
  fprintf(f, "graph {\noverlap=false\nsplines=true\n");
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      if (i > j && mgph[i + size * j])
        fprintf(f, "%d -- %d\n", i, j);
    }
  }
  fprintf(f, "}\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<save_graph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f9 <save_graph+0xc9>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <save_graph+0xb6>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    11d3 <save_graph+0xa3>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0xc(%rbp),%edx
imul   -0x28(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d3 <save_graph+0xa3>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11d8 <save_graph+0xa8>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1183 <save_graph+0x53>
jmp    11eb <save_graph+0xbb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1170 <save_graph+0x40>
mov    -0x20(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_graph>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xea9(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r12
lea    0xe99(%rip),%rdi
mov    $0x23,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
test   %ebx,%ebx
jle    11df <save_graph+0x9f>
mov    %ebx,%ebp
xor    %r13d,%r13d
jmp    119d <save_graph+0x5d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
add    $0x1,%r15
cmp    %rbp,%r13
je     11df <save_graph+0x9f>
mov    %r15,%r14
xor    %ebx,%ebx
jmp    11bc <save_graph+0x7c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
add    %rbp,%r14
cmp    %rbx,%rbp
je     1190 <save_graph+0x50>
cmp    %rbx,%r13
jbe    11b0 <save_graph+0x70>
cmpb   $0x0,(%r14)
je     11b0 <save_graph+0x70>
mov    %r12,%rdi
lea    0xe55(%rip),%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b0 <save_graph+0x70>
lea    0xe4a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [36 x i8] c"graph {\0Aoverlap=false\0Asplines=true\0A\00"
@.str.2 = [10 x i8] c"%d -- %d\0A\00"
@.str.3 = [3 x i8] c"}\0A\00"
define void @save_graph(i8* 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 = tail call i64 @fwrite(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 35, i64 1, i32* %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = zext i32 %1 to i64
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %16, %7
%11 = phi i64 [ 0, %7 ], [ %17, %16 ]
%12 = trunc i64 %11 to i32
br label %19
13: ; preds = %16, %3
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %4)
%15 = tail call i32 @fclose(i32* %4)
ret void
16: ; preds = %31
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %9
br i1 %18, label %13, label %10
19: ; preds = %10, %31
%20 = phi i64 [ 0, %10 ], [ %32, %31 ]
%21 = icmp ugt i64 %11, %20
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = mul nsw i64 %20, %8
%24 = add nuw nsw i64 %23, %11
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = trunc i64 %20 to i32
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %29)
br label %31
31: ; preds = %19, %22, %28
%32 = add nuw nsw i64 %20, 1
%33 = icmp eq i64 %32, %9
br i1 %33, label %16, label %19
}