#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*/ Gaussian_probability_function(double *, int, int, int);
scalar_t__ RAND_MAX;
int atoi(char *);
int calculate_synapse_count(double *, int, int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ clear_buffer(float *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(double *);
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[]) {
  FILE *fd_out;
  char outFileName[100];
  int i, j, k, x, y, z, connections_counter = 0;
  int N, target_synapse_count, rng, count, sparse = 0;
  float avg_counter = 0.0;
  if (argc > 4) {
    x = atoi(argv[1]);
    y = atoi(argv[2]);
    z = atoi(argv[3]);
    N = x * y * z;
    target_synapse_count = atoi(argv[4]);
  }
  if (argc > 5)
    sparse = atoi(argv[5]);
  if ((argc < 5) || (argc > 6)) {
    printf("Error: Wrong arguments:\nUsage: ./conn_generator.x x y z "
           "average_synapse_count <sparse_matrix>\n");
    exit(1);
  }
  if (target_synapse_count > 0.95 * N) {
    printf("Error:\nTarget Synapse Count must be less than 95%% of NW size\n");
    exit(1);
  }
  sprintf(outFileName, "cellConnections.txt");
  fd_out = fopen(outFileName, "w+");
  if (fd_out == NULL) {
    printf("Error: Couldn't create %s\n", outFileName);
    exit(1);
  }
  int *synapse_count = (int *)calloc(N, sizeof(int));
  double *synapse_count_probabilities =
      (double *)calloc((N + 1), sizeof(double));
  Gaussian_probability_function(synapse_count_probabilities, (N + 1),
                                target_synapse_count, 1);
  srand(time(NULL));
  for (i = 0; i < N; i++)
    synapse_count[i] = calculate_synapse_count(synapse_count_probabilities,
                                               (N + 1), 1, (i % 2));
  free(synapse_count_probabilities);
  float *connections = (float *)calloc(N, sizeof(float));
  for (i = 0; i < N; i++) {
    count = 0;
    while (count < synapse_count[i]) {
      rng = (int)(((float)rand() / (float)RAND_MAX) * N);
      if ((rng < N) && (rng != i) && (connections[rng] == 0)) {
        connections[rng] = 0.04;
        count++;
      }
    }
    if (sparse == 0) {
      for (j = 0; j < N; j++) {
        fprintf(fd_out, "%0.2lf ", connections[j]);
        if (connections[j] > 0)
          connections_counter++;
      }
      fprintf(fd_out, "\n");
    } else {
      for (j = 0; j < N; j++)
        if (connections[j] > 0) {
          fprintf(fd_out, "%d %d %0.2lf\n", i, j, connections[j]);
          connections_counter++;
        }
    }
    clear_buffer(connections, N);
  }
  avg_counter = ((float)connections_counter) / ((float)N);
  printf("Average Synapse Count Per Neuron: %0.2f\n", avg_counter);
  fclose(fd_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0xb0(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xb4(%rbp)
ff
cmpl   $0x4,-0x8(%rbp)
jle    1298 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x98(%rbp)
mov    -0x90(%rbp),%eax
imul   -0x94(%rbp),%eax
imul   -0x98(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    12b5 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0xb0(%rbp)
cmpl   $0x5,-0x8(%rbp)
jl     12c9 <main+0xd9>
cmpl   $0x6,-0x8(%rbp)
jle    12e1 <main+0xf1>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
cvtsi2sdl -0xa4(%rbp),%xmm0
ff
cvtsi2sdl -0xa0(%rbp),%xmm2
ff
movsd  0xd07(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    131f <main+0x12f>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xd84(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    136a <main+0x17a>
lea    -0x80(%rbp),%rsi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0xa0(%rbp),%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xa0(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xc8(%rbp),%rdi
mov    -0xa0(%rbp),%esi
add    $0x1,%esi
mov    -0xa4(%rbp),%edx
mov    $0x1,%ecx
call   10c0 <Gaussian_probability_function@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jge    1438 <main+0x248>
mov    -0xc8(%rbp),%rdi
mov    -0xa0(%rbp),%esi
add    $0x1,%esi
mov    -0x84(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    $0x1,%edx
call   10b0 <calculate_synapse_count@plt>
mov    %eax,%edx
mov    -0xc0(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    13d5 <main+0x1e5>
mov    -0xc8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xa0(%rbp),%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0xd0(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jge    16bb <main+0x4cb>
movl   $0x0,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    -0xc0(%rbp),%rcx
movslq -0x84(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1548 <main+0x358>
mov    $0x0,%al
call   1110 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2b37(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtsi2ssl -0xa0(%rbp),%xmm1
ff
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jge    1543 <main+0x353>
mov    -0xa8(%rbp),%eax
cmp    -0x84(%rbp),%eax
je     1543 <main+0x353>
mov    -0xd0(%rbp),%rax
movslq -0xa8(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1543 <main+0x353>
jp     1543 <main+0x353>
mov    -0xd0(%rbp),%rax
movslq -0xa8(%rbp),%rcx
movss  0xad9(%rip),%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    1481 <main+0x291>
cmpl   $0x0,-0xb0(%rbp)
jne    15f8 <main+0x408>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jge    15e1 <main+0x3f1>
mov    -0x18(%rbp),%rdi
mov    -0xd0(%rbp),%rax
movslq -0x88(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xb49(%rip),%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
mov    -0xd0(%rbp),%rax
movslq -0x88(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    15c8 <main+0x3d8>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    15cd <main+0x3dd>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    155f <main+0x36f>
mov    -0x18(%rbp),%rdi
lea    0xa7d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1695 <main+0x4a5>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0xa0(%rbp),%eax
jge    1690 <main+0x4a0>
mov    -0xd0(%rbp),%rax
movslq -0x88(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1677 <main+0x487>
mov    -0x18(%rbp),%rdi
mov    -0x84(%rbp),%edx
mov    -0x88(%rbp),%ecx
mov    -0xd0(%rbp),%rax
movslq -0x88(%rbp),%rsi
movss  (%rax,%rsi,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xa83(%rip),%rsi
mov    $0x1,%al
call   1090 <fprintf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    167c <main+0x48c>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1602 <main+0x412>
jmp    1695 <main+0x4a5>
mov    -0xd0(%rbp),%rdi
mov    -0xa0(%rbp),%esi
call   1060 <clear_buffer@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1465 <main+0x275>
cvtsi2ssl -0x9c(%rbp),%xmm0
ff
cvtsi2ssl -0xa0(%rbp),%xmm1
ff
divss  %xmm1,%xmm0
movss  %xmm0,-0xb4(%rbp)
ff
movss  -0xb4(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xa08(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
cmp    $0x5,%edi
jl     154c <main+0x34c>
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1100 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r13d
mov    0x20(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
movl   $0x0,0x8(%rsp)
cmp    $0x5,%ebx
je     1275 <main+0x75>
mov    0x28(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,0x8(%rsp)
add    $0xfffffff9,%ebx
cmp    $0xfffffffd,%ebx
jbe    154c <main+0x34c>
mov    %r15,%rbx
imul   %r14d,%ebx
imul   %r13d,%ebx
cvtsi2sd %r12d,%xmm0
cvtsi2sd %ebx,%xmm1
mulsd  0xd6f(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1562 <main+0x362>
movups 0xda9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x747874,0x40(%rsp)
lea    0xda9(%rip),%rsi
lea    0x30(%rsp),%rdi
call   10f0 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     157a <main+0x37a>
mov    %ebx,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,%r15
lea    0x1(%rbx),%r13d
mov    %r13d,%edi
mov    $0x8,%esi
call   10a0 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r15,%r12
mov    $0x1,%ecx
call   10e0 <Gaussian_probability_function@plt>
xor    %r15d,%r15d
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
mov    %ebx,%ebp
mov    %rbx,0x20(%rsp)
test   %ebx,%ebx
jle    1352 <main+0x152>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%ecx
and    $0x1,%ecx
mov    %r14,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
call   10d0 <calculate_synapse_count@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1330 <main+0x130>
mov    %rbp,0x18(%rsp)
mov    %r12,0x28(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%r13
mov    %r13d,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %r13d,%xmm0
movss  %xmm0,0xc(%rsp)
test   %r13d,%r13d
jle    150e <main+0x30e>
mov    %rax,%rbp
xorpd  %xmm1,%xmm1
lea    0xce2(%rip),%r12
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    13d0 <main+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    0x20(%rsp),%r13
mov    %r13d,%esi
call   1070 <clear_buffer@plt>
xorps  %xmm1,%xmm1
add    $0x1,%r14
cmp    %rbx,%r14
je     150e <main+0x30e>
mov    0x28(%rsp),%rax
cmpl   $0x0,(%rax,%r14,4)
jle    1450 <main+0x250>
xor    %ebx,%ebx
jmp    13ee <main+0x1ee>
xorps  %xmm1,%xmm1
mov    0x28(%rsp),%rax
cmp    (%rax,%r14,4),%ebx
jge    1450 <main+0x250>
xor    %eax,%eax
call   1120 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2be4(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
mulss  0xc(%rsp),%xmm0
cvttss2si %xmm0,%eax
cmp    %eax,%r13d
jle    13e0 <main+0x1e0>
cmp    %rax,%r14
xorps  %xmm1,%xmm1
je     13e3 <main+0x1e3>
cltq
movss  0x0(%rbp,%rax,4),%xmm0
ucomiss %xmm1,%xmm0
jne    13e3 <main+0x1e3>
jp     13e3 <main+0x1e3>
movl   $0x3d23d70a,0x0(%rbp,%rax,4)
3d
add    $0x1,%ebx
jmp    13e3 <main+0x1e3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpl   $0x0,0x8(%rsp)
je     14b0 <main+0x2b0>
xor    %r13d,%r13d
mov    0x18(%rsp),%rbx
jmp    147d <main+0x27d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r13,%rbx
je     13b0 <main+0x1b0>
movss  0x0(%rbp,%r13,4),%xmm0
ucomiss %xmm1,%xmm0
jbe    1470 <main+0x270>
cvtss2sd %xmm0,%xmm0
mov    0x10(%rsp),%rdi
lea    0xbec(%rip),%rsi
mov    %r14d,%edx
mov    %r13d,%ecx
mov    $0x1,%al
call   10b0 <fprintf@plt>
xorps  %xmm1,%xmm1
add    $0x1,%r15d
jmp    1470 <main+0x270>
nop
xor    %ebx,%ebx
mov    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
movss  0x0(%rbp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   10b0 <fprintf@plt>
movss  0x0(%rbp,%rbx,4),%xmm0
xor    %eax,%eax
ucomiss 0xb22(%rip),%xmm0
seta   %al
add    %eax,%r15d
add    $0x1,%rbx
cmp    %rbx,0x18(%rsp)
jne    14c0 <main+0x2c0>
mov    $0xa,%edi
mov    %r13,%rsi
call   1080 <fputc@plt>
mov    0x18(%rsp),%rbx
jmp    13b0 <main+0x1b0>
xorps  %xmm0,%xmm0
cvtsi2ss %r15d,%xmm0
divss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xb6c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb69(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xaa3(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    0xae1(%rip),%rdi
lea    0x30(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [95 x i8] c"Error: Wrong arguments:\0AUsage: ./conn_generator.x x y z average_synapse_count <sparse_matrix>\0A\00"
@.str.1 = [63 x i8] c"Error:\0ATarget Synapse Count must be less than 95%% of NW size\0A\00"
@.str.2 = [20 x i8] c"cellConnections.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [27 x i8] c"Error: Couldn't create %s\0A\00"
@RAND_MAX = global i64 0
@.str.5 = [8 x i8] c"%0.2lf \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [14 x i8] c"%d %d %0.2lf\0A\00"
@.str.8 = [41 x i8] c"Average Synapse Count Per Neuron: %0.2f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca float
%21 = alloca i32*
%22 = alloca double*
%23 = alloca float*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %14
store i32 0, i32* %19
store float 0.000000e+00, float* %20
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 4
br i1 %25, label %26, label %48
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %11
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %12
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %13
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = mul nsw i32 %39, %40
%42 = load i32, i32* %13
%43 = mul nsw i32 %41, %42
store i32 %43, i32* %15
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 4
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %16
br label %48
48: ; preds = %26, %2
%49 = load i32, i32* %4
%50 = icmp sgt i32 %49, 5
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 5
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %19
br label %56
56: ; preds = %51, %48
%57 = load i32, i32* %4
%58 = icmp slt i32 %57, 5
br i1 %58, label %62, label %59
59: ; preds = %56
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 6
br i1 %61, label %62, label %65
62: ; preds = %59, %56
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %59
%66 = load i32, i32* %16
%67 = sitofp i32 %66 to double
%68 = load i32, i32* %15
%69 = sitofp i32 %68 to double
%70 = fmul double 0x3FEE666666666666, %69
%71 = fcmp ogt double %67, %70
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %65
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%77 = call i32 @sprintf(i8* %76, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %79, i32** %6
%80 = load i32*, i32** %6
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %86
82: ; preds = %75
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %83)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %75
%87 = load i32, i32* %15
%88 = call i64 @calloc(i32 %87, i32 4)
%89 = inttoptr i64 %88 to i32*
store i32* %89, i32** %21
%90 = load i32, i32* %15
%91 = add nsw i32 %90, 1
%92 = call i64 @calloc(i32 %91, i32 8)
%93 = inttoptr i64 %92 to double*
store double* %93, double** %22
%94 = load double*, double** %22
%95 = load i32, i32* %15
%96 = add nsw i32 %95, 1
%97 = load i32, i32* %16
%98 = call i32 @Gaussian_probability_function(double* %94, i32 %96, i32 %97, i32 1)
%99 = call i32 @time(i32* null)
%100 = call i32 @srand(i32 %99)
store i32 0, i32* %8
br label %101
101: ; preds = %116, %86
%102 = load i32, i32* %8
%103 = load i32, i32* %15
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %119
105: ; preds = %101
%106 = load double*, double** %22
%107 = load i32, i32* %15
%108 = add nsw i32 %107, 1
%109 = load i32, i32* %8
%110 = srem i32 %109, 2
%111 = call i32 @calculate_synapse_count(double* %106, i32 %108, i32 1, i32 %110)
%112 = load i32*, i32** %21
%113 = load i32, i32* %8
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i32, i32* %112, i64 %114
store i32 %111, i32* %115
br label %116
116: ; preds = %105
%117 = load i32, i32* %8
%118 = add nsw i32 %117, 1
store i32 %118, i32* %8
br label %101
119: ; preds = %101
%120 = load double*, double** %22
%121 = call i32 @free(double* %120)
%122 = load i32, i32* %15
%123 = call i64 @calloc(i32 %122, i32 4)
%124 = inttoptr i64 %123 to float*
store float* %124, float** %23
store i32 0, i32* %8
br label %125
125: ; preds = %237, %119
%126 = load i32, i32* %8
%127 = load i32, i32* %15
%128 = icmp slt i32 %126, %127
br i1 %128, label %129, label %240
129: ; preds = %125
store i32 0, i32* %18
br label %130
130: ; preds = %169, %129
%131 = load i32, i32* %18
%132 = load i32*, i32** %21
%133 = load i32, i32* %8
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i32, i32* %132, i64 %134
%136 = load i32, i32* %135
%137 = icmp slt i32 %131, %136
br i1 %137, label %138, label %170
138: ; preds = %130
%139 = call i64 (...) @rand()
%140 = sitofp i64 %139 to float
%141 = load i64, i64* @RAND_MAX
%142 = sitofp i64 %141 to float
%143 = fdiv float %140, %142
%144 = load i32, i32* %15
%145 = sitofp i32 %144 to float
%146 = fmul float %143, %145
%147 = fptosi float %146 to i32
store i32 %147, i32* %17
%148 = load i32, i32* %17
%149 = load i32, i32* %15
%150 = icmp slt i32 %148, %149
br i1 %150, label %151, label %169
151: ; preds = %138
%152 = load i32, i32* %17
%153 = load i32, i32* %8
%154 = icmp ne i32 %152, %153
br i1 %154, label %155, label %169
155: ; preds = %151
%156 = load float*, float** %23
%157 = load i32, i32* %17
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds float, float* %156, i64 %158
%160 = load float, float* %159
%161 = fcmp oeq float %160, 0.000000e+00
br i1 %161, label %162, label %169
162: ; preds = %155
%163 = load float*, float** %23
%164 = load i32, i32* %17
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds float, float* %163, i64 %165
store float 0x3FA47AE140000000, float* %166
%167 = load i32, i32* %18
%168 = add nsw i32 %167, 1
store i32 %168, i32* %18
br label %169
169: ; preds = %162, %155, %151, %138
br label %130
170: ; preds = %130
%171 = load i32, i32* %19
%172 = icmp eq i32 %171, 0
br i1 %172, label %173, label %203
173: ; preds = %170
store i32 0, i32* %9
br label %174
174: ; preds = %197, %173
%175 = load i32, i32* %9
%176 = load i32, i32* %15
%177 = icmp slt i32 %175, %176
br i1 %177, label %178, label %200
178: ; preds = %174
%179 = load i32*, i32** %6
%180 = load float*, float** %23
%181 = load i32, i32* %9
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds float, float* %180, i64 %182
%184 = load float, float* %183
%185 = fpext float %184 to double
%186 = call i32 (i32*, i8*, ...) @fprintf(i32* %179, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %185)
%187 = load float*, float** %23
%188 = load i32, i32* %9
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds float, float* %187, i64 %189
%191 = load float, float* %190
%192 = fcmp ogt float %191, 0.000000e+00
br i1 %192, label %193, label %196
193: ; preds = %178
%194 = load i32, i32* %14
%195 = add nsw i32 %194, 1
store i32 %195, i32* %14
br label %196
196: ; preds = %193, %178
br label %197
197: ; preds = %196
%198 = load i32, i32* %9
%199 = add nsw i32 %198, 1
store i32 %199, i32* %9
br label %174
200: ; preds = %174
%201 = load i32*, i32** %6
%202 = call i32 (i32*, i8*, ...) @fprintf(i32* %201, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %233
203: ; preds = %170
store i32 0, i32* %9
br label %204
204: ; preds = %229, %203
%205 = load i32, i32* %9
%206 = load i32, i32* %15
%207 = icmp slt i32 %205, %206
br i1 %207, label %208, label %232
208: ; preds = %204
%209 = load float*, float** %23
%210 = load i32, i32* %9
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds float, float* %209, i64 %211
%213 = load float, float* %212
%214 = fcmp ogt float %213, 0.000000e+00
br i1 %214, label %215, label %228
215: ; preds = %208
%216 = load i32*, i32** %6
%217 = load i32, i32* %8
%218 = load i32, i32* %9
%219 = load float*, float** %23
%220 = load i32, i32* %9
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds float, float* %219, i64 %221
%223 = load float, float* %222
%224 = fpext float %223 to double
%225 = call i32 (i32*, i8*, ...) @fprintf(i32* %216, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %217, i32 %218, double %224)
%226 = load i32, i32* %14
%227 = add nsw i32 %226, 1
store i32 %227, i32* %14
br label %228
228: ; preds = %215, %208
br label %229
229: ; preds = %228
%230 = load i32, i32* %9
%231 = add nsw i32 %230, 1
store i32 %231, i32* %9
br label %204
232: ; preds = %204
br label %233
233: ; preds = %232, %200
%234 = load float*, float** %23
%235 = load i32, i32* %15
%236 = call i32 @clear_buffer(float* %234, i32 %235)
br label %237
237: ; preds = %233
%238 = load i32, i32* %8
%239 = add nsw i32 %238, 1
store i32 %239, i32* %8
br label %125
240: ; preds = %125
%241 = load i32, i32* %14
%242 = sitofp i32 %241 to float
%243 = load i32, i32* %15
%244 = sitofp i32 %243 to float
%245 = fdiv float %242, %244
store float %245, float* %20
%246 = load float, float* %20
%247 = fpext float %246 to double
%248 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %247)
%249 = load i32*, i32** %6
%250 = call i32 @fclose(i32* %249)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [63 x i8] c"Error:\0ATarget Synapse Count must be less than 95%% of NW size\0A\00"
@.str.2 = [20 x i8] c"cellConnections.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [27 x i8] c"Error: Couldn't create %s\0A\00"
@RAND_MAX = global i64 0
@.str.5 = [8 x i8] c"%0.2lf \00"
@.str.7 = [14 x i8] c"%d %d %0.2lf\0A\00"
@.str.8 = [41 x i8] c"Average Synapse Count Per Neuron: %0.2f\0A\00"
@str = [94 x i8] c"Error: Wrong arguments:\0AUsage: ./conn_generator.x x y z average_synapse_count <sparse_matrix>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 4
br i1 %5, label %6, label %28
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = mul nsw i32 %12, %9
%17 = mul i32 %16, %15
%18 = getelementptr inbounds i8*, i8** %1, i64 4
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp eq i32 %0, 5
br i1 %21, label %31, label %22
22: ; preds = %6
%23 = getelementptr inbounds i8*, i8** %1, i64 5
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = add nsw i32 %0, -7
%27 = icmp ult i32 %26, -2
br i1 %27, label %28, label %31
28: ; preds = %2, %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([94 x i8], [94 x i8]* @str, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %6, %22
%32 = phi i32 [ %25, %22 ], [ 0, %6 ]
%33 = sitofp i32 %20 to double
%34 = sitofp i32 %17 to double
%35 = fmul double %34, 0x3FEE666666666666
%36 = fcmp olt double %35, %33
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = tail call i64 @calloc(i32 %17, i32 4)
%48 = inttoptr i64 %47 to i32*
%49 = add nsw i32 %17, 1
%50 = tail call i64 @calloc(i32 %49, i32 8)
%51 = inttoptr i64 %50 to double*
%52 = tail call i32 @Gaussian_probability_function(double* %51, i32 %49, i32 %20, i32 1)
%53 = tail call i32 @time(i32* null)
%54 = tail call i32 @srand(i32 %53)
%55 = icmp sgt i32 %17, 0
br i1 %55, label %56, label %66
56: ; preds = %46
%57 = zext i32 %17 to i64
br label %58
58: ; preds = %56, %58
%59 = phi i64 [ 0, %56 ], [ %64, %58 ]
%60 = trunc i64 %59 to i32
%61 = and i32 %60, 1
%62 = tail call i32 @calculate_synapse_count(double* %51, i32 %49, i32 1, i32 %61)
%63 = getelementptr inbounds i32, i32* %48, i64 %59
store i32 %62, i32* %63
%64 = add nuw nsw i64 %59, 1
%65 = icmp eq i64 %64, %57
br i1 %65, label %66, label %58
66: ; preds = %58, %46
%67 = tail call i32 @free(double* %51)
%68 = tail call i64 @calloc(i32 %17, i32 4)
%69 = inttoptr i64 %68 to float*
%70 = sitofp i32 %17 to float
br i1 %55, label %71, label %142
71: ; preds = %66
%72 = icmp eq i32 %32, 0
%73 = zext i32 %17 to i64
br label %74
74: ; preds = %71, %137
%75 = phi i64 [ 0, %71 ], [ %140, %137 ]
%76 = phi i32 [ 0, %71 ], [ %138, %137 ]
%77 = getelementptr inbounds i32, i32* %48, i64 %75
%78 = load i32, i32* %77
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %104
80: ; preds = %74, %100
%81 = phi i32 [ %101, %100 ], [ 0, %74 ]
%82 = tail call i64 (...) @rand()
%83 = sitofp i64 %82 to float
%84 = load i64, i64* @RAND_MAX
%85 = sitofp i64 %84 to float
%86 = fdiv float %83, %85
%87 = fmul float %86, %70
%88 = fptosi float %87 to i32
%89 = icmp sle i32 %17, %88
%90 = zext i32 %88 to i64
%91 = icmp eq i64 %75, %90
%92 = select i1 %89, i1 true, i1 %91
br i1 %92, label %100, label %93
93: ; preds = %80
%94 = sext i32 %88 to i64
%95 = getelementptr inbounds float, float* %69, i64 %94
%96 = load float, float* %95
%97 = fcmp oeq float %96, 0.000000e+00
br i1 %97, label %98, label %100
98: ; preds = %93
store float 0x3FA47AE140000000, float* %95
%99 = add nsw i32 %81, 1
br label %100
100: ; preds = %98, %93, %80
%101 = phi i32 [ %99, %98 ], [ %81, %93 ], [ %81, %80 ]
%102 = load i32, i32* %77
%103 = icmp slt i32 %101, %102
br i1 %103, label %80, label %104
104: ; preds = %100, %74
br i1 %72, label %107, label %105
105: ; preds = %104
%106 = trunc i64 %75 to i32
br label %122
107: ; preds = %104, %107
%108 = phi i64 [ %118, %107 ], [ 0, %104 ]
%109 = phi i32 [ %117, %107 ], [ %76, %104 ]
%110 = getelementptr inbounds float, float* %69, i64 %108
%111 = load float, float* %110
%112 = fpext float %111 to double
%113 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %112)
%114 = load float, float* %110
%115 = fcmp ogt float %114, 0.000000e+00
%116 = zext i1 %115 to i32
%117 = add nsw i32 %109, %116
%118 = add nuw nsw i64 %108, 1
%119 = icmp eq i64 %118, %73
br i1 %119, label %120, label %107
120: ; preds = %107
%121 = tail call i32 @fputc(i32 10, i32* %41)
br label %137
122: ; preds = %105, %133
%123 = phi i64 [ 0, %105 ], [ %135, %133 ]
%124 = phi i32 [ %76, %105 ], [ %134, %133 ]
%125 = getelementptr inbounds float, float* %69, i64 %123
%126 = load float, float* %125
%127 = fcmp ogt float %126, 0.000000e+00
br i1 %127, label %128, label %133
128: ; preds = %122
%129 = fpext float %126 to double
%130 = trunc i64 %123 to i32
%131 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %106, i32 %130, double %129)
%132 = add nsw i32 %124, 1
br label %133
133: ; preds = %122, %128
%134 = phi i32 [ %132, %128 ], [ %124, %122 ]
%135 = add nuw nsw i64 %123, 1
%136 = icmp eq i64 %135, %73
br i1 %136, label %137, label %122
137: ; preds = %133, %120
%138 = phi i32 [ %117, %120 ], [ %134, %133 ]
%139 = tail call i32 @clear_buffer(float* %69, i32 %17)
%140 = add nuw nsw i64 %75, 1
%141 = icmp eq i64 %140, %73
br i1 %141, label %142, label %74
142: ; preds = %137, %66
%143 = phi i32 [ 0, %66 ], [ %138, %137 ]
%144 = sitofp i32 %143 to float
%145 = fdiv float %144, %70
%146 = fpext float %145 to double
%147 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), double %146)
%148 = tail call i32 @fclose(i32* %41)
ret i32 0
}