#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 */
double DBL_MAX;
int /*<<< orphan*/ assert(int);
double compute_distance(double const *, double const *, unsigned int);
unsigned int assign_point_to_cluster_ordinary(const double *px,
                                              const double *CX,
                                              unsigned int dim,
                                              unsigned int nclus) {
  unsigned int assignment = nclus;
  double mind = DBL_MAX;
  const double *pcx = CX;
  for (unsigned int j = 0; j < nclus; j++, pcx += dim) {
    double d = compute_distance(px, pcx, dim);
    if (d < mind) {
      mind = d;
      assignment = j;
    }
  }
  assert(assignment < nclus);
  return (assignment);
}


x86 assembly (clang, -O0):
<assign_point_to_cluster_ordinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e9d(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11c7 <assign_point_to_cluster_ordinary+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <compute_distance@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a0 <assign_point_to_cluster_ordinary+0x80>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <assign_point_to_cluster_ordinary+0x85>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    115b <assign_point_to_cluster_ordinary+0x3b>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign_point_to_cluster_ordinary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,0xc(%rsp)
test   %ecx,%ecx
je     1195 <assign_point_to_cluster_ordinary+0x75>
mov    %rsi,%rbp
mov    %rdi,%r15
mov    0x2e9a(%rip),%rax
movsd  (%rax),%xmm0
mov    0xc(%rsp),%r13d
shl    $0x3,%r13
xor    %r14d,%r14d
mov    %r12d,%ebx
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    0xc(%rsp),%edx
call   1040 <compute_distance@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
cmova  %r14d,%ebx
minsd  %xmm1,%xmm0
add    $0x1,%r14d
add    %r13,%rbp
cmp    %r14d,%r12d
jne    1160 <assign_point_to_cluster_ordinary+0x40>
jmp    1197 <assign_point_to_cluster_ordinary+0x77>
xor    %ebx,%ebx
xor    %edi,%edi
cmp    %r12d,%ebx
setb   %dil
call   1030 <assert@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX = global double 0.000000e+00
define i32 @assign_point_to_cluster_ordinary(double* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double*
%12 = alloca i32
%13 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %8
store i32 %14, i32* %9
%15 = load double, double* @DBL_MAX
store double %15, double* %10
%16 = load double*, double** %6
store double* %16, double** %11
store i32 0, i32* %12
br label %17
17: ; preds = %33, %4
%18 = load i32, i32* %12
%19 = load i32, i32* %8
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = load double*, double** %5
%23 = load double*, double** %11
%24 = load i32, i32* %7
%25 = call double @compute_distance(double* %22, double* %23, i32 %24)
store double %25, double* %13
%26 = load double, double* %13
%27 = load double, double* %10
%28 = fcmp olt double %26, %27
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load double, double* %13
store double %30, double* %10
%31 = load i32, i32* %12
store i32 %31, i32* %9
br label %32
32: ; preds = %29, %21
br label %33
33: ; preds = %32
%34 = load i32, i32* %12
%35 = add i32 %34, 1
store i32 %35, i32* %12
%36 = load i32, i32* %7
%37 = load double*, double** %11
%38 = zext i32 %36 to i64
%39 = getelementptr inbounds double, double* %37, i64 %38
store double* %39, double** %11
br label %17
40: ; preds = %17
%41 = load i32, i32* %9
%42 = load i32, i32* %8
%43 = icmp ult i32 %41, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %9
ret i32 %46
}

LLVM IR (-O2):
@DBL_MAX = global double 0.000000e+00
define i32 @assign_point_to_cluster_ordinary(double* %0, double* %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load double, double* @DBL_MAX
%8 = zext i32 %2 to i64
br label %14
9: ; preds = %14, %4
%10 = phi i32 [ 0, %4 ], [ %22, %14 ]
%11 = icmp ult i32 %10, %3
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
ret i32 %10
14: ; preds = %6, %14
%15 = phi i32 [ %3, %6 ], [ %22, %14 ]
%16 = phi i32 [ 0, %6 ], [ %23, %14 ]
%17 = phi double* [ %1, %6 ], [ %24, %14 ]
%18 = phi double [ %7, %6 ], [ %21, %14 ]
%19 = tail call double @compute_distance(double* %0, double* %17, i32 %2)
%20 = fcmp olt double %19, %18
%21 = select i1 %20, double %19, double %18
%22 = select i1 %20, i32 %16, i32 %15
%23 = add nuw i32 %16, 1
%24 = getelementptr inbounds double, double* %17, i64 %8
%25 = icmp eq i32 %23, %3
br i1 %25, label %9, label %14
}