#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*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AdjacencyMatrix_writeToFile(int /*<<< orphan*/ *, float *,
                                               size_t);
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ atoi(char *);
float *calloc(size_t, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
float randomVal();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  size_t nVert = 0;
  {
    time_t t;
    srand((unsigned)time(&t));
  };
  if (argc != 3) {
    printf("Useage: generator <n> <OutputFilename>\n"
           "where n is an integer denoting the number of vertices in "
           "the graph.\n");
    exit(EXIT_FAILURE);
  } else if ((nVert = (size_t)atoi(argv[1])) == 0) {
    printf("Invalid number of vertices: must be an integer greater "
           " than 0.\n");
    exit(EXIT_FAILURE);
  }
  float *graph = calloc(nVert * nVert, sizeof(float));
  for (int i = 0; i < nVert; i++)
    for (int j = 0; j < nVert; j++) {
      float val = i == j ? 0.0f : randomVal();
      *(graph + i * nVert + j) = *(graph + j * nVert + i) = val;
    }
  FILE *fp = fopen(argv[2], "w");
  if (fp)
    AdjacencyMatrix_writeToFile(fp, graph, nVert);
  else
    printf("Error opening file %s\n", argv[2]);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x3,-0x8(%rbp)
je     11f4 <main+0x54>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    122b <main+0x8b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    1230 <main+0x90>
mov    -0x18(%rbp),%rdi
imul   -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1300 <main+0x160>
movl   $0x0,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12ed <main+0x14d>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    128a <main+0xea>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
jmp    1296 <main+0xf6>
mov    $0x0,%al
call   1050 <randomVal@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
imul   -0x18(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   -0x18(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1263 <main+0xc3>
jmp    12f2 <main+0x152>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd9e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1339 <main+0x199>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <AdjacencyMatrix_writeToFile@plt>
jmp    134f <main+0x1af>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x24(%rsp),%rdi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmp    $0x3,%ebx
jne    12c4 <main+0x114>
mov    %rbp,0x10(%rsp)
mov    0x8(%rbp),%rdi
call   10c0 <atoi@plt>
test   %rax,%rax
je     12cd <main+0x11d>
mov    %rax,%r13
mov    %rax,%rdi
imul   %r13,%rdi
mov    $0x4,%esi
call   1080 <calloc@plt>
lea    0x0(,%r13,4),%rbx
mov    %rax,%r12
mov    %rax,0x8(%rsp)
mov    %rax,%rbp
xor    %r14d,%r14d
jmp    1235 <main+0x85>
add    $0x1,%r14
add    %rbx,%rbp
mov    0x18(%rsp),%r12
add    $0x4,%r12
cmp    %r13,%r14
je     126a <main+0xba>
mov    %r12,0x18(%rsp)
xor    %r15d,%r15d
jmp    1259 <main+0xa9>
nop
movss  %xmm0,(%r12)
movss  %xmm0,0x0(%rbp,%r15,4)
add    $0x1,%r15
add    %rbx,%r12
cmp    %r15,%r13
je     1220 <main+0x70>
xorps  %xmm0,%xmm0
cmp    %r15,%r14
je     1240 <main+0x90>
xor    %eax,%eax
call   1060 <randomVal@plt>
jmp    1240 <main+0x90>
mov    0x10(%rsp),%rbx
mov    0x10(%rbx),%rdi
lea    0xd86(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     1299 <main+0xe9>
mov    %r12,%rdi
mov    0x8(%rsp),%rsi
mov    %r13,%rdx
call   10a0 <AdjacencyMatrix_writeToFile@plt>
jmp    12ab <main+0xfb>
mov    0x10(%rbx),%rsi
lea    0xd5e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8e(%rip),%rdi
jmp    12d4 <main+0x124>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [108 x i8] c"Useage: generator <n> <OutputFilename>\0Awhere n is an integer denoting the number of vertices in the graph.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [65 x i8] c"Invalid number of vertices: must be an integer greater than 0.\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [23 x i8] c"Error opening file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%13 = call i64 @time(i32* %7)
%14 = trunc i64 %13 to i32
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @atoi(i8* %25)
store i64 %26, i64* %6
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = load i64, i64* %6
%35 = load i64, i64* %6
%36 = mul i64 %34, %35
%37 = call float* @calloc(i64 %36, i32 4)
store float* %37, float** %8
store i32 0, i32* %9
br label %38
38: ; preds = %81, %33
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = load i64, i64* %6
%42 = icmp ult i64 %40, %41
br i1 %42, label %43, label %84
43: ; preds = %38
store i32 0, i32* %10
br label %44
44: ; preds = %77, %43
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = load i64, i64* %6
%48 = icmp ult i64 %46, %47
br i1 %48, label %49, label %80
49: ; preds = %44
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %49
br label %56
54: ; preds = %49
%55 = call float (...) @randomVal()
br label %56
56: ; preds = %54, %53
%57 = phi float [ 0.000000e+00, %53 ], [ %55, %54 ]
store float %57, float* %11
%58 = load float, float* %11
%59 = load float*, float** %8
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = load i64, i64* %6
%63 = mul i64 %61, %62
%64 = getelementptr inbounds float, float* %59, i64 %63
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %64, i64 %66
store float %58, float* %67
%68 = load float*, float** %8
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = load i64, i64* %6
%72 = mul i64 %70, %71
%73 = getelementptr inbounds float, float* %68, i64 %72
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds float, float* %73, i64 %75
store float %58, float* %76
br label %77
77: ; preds = %56
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
br label %44
80: ; preds = %44
br label %81
81: ; preds = %80
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
br label %38
84: ; preds = %38
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 2
%87 = load i8*, i8** %86
%88 = call i32* @fopen(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %88, i32** %12
%89 = load i32*, i32** %12
%90 = icmp ne i32* %89, null
br i1 %90, label %91, label %96
91: ; preds = %84
%92 = load i32*, i32** %12
%93 = load float*, float** %8
%94 = load i64, i64* %6
%95 = call i32 @AdjacencyMatrix_writeToFile(i32* %92, float* %93, i64 %94)
br label %101
96: ; preds = %84
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 2
%99 = load i8*, i8** %98
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %96, %91
%102 = load i32*, i32** %12
%103 = call i32 @fclose(i32* %102)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [23 x i8] c"Error opening file %s\0A\00"
@str = [64 x i8] c"Invalid number of vertices: must be an integer greater than 0.\00"
@str.4 = [107 x i8] c"Useage: generator <n> <OutputFilename>\0Awhere n is an integer denoting the number of vertices in the graph.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i64 @time(i32* %3)
%6 = trunc i64 %5 to i32
%7 = call i32 @srand(i32 %6)
%8 = icmp eq i32 %0, 3
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([107 x i8], [107 x i8]* @str.4, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @atoi(i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = mul i64 %16, %16
%24 = call float* @calloc(i64 %23, i32 4)
br label %25
25: ; preds = %22, %35
%26 = phi i64 [ 0, %22 ], [ %36, %35 ]
%27 = mul i64 %26, %16
%28 = getelementptr inbounds float, float* %24, i64 %27
%29 = getelementptr inbounds float, float* %24, i64 %26
br label %38
30: ; preds = %35
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %52, label %50
35: ; preds = %43
%36 = add nuw i64 %26, 1
%37 = icmp eq i64 %36, %16
br i1 %37, label %30, label %25
38: ; preds = %25, %43
%39 = phi i64 [ 0, %25 ], [ %48, %43 ]
%40 = icmp eq i64 %26, %39
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call float (...) @randomVal()
br label %43
43: ; preds = %38, %41
%44 = phi float [ %42, %41 ], [ 0.000000e+00, %38 ]
%45 = mul i64 %39, %16
%46 = getelementptr inbounds float, float* %29, i64 %45
store float %44, float* %46
%47 = getelementptr inbounds float, float* %28, i64 %39
store float %44, float* %47
%48 = add nuw i64 %39, 1
%49 = icmp eq i64 %48, %16
br i1 %49, label %35, label %38
50: ; preds = %30
%51 = call i32 @AdjacencyMatrix_writeToFile(i32* %33, float* %24, i64 %16)
br label %55
52: ; preds = %30
%53 = load i8*, i8** %31
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %50
%56 = call i32 @fclose(i32* %33)
ret i32 0
}