#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*/ clusterCenter(double *, double *, int *, int, int, int,
                                 int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ selectCluster(double *, double *, int *, int, int, int,
                                 int *);
extern void kMeans(double *x, double *c, int *assign, int N, int K, int D) {
  int conv = 0;
  int count[K];
  while (!conv) {
    clusterCenter(x, c, assign, N, K, D, count);
    selectCluster(x, c, assign, N, K, D, &conv);
  }
  printf("Converged!\n\n");
}


x86 assembly (clang, -O0):
<kMeans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x28(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1193 <kMeans+0x63>
jmp    11f0 <kMeans+0xc0>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1030 <clusterCenter@plt>
add    $0x10,%rsp
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    -0x28(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1050 <selectCluster@plt>
add    $0x10,%rsp
jmp    117d <kMeans+0x4d>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kMeans>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,-0x38(%rbp)
mov    %ecx,-0x34(%rbp)
mov    %rdx,-0x60(%rbp)
mov    %rsi,-0x58(%rbp)
mov    %rdi,-0x40(%rbp)
mov    %rsp,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    %r8d,-0x30(%rbp)
mov    %r8d,%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    -0x58(%rbp),%r14
mov    -0x60(%rbp),%rbx
mov    -0x34(%rbp),%r12d
mov    -0x30(%rbp),%r13d
mov    -0x38(%rbp),%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sub    $0x8,%rsp
mov    -0x40(%rbp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    %r15d,%r9d
push   -0x50(%rbp)
call   1040 <clusterCenter@plt>
add    $0x8,%rsp
mov    -0x40(%rbp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    %r15d,%r9d
lea    -0x2c(%rbp),%rax
push   %rax
call   1050 <selectCluster@plt>
add    $0x10,%rsp
cmpl   $0x0,-0x2c(%rbp)
je     11a0 <kMeans+0x70>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Converged!\0A\0A\00"
define void @kMeans(double* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
store double* %0, double** %7
store double* %1, double** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
%16 = load i32, i32* %11
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %14
%19 = alloca i32, i64 %17
store i64 %17, i64* %15
br label %20
20: ; preds = %24, %6
%21 = load i32, i32* %13
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load double*, double** %7
%26 = load double*, double** %8
%27 = load i32*, i32** %9
%28 = load i32, i32* %10
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = call i32 @clusterCenter(double* %25, double* %26, i32* %27, i32 %28, i32 %29, i32 %30, i32* %19)
%32 = load double*, double** %7
%33 = load double*, double** %8
%34 = load i32*, i32** %9
%35 = load i32, i32* %10
%36 = load i32, i32* %11
%37 = load i32, i32* %12
%38 = call i32 @selectCluster(double* %32, double* %33, i32* %34, i32 %35, i32 %36, i32 %37, i32* %13)
br label %20
39: ; preds = %20
%40 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%41 = load i8*, i8** %14
ret void
}

LLVM IR (-O2):
@str = [12 x i8] c"Converged!\0A\00"
define void @kMeans(double* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%9 = zext i32 %4 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
br label %12
12: ; preds = %6, %12
%13 = call i32 @clusterCenter(double* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32* %11)
%14 = call i32 @selectCluster(double* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32* %7)
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret void
}