#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 */
scalar_t__ RAND_MAX;
float atof(char *);
int atoi(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ chmod(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ rand();
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int neurons, i, j;
  float rndm, percentage;
  char filename[30];
  sprintf(filename, "cellConnections.txt");
  FILE *out_file;
  float **global_connection_table;
  if (argc != 3) {
    printf("Error: Usage ./conn_generator.x #neurons density_pct%\n");
    return 0;
  }
  neurons = atoi(argv[1]);
  percentage = atof(argv[2]);
  if (percentage > 1) {
    printf("Warning: Connectivity Density assumed at 100%\n");
    percentage = 1;
  }
  out_file = fopen(filename, "w");
  global_connection_table = (float **)malloc(sizeof(float *) * neurons);
  for (i = 0; i < neurons; i++) {
    global_connection_table[i] = (float *)calloc(neurons, sizeof(float));
  }
  srand(time(NULL));
  for (i = 0; i < neurons; i++) {
    for (j = 0; j < neurons; j++) {
      if (i == j)
        ;
      else {
        rndm = ((float)rand()) / ((float)RAND_MAX);
        if (rndm <= percentage)
          global_connection_table[i][j] = 0.04;
      }
      fprintf(out_file, "%0.2f ", global_connection_table[i][j]);
    }
    fprintf(out_file, "\n");
  }
  fclose(out_file);
  chmod(out_file, 0x01B6);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   10e0 <sprintf@plt>
cmpl   $0x3,-0x8(%rbp)
je     1218 <main+0x48>
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e1 <main+0x211>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  0xdb9(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1269 <main+0x99>
lea    0xdfc(%rip),%rdi
call   1050 <printf@plt>
movss  0xd9c(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x58(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12cd <main+0xfd>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%rdx
mov    -0x60(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1297 <main+0xc7>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13c3 <main+0x1f3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13a3 <main+0x1d3>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1314 <main+0x144>
jmp    136a <main+0x19a>
mov    $0x0,%al
call   10f0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2cc1(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1365 <main+0x195>
mov    -0x60(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movss  0xca4(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
jmp    136a <main+0x19a>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcf6(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12f7 <main+0x127>
mov    -0x58(%rbp),%rdi
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12e4 <main+0x114>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x58(%rbp),%rdi
mov    $0x1b6,%esi
call   10b0 <chmod@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movups 0xe1f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x747874,0x20(%rsp)
cmp    $0x3,%edi
jne    1334 <main+0x164>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1030 <atof@plt>
movss  %xmm0,0xc(%rsp)
ucomiss 0xde0(%rip),%xmm0
jbe    123c <main+0x6c>
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
movss  0xdca(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
lea    0xe3b(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10d0 <fopen@plt>
mov    %rax,%r14
lea    0x0(,%r15,8),%edi
call   10b0 <malloc@plt>
test   %r15d,%r15d
jle    1342 <main+0x172>
mov    %rax,%rbx
mov    %r15d,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r15d,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1270 <main+0xa0>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
test   %r15d,%r15d
jle    1350 <main+0x180>
lea    0xdd8(%rip),%r15
xor    %ebp,%ebp
jmp    12ca <main+0xfa>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbp
cmp    %r12,%rbp
je     1350 <main+0x180>
xor    %r13d,%r13d
jmp    12f4 <main+0x124>
nop
mov    (%rbx,%rbp,8),%rax
movss  (%rax,%r13,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     12b0 <main+0xe0>
cmp    %r13,%rbp
je     12d0 <main+0x100>
xor    %eax,%eax
call   10f0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2cd9(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
movss  0xc(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jb     12d0 <main+0x100>
mov    (%rbx,%rbp,8),%rax
movl   $0x3d23d70a,(%rax,%r13,4)
3d
jmp    12d0 <main+0x100>
lea    0xcdd(%rip),%rdi
call   1050 <printf@plt>
jmp    1365 <main+0x195>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
mov    $0x1b6,%esi
call   10c0 <chmod@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"cellConnections.txt\00"
@.str.1 = [55 x i8] c"Error: Usage ./conn_generator.x #neurons density_pct%\0A\00"
@.str.2 = [47 x i8] c"Warning: Connectivity Density assumed at 100%\0A\00"
@.str.3 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@.str.4 = [7 x i8] c"%0.2f \00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca float
%11 = alloca [30 x i8]
%12 = alloca i32*
%13 = alloca float**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%15 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %120
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call float @atof(i8* %27)
store float %28, float* %10
%29 = load float, float* %10
%30 = fcmp ogt float %29, 1.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %20
%32 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
store float 1.000000e+00, float* %10
br label %33
33: ; preds = %31, %20
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %12
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = mul i64 8, %37
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to float**
store float** %41, float*** %13
store i32 0, i32* %7
br label %42
42: ; preds = %54, %33
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %57
46: ; preds = %42
%47 = load i32, i32* %6
%48 = call i64 @calloc(i32 %47, i32 4)
%49 = inttoptr i64 %48 to float*
%50 = load float**, float*** %13
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds float*, float** %50, i64 %52
store float* %49, float** %53
br label %54
54: ; preds = %46
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %42
57: ; preds = %42
%58 = call i32 @time(i32* null)
%59 = call i32 @srand(i32 %58)
store i32 0, i32* %7
br label %60
60: ; preds = %112, %57
%61 = load i32, i32* %7
%62 = load i32, i32* %6
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %115
64: ; preds = %60
store i32 0, i32* %8
br label %65
65: ; preds = %106, %64
%66 = load i32, i32* %8
%67 = load i32, i32* %6
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %109
69: ; preds = %65
%70 = load i32, i32* %7
%71 = load i32, i32* %8
%72 = icmp eq i32 %70, %71
br i1 %72, label %73, label %74
73: ; preds = %69
br label %93
74: ; preds = %69
%75 = call i64 (...) @rand()
%76 = sitofp i64 %75 to float
%77 = load i64, i64* @RAND_MAX
%78 = sitofp i64 %77 to float
%79 = fdiv float %76, %78
store float %79, float* %9
%80 = load float, float* %9
%81 = load float, float* %10
%82 = fcmp ole float %80, %81
br i1 %82, label %83, label %92
83: ; preds = %74
%84 = load float**, float*** %13
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds float*, float** %84, i64 %86
%88 = load float*, float** %87
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds float, float* %88, i64 %90
store float 0x3FA47AE140000000, float* %91
br label %92
92: ; preds = %83, %74
br label %93
93: ; preds = %92, %73
%94 = load i32*, i32** %12
%95 = load float**, float*** %13
%96 = load i32, i32* %7
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds float*, float** %95, i64 %97
%99 = load float*, float** %98
%100 = load i32, i32* %8
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds float, float* %99, i64 %101
%103 = load float, float* %102
%104 = fpext float %103 to double
%105 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %104)
br label %106
106: ; preds = %93
%107 = load i32, i32* %8
%108 = add nsw i32 %107, 1
store i32 %108, i32* %8
br label %65
109: ; preds = %65
%110 = load i32*, i32** %12
%111 = call i32 (i32*, i8*, ...) @fprintf(i32* %110, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %112
112: ; preds = %109
%113 = load i32, i32* %7
%114 = add nsw i32 %113, 1
store i32 %114, i32* %7
br label %60
115: ; preds = %60
%116 = load i32*, i32** %12
%117 = call i32 @fclose(i32* %116)
%118 = load i32*, i32** %12
%119 = call i32 @chmod(i32* %118, i32 438)
store i32 0, i32* %3
br label %120
120: ; preds = %115, %18
%121 = load i32, i32* %3
ret i32 %121
}

LLVM IR (-O2):
@.str = [20 x i8] c"cellConnections.txt\00"
@.str.1 = [55 x i8] c"Error: Usage ./conn_generator.x #neurons density_pct%\0A\00"
@.str.2 = [47 x i8] c"Warning: Connectivity Density assumed at 100%\0A\00"
@.str.3 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@.str.4 = [7 x i8] c"%0.2f \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %73
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call float @atof(i8* %13)
%15 = fcmp ogt float %14, 1.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
%19 = phi float [ 1.000000e+00, %16 ], [ %14, %8 ]
%20 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = shl i32 %11, 3
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to float**
%24 = icmp sgt i32 %11, 0
br i1 %24, label %25, label %67
25: ; preds = %18
%26 = zext i32 %11 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ 0, %25 ], [ %32, %27 ]
%29 = tail call i64 @calloc(i32 %11, i32 4)
%30 = inttoptr i64 %29 to float*
%31 = getelementptr inbounds float*, float** %23, i64 %28
store float* %30, float** %31
%32 = add nuw nsw i64 %28, 1
%33 = icmp eq i64 %32, %26
br i1 %33, label %34, label %27
34: ; preds = %27
%35 = tail call i32 @time(i32* null)
%36 = tail call i32 @srand(i32 %35)
br i1 %24, label %37, label %70
37: ; preds = %34
%38 = zext i32 %11 to i64
br label %39
39: ; preds = %63, %37
%40 = phi i64 [ 0, %37 ], [ %65, %63 ]
%41 = getelementptr inbounds float*, float** %23, i64 %40
br label %42
42: ; preds = %39, %55
%43 = phi i64 [ 0, %39 ], [ %61, %55 ]
%44 = icmp eq i64 %40, %43
br i1 %44, label %55, label %45
45: ; preds = %42
%46 = tail call i64 (...) @rand()
%47 = sitofp i64 %46 to float
%48 = load i64, i64* @RAND_MAX
%49 = sitofp i64 %48 to float
%50 = fdiv float %47, %49
%51 = fcmp ugt float %50, %19
br i1 %51, label %55, label %52
52: ; preds = %45
%53 = load float*, float** %41
%54 = getelementptr inbounds float, float* %53, i64 %43
store float 0x3FA47AE140000000, float* %54
br label %55
55: ; preds = %45, %52, %42
%56 = load float*, float** %41
%57 = getelementptr inbounds float, float* %56, i64 %43
%58 = load float, float* %57
%59 = fpext float %58 to double
%60 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %59)
%61 = add nuw nsw i64 %43, 1
%62 = icmp eq i64 %61, %38
br i1 %62, label %63, label %42
63: ; preds = %55
%64 = tail call i32 @fputc(i32 10, i32* %20)
%65 = add nuw nsw i64 %40, 1
%66 = icmp eq i64 %65, %38
br i1 %66, label %70, label %39
67: ; preds = %18
%68 = tail call i32 @time(i32* null)
%69 = tail call i32 @srand(i32 %68)
br label %70
70: ; preds = %63, %67, %34
%71 = tail call i32 @fclose(i32* %20)
%72 = tail call i32 @chmod(i32* %20, i32 438)
br label %73
73: ; preds = %70, %6
ret i32 0
}