void minibatch(double *data, double *centroids, int n_samples, int max_iter,
               double bic_ratio_termination, double reassignment_ratio, int k,
               int N, int D) {
  do {
    ;
  } while (0);
  int *sample_indicies = (int *)malloc(n_samples * sizeof(int));
  int *centroid_counts = (int *)malloc(k * sizeof(int));
  int *cluster_cache = (int *)malloc(n_samples * sizeof(int));
  int *last_centroid_counts = (int *)malloc(k * sizeof(int));
  int *reassign_centroid_indicies = (int *)malloc(k * sizeof(int));
  int count_diff = 0, reassign_num = 0, max_count_diff = 0;
  double current_bic, bic_sum = 0.0;
  double *historical_bic;
  int historical_bic_idx = 0;
  if (bic_ratio_termination > 0.0) {
    historical_bic = (double *)malloc((10) * sizeof(double));
  }
  for (int i = 0; i < k; i++) {
    centroid_counts[i] = 0;
    last_centroid_counts[i] = 0;
  }
  do {
    ;
  } while (0);
  for (int iter = 0; iter < max_iter; iter++) {
    do {
      ;
    } while (0);
    do {
      ;
    } while (0);
    generate_random_indicies(N, n_samples, sample_indicies);
    minibatch_iteration(data, centroids, sample_indicies, centroid_counts,
                        cluster_cache, n_samples, k, N, D);
    reassign_num = 0;
    max_count_diff = 0;
    for (int i = 0; i < k; i++) {
      count_diff = centroid_counts[i] - last_centroid_counts[i];
      if (count_diff == 0) {
        reassign_centroid_indicies[reassign_num] = i;
        reassign_num += 1;
      }
      if (count_diff > max_count_diff) {
        max_count_diff = count_diff;
      }
    }
    for (int i = 0; i < k; i++) {
      count_diff = centroid_counts[i] - last_centroid_counts[i];
      if (count_diff > 0 && count_diff < max_count_diff * reassignment_ratio) {
        reassign_centroid_indicies[reassign_num] = i;
        reassign_num += 1;
      }
      last_centroid_counts[i] = centroid_counts[i];
    }
    if (reassign_num > 0) {
      do {
        ;
      } while (0);
      reassign_centroids(data, centroids, reassign_centroid_indicies, n_samples,
                         reassign_num, k, N, D);
    }
    if (bic_ratio_termination > 0.0) {
      do {
        ;
      } while (0);
      current_bic = bayesian_information_criterion(data, centroids, k, N, D);
      if (iter > (10)) {
        do {
          ;
        } while (0);
        if (fabs(1.0 - current_bic * (10) / bic_sum) < bic_ratio_termination) {
          do {
            ;
          } while (0);
          break;
        }
      }
      bic_sum += current_bic;
      bic_sum -= historical_bic[historical_bic_idx];
      historical_bic[historical_bic_idx] = current_bic;
      historical_bic_idx = (historical_bic_idx + 1) % (10);
    }
  }
  do {
    ;
  } while (0);
  free(centroid_counts);
  free(sample_indicies);
  free(cluster_cache);
  if (bic_ratio_termination > 0.0) {
    free(historical_bic);
  }
}


x86 assembly (clang, -O0):
<minibatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
jmp    1193 <minibatch+0x33>
movslq -0x14(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x2c(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
movslq -0x14(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x2c(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
movslq -0x2c(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movl   $0x0,-0x84(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    122f <minibatch+0xcf>
mov    $0x50,%edi
call   1070 <malloc@plt>
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1280 <minibatch+0x120>
mov    -0x40(%rbp),%rax
movslq -0x88(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x50(%rbp),%rax
movslq -0x88(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1239 <minibatch+0xd9>
jmp    1285 <minibatch+0x125>
jmp    128a <minibatch+0x12a>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    158d <minibatch+0x42d>
jmp    12a8 <minibatch+0x148>
jmp    12ad <minibatch+0x14d>
jmp    12b2 <minibatch+0x152>
jmp    12b7 <minibatch+0x157>
mov    -0x30(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    $0x0,%al
call   1050 <generate_random_indicies@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    -0x2c(%rbp),%r11d
mov    -0x30(%rbp),%r10d
mov    0x10(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1060 <minibatch_iteration@plt>
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1394 <minibatch+0x234>
mov    -0x40(%rbp),%rax
movslq -0x90(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x50(%rbp),%rcx
movslq -0x90(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1369 <minibatch+0x209>
mov    -0x90(%rbp),%edx
mov    -0x58(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x64(%rbp),%eax
jle    137b <minibatch+0x21b>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    1380 <minibatch+0x220>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    1317 <minibatch+0x1b7>
movl   $0x0,-0x94(%rbp)
mov    -0x94(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1439 <minibatch+0x2d9>
mov    -0x40(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x50(%rbp),%rcx
movslq -0x94(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jle    1409 <minibatch+0x2a9>
cvtsi2sdl -0x5c(%rbp),%xmm1
cvtsi2sdl -0x64(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1409 <minibatch+0x2a9>
mov    -0x94(%rbp),%edx
mov    -0x58(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x50(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    139e <minibatch+0x23e>
cmpl   $0x0,-0x60(%rbp)
jle    147a <minibatch+0x31a>
jmp    1448 <minibatch+0x2e8>
jmp    144d <minibatch+0x2ed>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x60(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r10d
mov    0x10(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1040 <reassign_centroids@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1574 <minibatch+0x414>
jmp    1491 <minibatch+0x331>
jmp    1496 <minibatch+0x336>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    0x10(%rbp),%r8d
mov    $0x0,%al
call   1080 <bayesian_information_criterion@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x70(%rbp)
cmpl   $0xa,-0x8c(%rbp)
jle    151b <minibatch+0x3bb>
jmp    14ca <minibatch+0x36a>
jmp    14cf <minibatch+0x36f>
movsd  0xb41(%rip),%xmm0
mulsd  -0x70(%rbp),%xmm0
divsd  -0x78(%rbp),%xmm0
movsd  0xb27(%rip),%xmm1
subsd  %xmm0,%xmm1
movaps 0xb0c(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1516 <minibatch+0x3b6>
jmp    150c <minibatch+0x3ac>
jmp    1511 <minibatch+0x3b1>
jmp    158d <minibatch+0x42d>
jmp    151b <minibatch+0x3bb>
movsd  -0x70(%rbp),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x80(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x78(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
mov    -0x80(%rbp),%rax
movslq -0x84(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x84(%rbp)
jmp    1579 <minibatch+0x419>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1294 <minibatch+0x134>
jmp    1592 <minibatch+0x432>
jmp    1597 <minibatch+0x437>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    15cd <minibatch+0x46d>
mov    -0x80(%rbp),%rdi
call   1030 <free@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minibatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,0x38(%rsp)
mov    %r8d,%ebx
movsd  %xmm1,0x60(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %ecx,0x4(%rsp)
mov    %rsi,0x30(%rsp)
mov    %rdi,0x28(%rsp)
mov    0xb0(%rsp),%eax
mov    %rax,0x20(%rsp)
mov    %edx,0x8(%rsp)
movslq %edx,%r15
shl    $0x2,%r15
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,0x58(%rsp)
movslq %ebx,%rbp
shl    $0x2,%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,0x50(%rsp)
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%r12
xorpd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1218 <minibatch+0xa8>
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,0x40(%rsp)
mov    %ebx,%ebp
mov    %rbx,0x70(%rsp)
test   %ebx,%ebx
jle    1245 <minibatch+0xd5>
lea    0x0(,%rbp,4),%rbx
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
cmpl   $0x0,0x4(%rsp)
jle    14d9 <minibatch+0x369>
mov    %ebp,%eax
and    $0xfffffffe,%eax
mov    %rax,0x68(%rsp)
xor    %esi,%esi
movl   $0x0,(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %rbp,0x48(%rsp)
mov    0x8(%rsp),%r14d
jmp    1291 <minibatch+0x121>
nopl   0x0(%rax)
mov    0xc(%rsp),%esi
add    $0x1,%esi
cmp    0x4(%rsp),%esi
je     14d9 <minibatch+0x369>
mov    %esi,0xc(%rsp)
mov    0x38(%rsp),%rbx
mov    %ebx,%edi
mov    %r14d,%esi
mov    0x58(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <generate_random_indicies@plt>
sub    $0x8,%rsp
mov    0x30(%rsp),%rdi
mov    0x38(%rsp),%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
mov    0x58(%rsp),%r8
mov    %r14d,%r9d
xor    %eax,%eax
push   0x28(%rsp)
push   %rbx
mov    0x88(%rsp),%rbx
push   %rbx
call   1070 <minibatch_iteration@plt>
add    $0x20,%rsp
test   %ebx,%ebx
mov    0x68(%rsp),%rbp
jle    13ac <minibatch+0x23c>
xor    %ecx,%ecx
xor    %eax,%eax
xor    %r8d,%r8d
cmp    $0x1,%ebx
jne    1480 <minibatch+0x310>
mov    0x48(%rsp),%rdi
test   $0x1,%dil
je     1326 <minibatch+0x1b6>
mov    0x0(%r13,%rcx,4),%edx
sub    (%r15,%rcx,4),%edx
jne    1321 <minibatch+0x1b1>
movslq %r8d,%r8
mov    %ecx,(%r12,%r8,4)
add    $0x1,%r8d
cmp    %eax,%edx
cmovg  %edx,%eax
test   %ebx,%ebx
jle    1380 <minibatch+0x210>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x60(%rsp),%xmm0
xor    %eax,%eax
jmp    134d <minibatch+0x1dd>
nopl   0x0(%rax,%rax,1)
mov    %ecx,(%r15,%rax,4)
add    $0x1,%rax
cmp    %rax,%rdi
je     1380 <minibatch+0x210>
mov    0x0(%r13,%rax,4),%ecx
mov    %ecx,%edx
sub    (%r15,%rax,4),%edx
test   %edx,%edx
jle    1340 <minibatch+0x1d0>
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
ucomisd %xmm1,%xmm0
jbe    1340 <minibatch+0x1d0>
movslq %r8d,%r8
mov    %eax,(%r12,%r8,4)
add    $0x1,%r8d
jmp    1340 <minibatch+0x1d0>
cs nopw 0x0(%rax,%rax,1)
test   %r8d,%r8d
jle    13ac <minibatch+0x23c>
mov    0x28(%rsp),%rdi
mov    0x30(%rsp),%rsi
mov    %r12,%rdx
mov    0x8(%rsp),%ecx
mov    %ebx,%r9d
xor    %eax,%eax
push   0x20(%rsp)
push   0x40(%rsp)
call   1040 <reassign_centroids@plt>
add    $0x10,%rsp
movsd  0x10(%rsp),%xmm0
ucomisd 0xc56(%rip),%xmm0
jbe    1280 <minibatch+0x110>
mov    0x28(%rsp),%rdi
mov    0x30(%rsp),%rsi
mov    %ebx,%edx
mov    0x38(%rsp),%rcx
mov    0x20(%rsp),%r8
xor    %eax,%eax
call   1090 <bayesian_information_criterion@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0xc(%rsp),%esi
cmp    $0xb,%esi
jb     141f <minibatch+0x2af>
movapd %xmm0,%xmm1
mulsd  0xc07(%rip),%xmm1
divsd  0x18(%rsp),%xmm1
addsd  0xc01(%rip),%xmm1
andpd  0xc11(%rip),%xmm1
movsd  0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     14d9 <minibatch+0x369>
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movslq (%rsp),%rax
mov    0x40(%rsp),%rcx
subsd  (%rcx,%rax,8),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,(%rcx,%rax,8)
mov    %eax,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%rsp)
jmp    1284 <minibatch+0x114>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x48(%rsp),%rdi
jmp    14a2 <minibatch+0x332>
nopw   0x0(%rax,%rax,1)
cmp    %eax,%edx
cmovg  %edx,%eax
add    $0x2,%rcx
cmp    %rcx,%rbp
je     1305 <minibatch+0x195>
mov    0x0(%r13,%rcx,4),%edx
sub    (%r15,%rcx,4),%edx
jne    14b8 <minibatch+0x348>
movslq %r8d,%r8
mov    %ecx,(%r12,%r8,4)
add    $0x1,%r8d
cmp    %eax,%edx
cmovg  %edx,%eax
mov    0x4(%r13,%rcx,4),%edx
sub    0x4(%r15,%rcx,4),%edx
jne    1490 <minibatch+0x320>
movslq %r8d,%r8
lea    0x1(%rcx),%esi
mov    %esi,(%r12,%r8,4)
add    $0x1,%r8d
jmp    1490 <minibatch+0x320>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x58(%rsp),%rdi
call   1030 <free@plt>
mov    0x50(%rsp),%rdi
call   1030 <free@plt>
xorpd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    151d <minibatch+0x3ad>
mov    0x40(%rsp),%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @minibatch(double* %0, double* %1, i32 %2, i32 %3, double %4, double %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca double
%28 = alloca double
%29 = alloca double*
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
%33 = alloca i32
%34 = alloca i32
store double* %0, double** %10
store double* %1, double** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store double %4, double* %14
store double %5, double* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
br label %35
35: ; preds = %9
br label %36
36: ; preds = %35
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 4
%40 = call i8* @malloc(i64 %39)
%41 = bitcast i8* %40 to i32*
store i32* %41, i32** %19
%42 = load i32, i32* %16
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = call i8* @malloc(i64 %44)
%46 = bitcast i8* %45 to i32*
store i32* %46, i32** %20
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 4
%50 = call i8* @malloc(i64 %49)
%51 = bitcast i8* %50 to i32*
store i32* %51, i32** %21
%52 = load i32, i32* %16
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 4
%55 = call i8* @malloc(i64 %54)
%56 = bitcast i8* %55 to i32*
store i32* %56, i32** %22
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = mul i64 %58, 4
%60 = call i8* @malloc(i64 %59)
%61 = bitcast i8* %60 to i32*
store i32* %61, i32** %23
store i32 0, i32* %24
store i32 0, i32* %25
store i32 0, i32* %26
store double 0.000000e+00, double* %28
store i32 0, i32* %30
%62 = load double, double* %14
%63 = fcmp ogt double %62, 0.000000e+00
br i1 %63, label %64, label %67
64: ; preds = %36
%65 = call i8* @malloc(i64 80)
%66 = bitcast i8* %65 to double*
store double* %66, double** %29
br label %67
67: ; preds = %64, %36
store i32 0, i32* %31
br label %68
68: ; preds = %81, %67
%69 = load i32, i32* %31
%70 = load i32, i32* %16
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %84
72: ; preds = %68
%73 = load i32*, i32** %20
%74 = load i32, i32* %31
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i32, i32* %73, i64 %75
store i32 0, i32* %76
%77 = load i32*, i32** %22
%78 = load i32, i32* %31
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 0, i32* %80
br label %81
81: ; preds = %72
%82 = load i32, i32* %31
%83 = add nsw i32 %82, 1
store i32 %83, i32* %31
br label %68
84: ; preds = %68
br label %85
85: ; preds = %84
br label %86
86: ; preds = %85
store i32 0, i32* %32
br label %87
87: ; preds = %259, %86
%88 = load i32, i32* %32
%89 = load i32, i32* %13
%90 = icmp slt i32 %88, %89
br i1 %90, label %91, label %262
91: ; preds = %87
br label %92
92: ; preds = %91
br label %93
93: ; preds = %92
br label %94
94: ; preds = %93
br label %95
95: ; preds = %94
%96 = load i32, i32* %17
%97 = load i32, i32* %12
%98 = load i32*, i32** %19
%99 = call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @generate_random_indicies to i32 (i32, i32, i32*, ...)*)(i32 %96, i32 %97, i32* %98)
%100 = load double*, double** %10
%101 = load double*, double** %11
%102 = load i32*, i32** %19
%103 = load i32*, i32** %20
%104 = load i32*, i32** %21
%105 = load i32, i32* %12
%106 = load i32, i32* %16
%107 = load i32, i32* %17
%108 = load i32, i32* %18
%109 = call i32 (double*, double*, i32*, i32*, i32*, i32, i32, i32, i32, ...) bitcast (i32 (...)* @minibatch_iteration to i32 (double*, double*, i32*, i32*, i32*, i32, i32, i32, i32, ...)*)(double* %100, double* %101, i32* %102, i32* %103, i32* %104, i32 %105, i32 %106, i32 %107, i32 %108)
store i32 0, i32* %25
store i32 0, i32* %26
store i32 0, i32* %33
br label %110
110: ; preds = %143, %95
%111 = load i32, i32* %33
%112 = load i32, i32* %16
%113 = icmp slt i32 %111, %112
br i1 %113, label %114, label %146
114: ; preds = %110
%115 = load i32*, i32** %20
%116 = load i32, i32* %33
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds i32, i32* %115, i64 %117
%119 = load i32, i32* %118
%120 = load i32*, i32** %22
%121 = load i32, i32* %33
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %120, i64 %122
%124 = load i32, i32* %123
%125 = sub nsw i32 %119, %124
store i32 %125, i32* %24
%126 = load i32, i32* %24
%127 = icmp eq i32 %126, 0
br i1 %127, label %128, label %136
128: ; preds = %114
%129 = load i32, i32* %33
%130 = load i32*, i32** %23
%131 = load i32, i32* %25
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i32, i32* %130, i64 %132
store i32 %129, i32* %133
%134 = load i32, i32* %25
%135 = add nsw i32 %134, 1
store i32 %135, i32* %25
br label %136
136: ; preds = %128, %114
%137 = load i32, i32* %24
%138 = load i32, i32* %26
%139 = icmp sgt i32 %137, %138
br i1 %139, label %140, label %142
140: ; preds = %136
%141 = load i32, i32* %24
store i32 %141, i32* %26
br label %142
142: ; preds = %140, %136
br label %143
143: ; preds = %142
%144 = load i32, i32* %33
%145 = add nsw i32 %144, 1
store i32 %145, i32* %33
br label %110
146: ; preds = %110
store i32 0, i32* %34
br label %147
147: ; preds = %191, %146
%148 = load i32, i32* %34
%149 = load i32, i32* %16
%150 = icmp slt i32 %148, %149
br i1 %150, label %151, label %194
151: ; preds = %147
%152 = load i32*, i32** %20
%153 = load i32, i32* %34
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i32, i32* %152, i64 %154
%156 = load i32, i32* %155
%157 = load i32*, i32** %22
%158 = load i32, i32* %34
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds i32, i32* %157, i64 %159
%161 = load i32, i32* %160
%162 = sub nsw i32 %156, %161
store i32 %162, i32* %24
%163 = load i32, i32* %24
%164 = icmp sgt i32 %163, 0
br i1 %164, label %165, label %181
165: ; preds = %151
%166 = load i32, i32* %24
%167 = sitofp i32 %166 to double
%168 = load i32, i32* %26
%169 = sitofp i32 %168 to double
%170 = load double, double* %15
%171 = fmul double %169, %170
%172 = fcmp olt double %167, %171
br i1 %172, label %173, label %181
173: ; preds = %165
%174 = load i32, i32* %34
%175 = load i32*, i32** %23
%176 = load i32, i32* %25
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i32, i32* %175, i64 %177
store i32 %174, i32* %178
%179 = load i32, i32* %25
%180 = add nsw i32 %179, 1
store i32 %180, i32* %25
br label %181
181: ; preds = %173, %165, %151
%182 = load i32*, i32** %20
%183 = load i32, i32* %34
%184 = sext i32 %183 to i64
%185 = getelementptr inbounds i32, i32* %182, i64 %184
%186 = load i32, i32* %185
%187 = load i32*, i32** %22
%188 = load i32, i32* %34
%189 = sext i32 %188 to i64
%190 = getelementptr inbounds i32, i32* %187, i64 %189
store i32 %186, i32* %190
br label %191
191: ; preds = %181
%192 = load i32, i32* %34
%193 = add nsw i32 %192, 1
store i32 %193, i32* %34
br label %147
194: ; preds = %147
%195 = load i32, i32* %25
%196 = icmp sgt i32 %195, 0
br i1 %196, label %197, label %209
197: ; preds = %194
br label %198
198: ; preds = %197
br label %199
199: ; preds = %198
%200 = load double*, double** %10
%201 = load double*, double** %11
%202 = load i32*, i32** %23
%203 = load i32, i32* %12
%204 = load i32, i32* %25
%205 = load i32, i32* %16
%206 = load i32, i32* %17
%207 = load i32, i32* %18
%208 = call i32 (double*, double*, i32*, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @reassign_centroids to i32 (double*, double*, i32*, i32, i32, i32, i32, i32, ...)*)(double* %200, double* %201, i32* %202, i32 %203, i32 %204, i32 %205, i32 %206, i32 %207)
br label %209
209: ; preds = %199, %194
%210 = load double, double* %14
%211 = fcmp ogt double %210, 0.000000e+00
br i1 %211, label %212, label %258
212: ; preds = %209
br label %213
213: ; preds = %212
br label %214
214: ; preds = %213
%215 = load double*, double** %10
%216 = load double*, double** %11
%217 = load i32, i32* %16
%218 = load i32, i32* %17
%219 = load i32, i32* %18
%220 = call i32 (double*, double*, i32, i32, i32, ...) bitcast (i32 (...)* @bayesian_information_criterion to i32 (double*, double*, i32, i32, i32, ...)*)(double* %215, double* %216, i32 %217, i32 %218, i32 %219)
%221 = sitofp i32 %220 to double
store double %221, double* %27
%222 = load i32, i32* %32
%223 = icmp sgt i32 %222, 10
br i1 %223, label %224, label %239
224: ; preds = %214
br label %225
225: ; preds = %224
br label %226
226: ; preds = %225
%227 = load double, double* %27
%228 = fmul double %227, 1.000000e+01
%229 = load double, double* %28
%230 = fdiv double %228, %229
%231 = fsub double 1.000000e+00, %230
%232 = call double @llvm.fabs.f64(double %231)
%233 = load double, double* %14
%234 = fcmp olt double %232, %233
br i1 %234, label %235, label %238
235: ; preds = %226
br label %236
236: ; preds = %235
br label %237
237: ; preds = %236
br label %262
238: ; preds = %226
br label %239
239: ; preds = %238, %214
%240 = load double, double* %27
%241 = load double, double* %28
%242 = fadd double %241, %240
store double %242, double* %28
%243 = load double*, double** %29
%244 = load i32, i32* %30
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds double, double* %243, i64 %245
%247 = load double, double* %246
%248 = load double, double* %28
%249 = fsub double %248, %247
store double %249, double* %28
%250 = load double, double* %27
%251 = load double*, double** %29
%252 = load i32, i32* %30
%253 = sext i32 %252 to i64
%254 = getelementptr inbounds double, double* %251, i64 %253
store double %250, double* %254
%255 = load i32, i32* %30
%256 = add nsw i32 %255, 1
%257 = srem i32 %256, 10
store i32 %257, i32* %30
br label %258
258: ; preds = %239, %209
br label %259
259: ; preds = %258
%260 = load i32, i32* %32
%261 = add nsw i32 %260, 1
store i32 %261, i32* %32
br label %87
262: ; preds = %237, %87
br label %263
263: ; preds = %262
br label %264
264: ; preds = %263
%265 = load i32*, i32** %20
%266 = bitcast i32* %265 to i8*
%267 = load i32*, i32** %19
%268 = bitcast i32* %267 to i8*
%269 = load i32*, i32** %21
%270 = bitcast i32* %269 to i8*
%271 = load double, double* %14
%272 = fcmp ogt double %271, 0.000000e+00
br i1 %272, label %273, label %276
273: ; preds = %264
%274 = load double*, double** %29
%275 = bitcast double* %274 to i8*
br label %276
276: ; preds = %273, %264
ret void
}

LLVM IR (-O2):
define void @minibatch(double* %0, double* %1, i32 %2, i32 %3, double %4, double %5, i32 %6, i32 %7, i32 %8) {
%10 = sext i32 %2 to i64
%11 = shl nsw i64 %10, 2
%12 = tail call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to i32*
%14 = sext i32 %6 to i64
%15 = shl nsw i64 %14, 2
%16 = tail call i8* @malloc(i64 %15)
%17 = bitcast i8* %16 to i32*
%18 = tail call i8* @malloc(i64 %11)
%19 = bitcast i8* %18 to i32*
%20 = tail call i8* @malloc(i64 %15)
%21 = bitcast i8* %20 to i32*
%22 = tail call i8* @malloc(i64 %15)
%23 = bitcast i8* %22 to i32*
%24 = fcmp ogt double %4, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %9
%26 = tail call dereferenceable_or_null(80) i8* @malloc(i64 80)
%27 = bitcast i8* %26 to double*
br label %28
28: ; preds = %25, %9
%29 = phi double* [ %27, %25 ], [ undef, %9 ]
%30 = icmp sgt i32 %6, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = zext i32 %6 to i64
%33 = shl nuw nsw i64 %32, 2
br label %34
34: ; preds = %31, %28
%35 = icmp sgt i32 %3, 0
br i1 %35, label %36, label %166
36: ; preds = %34
%37 = zext i32 %6 to i64
%38 = and i64 %37, 1
%39 = icmp eq i32 %6, 1
%40 = and i64 %37, 4294967294
%41 = icmp eq i64 %38, 0
br label %42
42: ; preds = %36, %161
%43 = phi i32 [ 0, %36 ], [ %164, %161 ]
%44 = phi i32 [ 0, %36 ], [ %163, %161 ]
%45 = phi double [ 0.000000e+00, %36 ], [ %162, %161 ]
%46 = tail call i32 (i32, i32, i32*, ...) bitcast (i32 (...)* @generate_random_indicies to i32 (i32, i32, i32*, ...)*)(i32 %7, i32 %2, i32* %13)
%47 = tail call i32 (double*, double*, i32*, i32*, i32*, i32, i32, i32, i32, ...) bitcast (i32 (...)* @minibatch_iteration to i32 (double*, double*, i32*, i32*, i32*, i32, i32, i32, i32, ...)*)(double* %0, double* %1, i32* %13, i32* %17, i32* %19, i32 %2, i32 %6, i32 %7, i32 %8)
br i1 %30, label %48, label %142
48: ; preds = %42
br i1 %39, label %49, label %77
49: ; preds = %109, %48
%50 = phi i32 [ undef, %48 ], [ %110, %109 ]
%51 = phi i32 [ undef, %48 ], [ %112, %109 ]
%52 = phi i64 [ 0, %48 ], [ %113, %109 ]
%53 = phi i32 [ 0, %48 ], [ %112, %109 ]
%54 = phi i32 [ 0, %48 ], [ %110, %109 ]
br i1 %41, label %71, label %55
55: ; preds = %49
%56 = getelementptr inbounds i32, i32* %17, i64 %52
%57 = load i32, i32* %56
%58 = getelementptr inbounds i32, i32* %21, i64 %52
%59 = load i32, i32* %58
%60 = sub nsw i32 %57, %59
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %55
%63 = sext i32 %54 to i64
%64 = getelementptr inbounds i32, i32* %23, i64 %63
%65 = trunc i64 %52 to i32
store i32 %65, i32* %64
%66 = add nsw i32 %54, 1
br label %67
67: ; preds = %62, %55
%68 = phi i32 [ %66, %62 ], [ %54, %55 ]
%69 = icmp sgt i32 %60, %53
%70 = select i1 %69, i32 %60, i32 %53
br label %71
71: ; preds = %49, %67
%72 = phi i32 [ %50, %49 ], [ %68, %67 ]
%73 = phi i32 [ %51, %49 ], [ %70, %67 ]
br i1 %30, label %74, label %116
74: ; preds = %71
%75 = sitofp i32 %73 to double
%76 = fmul double %75, %5
br label %119
77: ; preds = %48, %109
%78 = phi i64 [ %113, %109 ], [ 0, %48 ]
%79 = phi i32 [ %112, %109 ], [ 0, %48 ]
%80 = phi i32 [ %110, %109 ], [ 0, %48 ]
%81 = phi i64 [ %114, %109 ], [ 0, %48 ]
%82 = getelementptr inbounds i32, i32* %17, i64 %78
%83 = load i32, i32* %82
%84 = getelementptr inbounds i32, i32* %21, i64 %78
%85 = load i32, i32* %84
%86 = sub nsw i32 %83, %85
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %93
88: ; preds = %77
%89 = sext i32 %80 to i64
%90 = getelementptr inbounds i32, i32* %23, i64 %89
%91 = trunc i64 %78 to i32
store i32 %91, i32* %90
%92 = add nsw i32 %80, 1
br label %93
93: ; preds = %88, %77
%94 = phi i32 [ %92, %88 ], [ %80, %77 ]
%95 = icmp sgt i32 %86, %79
%96 = select i1 %95, i32 %86, i32 %79
%97 = or i64 %78, 1
%98 = getelementptr inbounds i32, i32* %17, i64 %97
%99 = load i32, i32* %98
%100 = getelementptr inbounds i32, i32* %21, i64 %97
%101 = load i32, i32* %100
%102 = sub nsw i32 %99, %101
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %93
%105 = sext i32 %94 to i64
%106 = getelementptr inbounds i32, i32* %23, i64 %105
%107 = trunc i64 %97 to i32
store i32 %107, i32* %106
%108 = add nsw i32 %94, 1
br label %109
109: ; preds = %104, %93
%110 = phi i32 [ %108, %104 ], [ %94, %93 ]
%111 = icmp sgt i32 %102, %96
%112 = select i1 %111, i32 %102, i32 %96
%113 = add nuw nsw i64 %78, 2
%114 = add i64 %81, 2
%115 = icmp eq i64 %114, %40
br i1 %115, label %49, label %77
116: ; preds = %136, %71
%117 = phi i32 [ %72, %71 ], [ %137, %136 ]
%118 = icmp sgt i32 %117, 0
br i1 %118, label %140, label %142
119: ; preds = %74, %136
%120 = phi i64 [ 0, %74 ], [ %138, %136 ]
%121 = phi i32 [ %72, %74 ], [ %137, %136 ]
%122 = getelementptr inbounds i32, i32* %17, i64 %120
%123 = load i32, i32* %122
%124 = getelementptr inbounds i32, i32* %21, i64 %120
%125 = load i32, i32* %124
%126 = sub nsw i32 %123, %125
%127 = icmp sgt i32 %126, 0
%128 = sitofp i32 %126 to double
%129 = fcmp ogt double %76, %128
%130 = select i1 %127, i1 %129, i1 false
br i1 %130, label %131, label %136
131: ; preds = %119
%132 = sext i32 %121 to i64
%133 = getelementptr inbounds i32, i32* %23, i64 %132
%134 = trunc i64 %120 to i32
store i32 %134, i32* %133
%135 = add nsw i32 %121, 1
br label %136
136: ; preds = %131, %119
%137 = phi i32 [ %135, %131 ], [ %121, %119 ]
store i32 %123, i32* %124
%138 = add nuw nsw i64 %120, 1
%139 = icmp eq i64 %138, %37
br i1 %139, label %116, label %119
140: ; preds = %116
%141 = tail call i32 (double*, double*, i32*, i32, i32, i32, i32, i32, ...) bitcast (i32 (...)* @reassign_centroids to i32 (double*, double*, i32*, i32, i32, i32, i32, i32, ...)*)(double* %0, double* %1, i32* %23, i32 %2, i32 %117, i32 %6, i32 %7, i32 %8)
br label %142
142: ; preds = %42, %140, %116
br i1 %24, label %143, label %161
143: ; preds = %142
%144 = tail call i32 (double*, double*, i32, i32, i32, ...) bitcast (i32 (...)* @bayesian_information_criterion to i32 (double*, double*, i32, i32, i32, ...)*)(double* %0, double* %1, i32 %6, i32 %7, i32 %8)
%145 = sitofp i32 %144 to double
%146 = icmp ugt i32 %43, 10
br i1 %146, label %147, label %153
147: ; preds = %143
%148 = fmul double %145, 1.000000e+01
%149 = fdiv double %148, %45
%150 = fsub double 1.000000e+00, %149
%151 = tail call double @llvm.fabs.f64(double %150)
%152 = fcmp olt double %151, %4
br i1 %152, label %166, label %153
153: ; preds = %147, %143
%154 = fadd double %45, %145
%155 = sext i32 %44 to i64
%156 = getelementptr inbounds double, double* %29, i64 %155
%157 = load double, double* %156
%158 = fsub double %154, %157
store double %145, double* %156
%159 = add nsw i32 %44, 1
%160 = srem i32 %159, 10
br label %161
161: ; preds = %142, %153
%162 = phi double [ %158, %153 ], [ %45, %142 ]
%163 = phi i32 [ %160, %153 ], [ %44, %142 ]
%164 = add nuw nsw i32 %43, 1
%165 = icmp eq i32 %164, %3
br i1 %165, label %166, label %42
166: ; preds = %161, %147, %34
tail call void @free(i8* %16)
tail call void @free(i8* %12)
tail call void @free(i8* %18)
br i1 %24, label %167, label %169
167: ; preds = %166
%168 = bitcast double* %29 to i8*
tail call void @free(i8* %168)
br label %169
169: ; preds = %167, %166
ret void
}