#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
void calc_cluster_centroids(int dim, int n, int k, double *X,
                            int *cluster_assignment_index,
                            double *new_cluster_centroid) {
  int cluster_member_count[16];
  for (int ii = 0; ii < k; ii++) {
    cluster_member_count[ii] = 0;
    for (int jj = 0; jj < dim; jj++)
      new_cluster_centroid[ii * dim + jj] = 0;
  }
  for (int ii = 0; ii < n; ii++) {
    int active_cluster = cluster_assignment_index[ii];
    cluster_member_count[active_cluster]++;
    for (int jj = 0; jj < dim; jj++)
      new_cluster_centroid[active_cluster * dim + jj] += X[ii * dim + jj];
  }
  for (int ii = 0; ii < k; ii++) {
    if (cluster_member_count[ii] == 0)
      printf("WARNING: Empty cluster %d! \n", ii);
    for (int jj = 0; jj < dim; jj++)
      new_cluster_centroid[ii * dim + jj] /= cluster_member_count[ii];
  }
}


x86 assembly (clang, -O0):
<calc_cluster_centroids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119c <calc_cluster_centroids+0x8c>
movslq -0x74(%rbp),%rax
movl   $0x0,-0x70(%rbp,%rax,4)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1189 <calc_cluster_centroids+0x79>
mov    -0x28(%rbp),%rax
mov    -0x74(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x78(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1156 <calc_cluster_centroids+0x46>
jmp    118e <calc_cluster_centroids+0x7e>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1137 <calc_cluster_centroids+0x27>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1243 <calc_cluster_centroids+0x133>
mov    -0x20(%rbp),%rax
movslq -0x7c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x80(%rbp)
movslq -0x80(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x70(%rbp,%rax,4)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1230 <calc_cluster_centroids+0x120>
mov    -0x18(%rbp),%rax
mov    -0x7c(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x84(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x80(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x84(%rbp),%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11d6 <calc_cluster_centroids+0xc6>
jmp    1235 <calc_cluster_centroids+0x125>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11a3 <calc_cluster_centroids+0x93>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f8 <calc_cluster_centroids+0x1e8>
movslq -0x88(%rbp),%rax
cmpl   $0x0,-0x70(%rbp,%rax,4)
jne    1280 <calc_cluster_centroids+0x170>
mov    -0x88(%rbp),%esi
lea    0xd85(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12df <calc_cluster_centroids+0x1cf>
movslq -0x88(%rbp),%rax
cvtsi2sdl -0x70(%rbp,%rax,4),%xmm1
mov    -0x28(%rbp),%rax
mov    -0x88(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x8c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    128a <calc_cluster_centroids+0x17a>
jmp    12e4 <calc_cluster_centroids+0x1d4>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    124d <calc_cluster_centroids+0x13d>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_cluster_centroids>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9,%rbx
mov    %r8,0x30(%rsp)
mov    %rcx,(%rsp)
mov    %esi,%r14d
mov    %edi,%r13d
mov    %edx,%eax
mov    %rax,0x48(%rsp)
mov    %edx,0x44(%rsp)
test   %edx,%edx
mov    %rdi,0x8(%rsp)
jle    11d4 <calc_cluster_centroids+0xb4>
mov    %r14d,0x38(%rsp)
lea    0x0(,%r13,8),%r12
mov    0x48(%rsp),%rbp
lea    0x0(,%rbp,4),%rdx
lea    0x60(%rsp),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x1(%rbp),%rax
mov    %ebp,%r15d
and    $0x3,%r15d
cmp    $0x3,%rax
jae    159f <calc_cluster_centroids+0x47f>
xor    %ebp,%ebp
mov    0x8(%rsp),%rdi
test   %r15,%r15
mov    0x38(%rsp),%r14d
je     11d4 <calc_cluster_centroids+0xb4>
imul   %edi,%ebp
jmp    11b8 <calc_cluster_centroids+0x98>
nopl   0x0(%rax,%rax,1)
add    %edi,%ebp
add    $0xffffffffffffffff,%r15
je     11d4 <calc_cluster_centroids+0xb4>
test   %edi,%edi
jle    11b0 <calc_cluster_centroids+0x90>
movslq %ebp,%rax
lea    (%rbx,%rax,8),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    0x8(%rsp),%rdi
jmp    11b0 <calc_cluster_centroids+0x90>
movslq %edi,%rax
mov    %rax,0x10(%rsp)
test   %r14d,%r14d
mov    0x30(%rsp),%rbp
jle    141b <calc_cluster_centroids+0x2fb>
mov    %r14d,%r12d
lea    (%rbx,%r13,8),%rax
mov    %rax,0x20(%rsp)
mov    %r13d,%r14d
and    $0xfffffffc,%r14d
lea    -0x4(%r14),%rax
mov    %rax,0x18(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x38(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x58(%rsp)
mov    %r13,%r15
neg    %r15
mov    (%rsp),%rax
lea    0x30(%rax),%rcx
mov    0x10(%rsp),%rdx
lea    0x0(,%rdx,8),%r11
lea    0x30(%rbx),%rdx
mov    %rdx,0x50(%rsp)
lea    0x8(%rbx),%rdx
mov    %rdx,0x28(%rsp)
lea    0x8(%rax),%r9
xor    %r10d,%r10d
jmp    1278 <calc_cluster_centroids+0x158>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r10
add    %r11,%rcx
add    %r11,%r9
cmp    %r12,%r10
mov    0x8(%rsp),%rdi
je     141b <calc_cluster_centroids+0x2fb>
movslq 0x0(%rbp,%r10,4),%r8
addl   $0x1,0x60(%rsp,%r8,4)
test   %edi,%edi
jle    1260 <calc_cluster_centroids+0x140>
mov    %r10,%rdx
mov    0x10(%rsp),%rax
imul   %rax,%rdx
imul   %rax,%r8
cmpl   $0x4,0x8(%rsp)
jb     12c9 <calc_cluster_centroids+0x1a9>
lea    (%rdx,%r13,1),%rax
mov    (%rsp),%rdi
lea    (%rdi,%rax,8),%rax
lea    (%rbx,%r8,8),%rsi
cmp    %rax,%rsi
jae    1341 <calc_cluster_centroids+0x221>
lea    (%rdi,%rdx,8),%rax
mov    0x20(%rsp),%rsi
lea    (%rsi,%r8,8),%rsi
cmp    %rsi,%rax
jae    1341 <calc_cluster_centroids+0x221>
xor    %esi,%esi
mov    %rsi,%rax
test   $0x1,%r13b
je     12f5 <calc_cluster_centroids+0x1d5>
add    %rsi,%rdx
mov    (%rsp),%rax
movsd  (%rax,%rdx,8),%xmm0
lea    (%rsi,%r8,1),%rax
addsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    %rsi,%rax
or     $0x1,%rax
not    %rsi
cmp    %r15,%rsi
je     1260 <calc_cluster_centroids+0x140>
mov    0x28(%rsp),%rdx
lea    (%rdx,%r8,8),%rdx
nopw   0x0(%rax,%rax,1)
movsd  -0x8(%r9,%rax,8),%xmm0
addsd  -0x8(%rdx,%rax,8),%xmm0
movsd  %xmm0,-0x8(%rdx,%rax,8)
movsd  (%r9,%rax,8),%xmm0
addsd  (%rdx,%rax,8),%xmm0
movsd  %xmm0,(%rdx,%rax,8)
add    $0x2,%rax
cmp    %rax,%r13
jne    1310 <calc_cluster_centroids+0x1f0>
jmp    1260 <calc_cluster_centroids+0x140>
cmpq   $0x0,0x18(%rsp)
je     1410 <calc_cluster_centroids+0x2f0>
mov    0x50(%rsp),%rax
lea    (%rax,%r8,8),%rsi
mov    0x58(%rsp),%rax
xor    %ebp,%ebp
nopl   (%rax)
movupd -0x30(%rcx,%rbp,8),%xmm0
movupd -0x20(%rcx,%rbp,8),%xmm1
movupd -0x30(%rsi,%rbp,8),%xmm2
addpd  %xmm0,%xmm2
movupd -0x20(%rsi,%rbp,8),%xmm0
addpd  %xmm1,%xmm0
movupd -0x10(%rsi,%rbp,8),%xmm1
movupd (%rsi,%rbp,8),%xmm3
movupd %xmm2,-0x30(%rsi,%rbp,8)
movupd %xmm0,-0x20(%rsi,%rbp,8)
movupd -0x10(%rcx,%rbp,8),%xmm0
addpd  %xmm1,%xmm0
movupd (%rcx,%rbp,8),%xmm1
addpd  %xmm3,%xmm1
movupd %xmm0,-0x10(%rsi,%rbp,8)
movupd %xmm1,(%rsi,%rbp,8)
add    $0x8,%rbp
add    $0xfffffffffffffffe,%rax
jne    1360 <calc_cluster_centroids+0x240>
testb  $0x1,0x38(%rsp)
je     13fa <calc_cluster_centroids+0x2da>
lea    (%rdx,%rbp,1),%rax
mov    (%rsp),%rsi
movupd (%rsi,%rax,8),%xmm0
movupd 0x10(%rsi,%rax,8),%xmm1
add    %r8,%rbp
movupd (%rbx,%rbp,8),%xmm2
addpd  %xmm0,%xmm2
movupd 0x10(%rbx,%rbp,8),%xmm0
addpd  %xmm1,%xmm0
movupd %xmm2,(%rbx,%rbp,8)
movupd %xmm0,0x10(%rbx,%rbp,8)
mov    %r14,%rsi
cmp    %r13,%r14
mov    0x30(%rsp),%rbp
je     1260 <calc_cluster_centroids+0x140>
jmp    12cb <calc_cluster_centroids+0x1ab>
xor    %ebp,%ebp
testb  $0x1,0x38(%rsp)
jne    13c6 <calc_cluster_centroids+0x2a6>
jmp    13fa <calc_cluster_centroids+0x2da>
mov    %rbx,(%rsp)
cmpl   $0x0,0x44(%rsp)
jle    158d <calc_cluster_centroids+0x46d>
mov    %r13d,%eax
and    $0xfffffffe,%eax
mov    %rax,0x28(%rsp)
add    $0xfffffffffffffffe,%rax
mov    %rax,0x20(%rsp)
mov    %rax,%rcx
shr    %rcx
add    $0x1,%rcx
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x30(%rsp)
mov    (%rsp),%r14
lea    0x10(%r14),%r12
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%r15
xor    %ebp,%ebp
jmp    1495 <calc_cluster_centroids+0x375>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
add    %r15,%r12
add    %r15,%r14
cmp    0x48(%rsp),%rbp
je     158d <calc_cluster_centroids+0x46d>
mov    0x60(%rsp,%rbp,4),%ebx
test   %ebx,%ebx
je     14b0 <calc_cluster_centroids+0x390>
test   %edi,%edi
jg     14c7 <calc_cluster_centroids+0x3a7>
jmp    1480 <calc_cluster_centroids+0x360>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xb49(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%rdi
test   %edi,%edi
jle    1480 <calc_cluster_centroids+0x360>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
cmp    $0x1,%edi
jne    14e0 <calc_cluster_centroids+0x3c0>
xor    %eax,%eax
jmp    1560 <calc_cluster_centroids+0x440>
nopw   0x0(%rax,%rax,1)
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
cmpq   $0x0,0x20(%rsp)
je     157e <calc_cluster_centroids+0x45e>
mov    0x30(%rsp),%rcx
xor    %eax,%eax
mov    (%rsp),%rdx
nop
movupd -0x10(%r12,%rax,8),%xmm2
movupd (%r12,%rax,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,-0x10(%r12,%rax,8)
divpd  %xmm1,%xmm3
movupd %xmm3,(%r12,%rax,8)
add    $0x4,%rax
add    $0xfffffffffffffffe,%rcx
jne    1500 <calc_cluster_centroids+0x3e0>
testb  $0x1,0x18(%rsp)
je     154d <calc_cluster_centroids+0x42d>
mov    %rbp,%rcx
imul   0x10(%rsp),%rcx
add    %rcx,%rax
movupd (%rdx,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rdx,%rax,8)
mov    0x28(%rsp),%rcx
mov    %rcx,%rax
cmp    %r13,%rcx
je     1480 <calc_cluster_centroids+0x360>
xchg   %ax,%ax
movsd  (%r14,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%rax,8)
add    $0x1,%rax
cmp    %rax,%r13
jne    1560 <calc_cluster_centroids+0x440>
jmp    1480 <calc_cluster_centroids+0x360>
xor    %eax,%eax
mov    (%rsp),%rdx
testb  $0x1,0x18(%rsp)
jne    1533 <calc_cluster_centroids+0x413>
jmp    154d <calc_cluster_centroids+0x42d>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
and    $0xfffffffc,%ebp
mov    %rbp,0x10(%rsp)
mov    0x8(%rsp),%rdi
lea    0x0(,%rdi,4),%eax
mov    %eax,0x28(%rsp)
lea    (%rdi,%rdi,1),%eax
mov    %rax,0x20(%rsp)
lea    (%rdi,%rdi,2),%eax
mov    %rax,0x18(%rsp)
xor    %ebp,%ebp
jmp    15e4 <calc_cluster_centroids+0x4c4>
nopl   0x0(%rax,%rax,1)
add    $0x4,%rbp
add    0x28(%rsp),%r14d
cmp    %rbp,0x10(%rsp)
je     119c <calc_cluster_centroids+0x7c>
test   %edi,%edi
jle    15d0 <calc_cluster_centroids+0x4b0>
movslq %r14d,%rax
lea    (%rbx,%rax,8),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    0x8(%rsp),%rax
add    %r14d,%eax
cltq
lea    (%rbx,%rax,8),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    0x20(%rsp),%rax
add    %r14d,%eax
cltq
lea    (%rbx,%rax,8),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    0x18(%rsp),%rax
add    %r14d,%eax
cltq
lea    (%rbx,%rax,8),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    0x8(%rsp),%rdi
jmp    15d0 <calc_cluster_centroids+0x4b0>

LLVM IR (-O0):
@.str = [29 x i8] c"WARNING: Empty cluster %d! \0A\00"
define void @calc_cluster_centroids(i32 %0, i32 %1, i32 %2, double* %3, i32* %4, double* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32*
%12 = alloca double*
%13 = alloca [16 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store i32* %4, i32** %11
store double* %5, double** %12
store i32 0, i32* %14
br label %21
21: ; preds = %46, %6
%22 = load i32, i32* %14
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %49
25: ; preds = %21
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 %27
store i32 0, i32* %28
store i32 0, i32* %15
br label %29
29: ; preds = %42, %25
%30 = load i32, i32* %15
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load double*, double** %12
%35 = load i32, i32* %14
%36 = load i32, i32* %7
%37 = mul nsw i32 %35, %36
%38 = load i32, i32* %15
%39 = add nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %34, i64 %40
store double 0.000000e+00, double* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %15
%44 = add nsw i32 %43, 1
store i32 %44, i32* %15
br label %29
45: ; preds = %29
br label %46
46: ; preds = %45
%47 = load i32, i32* %14
%48 = add nsw i32 %47, 1
store i32 %48, i32* %14
br label %21
49: ; preds = %21
store i32 0, i32* %16
br label %50
50: ; preds = %93, %49
%51 = load i32, i32* %16
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %96
54: ; preds = %50
%55 = load i32*, i32** %11
%56 = load i32, i32* %16
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
store i32 %59, i32* %17
%60 = load i32, i32* %17
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = add nsw i32 %63, 1
store i32 %64, i32* %62
store i32 0, i32* %18
br label %65
65: ; preds = %89, %54
%66 = load i32, i32* %18
%67 = load i32, i32* %7
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %92
69: ; preds = %65
%70 = load double*, double** %10
%71 = load i32, i32* %16
%72 = load i32, i32* %7
%73 = mul nsw i32 %71, %72
%74 = load i32, i32* %18
%75 = add nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %70, i64 %76
%78 = load double, double* %77
%79 = load double*, double** %12
%80 = load i32, i32* %17
%81 = load i32, i32* %7
%82 = mul nsw i32 %80, %81
%83 = load i32, i32* %18
%84 = add nsw i32 %82, %83
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %79, i64 %85
%87 = load double, double* %86
%88 = fadd double %87, %78
store double %88, double* %86
br label %89
89: ; preds = %69
%90 = load i32, i32* %18
%91 = add nsw i32 %90, 1
store i32 %91, i32* %18
br label %65
92: ; preds = %65
br label %93
93: ; preds = %92
%94 = load i32, i32* %16
%95 = add nsw i32 %94, 1
store i32 %95, i32* %16
br label %50
96: ; preds = %50
store i32 0, i32* %19
br label %97
97: ; preds = %135, %96
%98 = load i32, i32* %19
%99 = load i32, i32* %9
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %138
101: ; preds = %97
%102 = load i32, i32* %19
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 %103
%105 = load i32, i32* %104
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %101
%108 = load i32, i32* %19
%109 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %107, %101
store i32 0, i32* %20
br label %111
111: ; preds = %131, %110
%112 = load i32, i32* %20
%113 = load i32, i32* %7
%114 = icmp slt i32 %112, %113
br i1 %114, label %115, label %134
115: ; preds = %111
%116 = load i32, i32* %19
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 %117
%119 = load i32, i32* %118
%120 = sitofp i32 %119 to double
%121 = load double*, double** %12
%122 = load i32, i32* %19
%123 = load i32, i32* %7
%124 = mul nsw i32 %122, %123
%125 = load i32, i32* %20
%126 = add nsw i32 %124, %125
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %121, i64 %127
%129 = load double, double* %128
%130 = fdiv double %129, %120
store double %130, double* %128
br label %131
131: ; preds = %115
%132 = load i32, i32* %20
%133 = add nsw i32 %132, 1
store i32 %133, i32* %20
br label %111
134: ; preds = %111
br label %135
135: ; preds = %134
%136 = load i32, i32* %19
%137 = add nsw i32 %136, 1
store i32 %137, i32* %19
br label %97
138: ; preds = %97
ret void
}

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