#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ stderr;
void exibeGrafo(int **matriz, int n) {
  int i;
  int j;
  FILE *fp = fopen("grafo.txt", "w");
  if (!fp) {
    fprintf(stderr, "Não pude abrir o arquivo");
    return;
  }
  for (i = 0; i < n; i++) {
    fprintf(fp, "%d %.3f ", i, (rand() % 1000) / 1000.0);
    for (j = 0; j < n; j++) {
      if (matriz[i][j]) {
        fprintf(fp, "%d %d ", j, matriz[i][j]);
      }
    }
    fputc('\n', fp);
  }
}


x86 assembly (clang, -O0):
<exibeGrafo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeb2(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <exibeGrafo+0x4e>
mov    0x2e68(%rip),%rax
movslq (%rax),%rdi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1269 <exibeGrafo+0x129>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1269 <exibeGrafo+0x129>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x30(%rbp),%rdi
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x24(%rbp),%edx
cvtsi2sd %eax,%xmm0
movsd  0xe2d(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe50(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124d <exibeGrafo+0x10d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     123a <exibeGrafo+0xfa>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    123f <exibeGrafo+0xff>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ec <exibeGrafo+0xac>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <exibeGrafo+0x55>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exibeGrafo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r13
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1245 <exibeGrafo+0xf5>
test   %ebx,%ebx
jle    1236 <exibeGrafo+0xe6>
mov    %rax,%r14
mov    %ebx,%r15d
lea    0xea6(%rip),%r12
xor    %ebx,%ebx
jmp    11ba <exibeGrafo+0x6a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
je     1236 <exibeGrafo+0xe6>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe12(%rip),%xmm0
mov    %r14,%rdi
lea    0xe36(%rip),%rsi
mov    %ebx,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
xor    %ebp,%ebp
jmp    1219 <exibeGrafo+0xc9>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    %rbp,%r15
je     11a0 <exibeGrafo+0x50>
mov    0x0(%r13,%rbx,8),%rax
mov    (%rax,%rbp,4),%ecx
test   %ecx,%ecx
je     1210 <exibeGrafo+0xc0>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1210 <exibeGrafo+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d94(%rip),%rax
movslq (%rax),%rcx
lea    0xdbe(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"grafo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"N\C3\A3o pude abrir o arquivo\00"
@.str.3 = [9 x i8] c"%d %.3f \00"
@.str.4 = [7 x i8] c"%d %d \00"
define void @exibeGrafo(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32** %0, i32*** %3
store i32 %1, i32* %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %67
16: ; preds = %2
store i32 0, i32* %5
br label %17
17: ; preds = %64, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %67
21: ; preds = %17
%22 = load i32*, i32** %7
%23 = load i32, i32* %5
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 1000
%26 = sitofp i32 %25 to double
%27 = fdiv double %26, 1.000000e+03
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %23, double %27)
store i32 0, i32* %6
br label %29
29: ; preds = %58, %21
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %61
33: ; preds = %29
%34 = load i32**, i32*** %3
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32*, i32** %34, i64 %36
%38 = load i32*, i32** %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %57
44: ; preds = %33
%45 = load i32*, i32** %7
%46 = load i32, i32* %6
%47 = load i32**, i32*** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32*, i32** %47, i64 %49
%51 = load i32*, i32** %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %55)
br label %57
57: ; preds = %44, %33
br label %58
58: ; preds = %57
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %29
61: ; preds = %29
%62 = load i32*, i32** %7
%63 = call i32 @fputc(i8 signext 10, i32* %62)
br label %64
64: ; preds = %61
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %17
67: ; preds = %11, %17
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"grafo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"N\C3\A3o pude abrir o arquivo\00"
@.str.3 = [9 x i8] c"%d %.3f \00"
@.str.4 = [7 x i8] c"%d %d \00"
define void @exibeGrafo(i32** nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 %9, label %5
5: ; preds = %2
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %39
7: ; preds = %5
%8 = zext i32 %1 to i64
br label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 25, i64 1, i32* %12)
br label %39
14: ; preds = %35, %7
%15 = phi i64 [ 0, %7 ], [ %37, %35 ]
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 1000
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, 1.000000e+03
%20 = trunc i64 %15 to i32
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %20, double %19)
%22 = getelementptr inbounds i32*, i32** %0, i64 %15
br label %23
23: ; preds = %14, %32
%24 = phi i64 [ 0, %14 ], [ %33, %32 ]
%25 = load i32*, i32** %22
%26 = getelementptr inbounds i32, i32* %25, i64 %24
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %23
%30 = trunc i64 %24 to i32
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %27)
br label %32
32: ; preds = %23, %29
%33 = add nuw nsw i64 %24, 1
%34 = icmp eq i64 %33, %8
br i1 %34, label %35, label %23
35: ; preds = %32
%36 = tail call i32 @fputc(i8 signext 10, i32* %3)
%37 = add nuw nsw i64 %15, 1
%38 = icmp eq i64 %37, %8
br i1 %38, label %39, label %14
39: ; preds = %35, %5, %9
ret void
}