#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 closest_centroid(double *, double *, int, int);
void assign_centroids_multi(double *data, double *centroids, int *assignments,
                            int n_jobs, int k, int N, int D) {
#pragma omp parallel shared(data, centroids, assignments) num_threads(n_jobs)
  for (int i = 0; i < N; i++) {
    assignments[i] = closest_centroid(data + i * D, centroids, k, D);
  }
}


x86 assembly (clang, -O0):
<assign_centroids_multi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%eax
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    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1183 <assign_centroids_multi+0x73>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
imul   0x10(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    0x10(%rbp),%ecx
call   1030 <closest_centroid@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1139 <assign_centroids_multi+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign_centroids_multi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %r9d,%r9d
jle    1164 <assign_centroids_multi+0x54>
mov    %r8d,%r15d
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
movslq 0x40(%rsp),%rbp
mov    %r9d,%eax
mov    %rax,(%rsp)
shl    $0x3,%rbp
xor    %r14d,%r14d
nop
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    0x40(%rsp),%ecx
call   1030 <closest_centroid@plt>
mov    %eax,0x0(%r13,%r14,4)
add    $0x1,%r14
add    %rbp,%rbx
cmp    %r14,(%rsp)
jne    1140 <assign_centroids_multi+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @assign_centroids_multi(double* %0, double* %1, i32* %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store double* %0, double** %8
store double* %1, double** %9
store i32* %2, i32** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
store i32 0, i32* %15
br label %16
16: ; preds = %35, %7
%17 = load i32, i32* %15
%18 = load i32, i32* %13
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load double*, double** %8
%22 = load i32, i32* %15
%23 = load i32, i32* %14
%24 = mul nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %21, i64 %25
%27 = load double*, double** %9
%28 = load i32, i32* %12
%29 = load i32, i32* %14
%30 = call i32 @closest_centroid(double* %26, double* %27, i32 %28, i32 %29)
%31 = load i32*, i32** %10
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
br label %35
35: ; preds = %20
%36 = load i32, i32* %15
%37 = add nsw i32 %36, 1
store i32 %37, i32* %15
br label %16
38: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @assign_centroids_multi(double* %0, double* %1, i32* nocapture writeonly %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = sext i32 %6 to i64
%11 = zext i32 %5 to i64
br label %13
12: ; preds = %13, %7
ret void
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %19, %13 ]
%15 = mul nsw i64 %14, %10
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = tail call i32 @closest_centroid(double* %16, double* %1, i32 %4, i32 %6)
%18 = getelementptr inbounds i32, i32* %2, i64 %14
store i32 %17, i32* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %12, label %13
}