#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*/ get_cluster_member_count(int, int, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
void cluster_diag(int dim, int n, int k, double *X,
                  int *cluster_assignment_index, double *cluster_centroid) {
  int cluster_member_count[16];
  get_cluster_member_count(n, k, cluster_assignment_index,
                           cluster_member_count);
  printf("  Final clusters \n");
  for (int ii = 0; ii < k; ii++)
    printf("    cluster %d:     members: %8d, centroid (%.1f %.1f) \n", ii,
           cluster_member_count[ii], cluster_centroid[ii * dim + 0],
           cluster_centroid[ii * dim + 1]);
}


x86 assembly (clang, -O0):
<cluster_diag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1030 <get_cluster_member_count@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <cluster_diag+0xa7>
mov    -0x74(%rbp),%esi
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edx
mov    -0x28(%rbp),%rax
mov    -0x74(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x74(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe61(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1168 <cluster_diag+0x48>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cluster_diag>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r9,%r14
mov    %edx,%ebx
mov    %edi,%ebp
mov    %rsp,%rcx
mov    %esi,%edi
mov    %edx,%esi
mov    %r8,%rdx
call   1040 <get_cluster_member_count@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    11a6 <cluster_diag+0x76>
movslq %ebp,%rbp
mov    %ebx,%r12d
add    $0x8,%r14
shl    $0x3,%rbp
xor    %ebx,%ebx
lea    0xe87(%rip),%r15
nopl   0x0(%rax)
mov    (%rsp,%rbx,4),%edx
movsd  -0x8(%r14),%xmm0
movsd  (%r14),%xmm1
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x2,%al
call   1050 <printf@plt>
add    $0x1,%rbx
add    %rbp,%r14
cmp    %rbx,%r12
jne    1180 <cluster_diag+0x50>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c" Final clusters \0A\00"
@.str.1 = [57 x i8] c" cluster %d: members: %8d, centroid (%.1f %.1f) \0A\00"
define void @cluster_diag(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
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
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = load i32*, i32** %11
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 0
%19 = call i32 @get_cluster_member_count(i32 %15, i32 %16, i32* %17, i32* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %14
br label %21
21: ; preds = %48, %6
%22 = load i32, i32* %14
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %51
25: ; preds = %21
%26 = load i32, i32* %14
%27 = load i32, i32* %14
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %13, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load double*, double** %12
%32 = load i32, i32* %14
%33 = load i32, i32* %7
%34 = mul nsw i32 %32, %33
%35 = add nsw i32 %34, 0
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %31, i64 %36
%38 = load double, double* %37
%39 = load double*, double** %12
%40 = load i32, i32* %14
%41 = load i32, i32* %7
%42 = mul nsw i32 %40, %41
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %39, i64 %44
%46 = load double, double* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %30, double %38, double %46)
br label %48
48: ; preds = %25
%49 = load i32, i32* %14
%50 = add nsw i32 %49, 1
store i32 %50, i32* %14
br label %21
51: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str.1 = [57 x i8] c" cluster %d: members: %8d, centroid (%.1f %.1f) \0A\00"
@str = [18 x i8] c" Final clusters \00"
define void @cluster_diag(i32 %0, i32 %1, i32 %2, double* nocapture readnone %3, i32* %4, double* nocapture %5) {
%7 = alloca [16 x i32]
%8 = bitcast [16 x i32]* %7 to i8*
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 0
%10 = call i32 @get_cluster_member_count(i32 %1, i32 %2, i32* %4, i32* %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = sext i32 %0 to i64
%15 = zext i32 %2 to i64
br label %17
16: ; preds = %17, %6
ret void
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %29, %17 ]
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %18
%20 = load i32, i32* %19
%21 = mul nsw i64 %18, %14
%22 = getelementptr inbounds double, double* %5, i64 %21
%23 = load double, double* %22
%24 = add nsw i64 %21, 1
%25 = getelementptr inbounds double, double* %5, i64 %24
%26 = load double, double* %25
%27 = trunc i64 %18 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %20, double %23, double %26)
%29 = add nuw nsw i64 %18, 1
%30 = icmp eq i64 %29, %15
br i1 %30, label %16, label %17
}