#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*/ furthest_first_sample(double *, double const *, double *,
                                         unsigned int, unsigned int,
                                         unsigned int);
unsigned int rand();
void kpp(double *CX, const double *X, double *W, unsigned int dim,
         unsigned int npts, unsigned int nclus) {
  int r = rand() % npts;
  const double *a = X + r * dim;
  for (int i = 0; i < dim; i++)
    CX[i] = a[i];
  furthest_first_sample(CX, X, W, dim, npts, nclus);
}


x86 assembly (clang, -O0):
<kpp>:
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)
mov    $0x0,%al
call   1040 <rand@plt>
xor    %edx,%edx
divl   -0x20(%rbp)
mov    %edx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11a1 <kpp+0x81>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116d <kpp+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
call   1030 <furthest_first_sample@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kpp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebx
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1040 <rand@plt>
xor    %edx,%edx
div    %r12d
test   %r14d,%r14d
je     12fb <kpp+0x1db>
imul   %r14d,%edx
lea    0x0(,%rdx,8),%rax
add    %r13,%rax
mov    %r14d,%r9d
cmp    $0x4,%r14d
jb     1191 <kpp+0x71>
add    %r9,%rdx
lea    0x0(,%rdx,8),%rdx
add    %r13,%rdx
cmp    %rbp,%rdx
jbe    120d <kpp+0xed>
lea    0x0(,%r9,8),%rdx
add    %rbp,%rdx
cmp    %rdx,%rax
jae    120d <kpp+0xed>
xor    %edx,%edx
mov    %rdx,%rsi
not    %rsi
add    %r9,%rsi
mov    %r9,%rdi
and    $0x3,%rdi
je     11c5 <kpp+0xa5>
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%rax,%rdx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rdx,8)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rdi
jne    11b0 <kpp+0x90>
cmp    $0x3,%rsi
jb     12fb <kpp+0x1db>
nop
movsd  (%rax,%rdx,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rdx,8)
movsd  0x8(%rax,%rdx,8),%xmm0
movsd  %xmm0,0x8(%rbp,%rdx,8)
movsd  0x10(%rax,%rdx,8),%xmm0
movsd  %xmm0,0x10(%rbp,%rdx,8)
movsd  0x18(%rax,%rdx,8),%xmm0
movsd  %xmm0,0x18(%rbp,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%r9
jne    11d0 <kpp+0xb0>
jmp    12fb <kpp+0x1db>
mov    %ebx,%r11d
mov    %r9d,%edx
and    $0xfffffffc,%edx
lea    -0x4(%rdx),%rdi
mov    %rdi,%r10
shr    $0x2,%r10
add    $0x1,%r10
mov    %r10d,%r8d
and    $0x3,%r8d
cmp    $0xc,%rdi
jae    1236 <kpp+0x116>
xor    %edi,%edi
jmp    12b0 <kpp+0x190>
and    $0xfffffffffffffffc,%r10
xor    %edi,%edi
nopl   0x0(%rax)
lea    0x0(,%rdi,8),%rsi
movups (%rax,%rdi,8),%xmm0
movups 0x10(%rax,%rdi,8),%xmm1
movups %xmm0,0x0(%rbp,%rdi,8)
movups %xmm1,0x10(%rbp,%rdi,8)
mov    %rsi,%rbx
or     $0x20,%rbx
movups (%rax,%rbx,1),%xmm0
movups 0x10(%rax,%rbx,1),%xmm1
movups %xmm0,0x20(%rbp,%rdi,8)
movups %xmm1,0x30(%rbp,%rdi,8)
mov    %rsi,%rcx
or     $0x40,%rcx
movups (%rax,%rcx,1),%xmm0
movups 0x10(%rax,%rcx,1),%xmm1
movups %xmm0,0x40(%rbp,%rdi,8)
movups %xmm1,0x50(%rbp,%rdi,8)
or     $0x60,%rsi
movups (%rax,%rsi,1),%xmm0
movups 0x10(%rax,%rsi,1),%xmm1
movups %xmm0,0x60(%rbp,%rdi,8)
movups %xmm1,0x70(%rbp,%rdi,8)
add    $0x10,%rdi
add    $0xfffffffffffffffc,%r10
jne    1240 <kpp+0x120>
test   %r8,%r8
je     12ef <kpp+0x1cf>
lea    0x10(,%rdi,8),%rsi
add    %rbp,%rsi
shl    $0x5,%r8
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movups (%rax,%rdi,8),%xmm0
movups 0x10(%rax,%rdi,8),%xmm1
movups %xmm0,-0x10(%rsi,%rbx,1)
movups %xmm1,(%rsi,%rbx,1)
add    $0x4,%rdi
add    $0x20,%rbx
cmp    %rbx,%r8
jne    12d0 <kpp+0x1b0>
cmp    %r9,%rdx
mov    %r11d,%ebx
jne    1193 <kpp+0x73>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %r12d,%r8d
mov    %ebx,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <furthest_first_sample@plt>

LLVM IR (-O0):
define void @kpp(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%16 = call i32 (...) @rand()
%17 = load i32, i32* %11
%18 = urem i32 %16, %17
store i32 %18, i32* %13
%19 = load double*, double** %8
%20 = load i32, i32* %13
%21 = load i32, i32* %10
%22 = mul i32 %20, %21
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds double, double* %19, i64 %23
store double* %24, double** %14
store i32 0, i32* %15
br label %25
25: ; preds = %39, %6
%26 = load i32, i32* %15
%27 = load i32, i32* %10
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = load double*, double** %14
%31 = load i32, i32* %15
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %7
%36 = load i32, i32* %15
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
store double %34, double* %38
br label %39
39: ; preds = %29
%40 = load i32, i32* %15
%41 = add nsw i32 %40, 1
store i32 %41, i32* %15
br label %25
42: ; preds = %25
%43 = load double*, double** %7
%44 = load double*, double** %8
%45 = load double*, double** %9
%46 = load i32, i32* %10
%47 = load i32, i32* %11
%48 = load i32, i32* %12
%49 = call i32 @furthest_first_sample(double* %43, double* %44, double* %45, i32 %46, i32 %47, i32 %48)
ret void
}

LLVM IR (-O2):
define void @kpp(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 (...) @rand()
%8 = urem i32 %7, %4
%9 = mul i32 %8, %3
%10 = zext i32 %9 to i64
%11 = getelementptr double, double* %1, i64 %10
%12 = icmp eq i32 %3, 0
br i1 %12, label %120, label %13
13: ; preds = %6
%14 = zext i32 %3 to i64
%15 = icmp ult i32 %3, 4
br i1 %15, label %102, label %16
16: ; preds = %13
%17 = getelementptr double, double* %0, i64 %14
%18 = add nuw nsw i64 %14, %10
%19 = getelementptr double, double* %1, i64 %18
%20 = icmp ugt double* %19, %0
%21 = icmp ult double* %11, %17
%22 = and i1 %20, %21
br i1 %22, label %102, label %23
23: ; preds = %16
%24 = and i64 %14, 4294967292
%25 = add nsw i64 %24, -4
%26 = lshr exact i64 %25, 2
%27 = add nuw nsw i64 %26, 1
%28 = and i64 %27, 3
%29 = icmp ult i64 %25, 12
br i1 %29, label %81, label %30
30: ; preds = %23
%31 = and i64 %27, 9223372036854775804
br label %32
32: ; preds = %32, %30
%33 = phi i64 [ 0, %30 ], [ %78, %32 ]
%34 = phi i64 [ 0, %30 ], [ %79, %32 ]
%35 = getelementptr inbounds double, double* %11, i64 %33
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %35, i64 2
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = getelementptr inbounds double, double* %0, i64 %33
%42 = bitcast double* %41 to <2 x double>*
store <2 x double> %37, <2 x double>* %42
%43 = getelementptr inbounds double, double* %41, i64 2
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %40, <2 x double>* %44
%45 = or i64 %33, 4
%46 = getelementptr inbounds double, double* %11, i64 %45
%47 = bitcast double* %46 to <2 x double>*
%48 = load <2 x double>, <2 x double>* %47
%49 = getelementptr inbounds double, double* %46, i64 2
%50 = bitcast double* %49 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = getelementptr inbounds double, double* %0, i64 %45
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> %48, <2 x double>* %53
%54 = getelementptr inbounds double, double* %52, i64 2
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %51, <2 x double>* %55
%56 = or i64 %33, 8
%57 = getelementptr inbounds double, double* %11, i64 %56
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = getelementptr inbounds double, double* %57, i64 2
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %0, i64 %56
%64 = bitcast double* %63 to <2 x double>*
store <2 x double> %59, <2 x double>* %64
%65 = getelementptr inbounds double, double* %63, i64 2
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %62, <2 x double>* %66
%67 = or i64 %33, 12
%68 = getelementptr inbounds double, double* %11, i64 %67
%69 = bitcast double* %68 to <2 x double>*
%70 = load <2 x double>, <2 x double>* %69
%71 = getelementptr inbounds double, double* %68, i64 2
%72 = bitcast double* %71 to <2 x double>*
%73 = load <2 x double>, <2 x double>* %72
%74 = getelementptr inbounds double, double* %0, i64 %67
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %70, <2 x double>* %75
%76 = getelementptr inbounds double, double* %74, i64 2
%77 = bitcast double* %76 to <2 x double>*
store <2 x double> %73, <2 x double>* %77
%78 = add nuw i64 %33, 16
%79 = add nuw i64 %34, 4
%80 = icmp eq i64 %79, %31
br i1 %80, label %81, label %32
81: ; preds = %32, %23
%82 = phi i64 [ 0, %23 ], [ %78, %32 ]
%83 = icmp eq i64 %28, 0
br i1 %83, label %100, label %84
84: ; preds = %81, %84
%85 = phi i64 [ %97, %84 ], [ %82, %81 ]
%86 = phi i64 [ %98, %84 ], [ 0, %81 ]
%87 = getelementptr inbounds double, double* %11, i64 %85
%88 = bitcast double* %87 to <2 x double>*
%89 = load <2 x double>, <2 x double>* %88
%90 = getelementptr inbounds double, double* %87, i64 2
%91 = bitcast double* %90 to <2 x double>*
%92 = load <2 x double>, <2 x double>* %91
%93 = getelementptr inbounds double, double* %0, i64 %85
%94 = bitcast double* %93 to <2 x double>*
store <2 x double> %89, <2 x double>* %94
%95 = getelementptr inbounds double, double* %93, i64 2
%96 = bitcast double* %95 to <2 x double>*
store <2 x double> %92, <2 x double>* %96
%97 = add nuw i64 %85, 4
%98 = add i64 %86, 1
%99 = icmp eq i64 %98, %28
br i1 %99, label %100, label %84
100: ; preds = %84, %81
%101 = icmp eq i64 %24, %14
br i1 %101, label %120, label %102
102: ; preds = %16, %13, %100
%103 = phi i64 [ 0, %16 ], [ 0, %13 ], [ %24, %100 ]
%104 = xor i64 %103, -1
%105 = add nsw i64 %104, %14
%106 = and i64 %14, 3
%107 = icmp eq i64 %106, 0
br i1 %107, label %117, label %108
108: ; preds = %102, %108
%109 = phi i64 [ %114, %108 ], [ %103, %102 ]
%110 = phi i64 [ %115, %108 ], [ 0, %102 ]
%111 = getelementptr inbounds double, double* %11, i64 %109
%112 = load double, double* %111
%113 = getelementptr inbounds double, double* %0, i64 %109
store double %112, double* %113
%114 = add nuw nsw i64 %109, 1
%115 = add i64 %110, 1
%116 = icmp eq i64 %115, %106
br i1 %116, label %117, label %108
117: ; preds = %108, %102
%118 = phi i64 [ %103, %102 ], [ %114, %108 ]
%119 = icmp ult i64 %105, 3
br i1 %119, label %120, label %122
120: ; preds = %117, %122, %100, %6
%121 = tail call i32 @furthest_first_sample(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5)
ret void
122: ; preds = %117, %122
%123 = phi i64 [ %139, %122 ], [ %118, %117 ]
%124 = getelementptr inbounds double, double* %11, i64 %123
%125 = load double, double* %124
%126 = getelementptr inbounds double, double* %0, i64 %123
store double %125, double* %126
%127 = add nuw nsw i64 %123, 1
%128 = getelementptr inbounds double, double* %11, i64 %127
%129 = load double, double* %128
%130 = getelementptr inbounds double, double* %0, i64 %127
store double %129, double* %130
%131 = add nuw nsw i64 %123, 2
%132 = getelementptr inbounds double, double* %11, i64 %131
%133 = load double, double* %132
%134 = getelementptr inbounds double, double* %0, i64 %131
store double %133, double* %134
%135 = add nuw nsw i64 %123, 3
%136 = getelementptr inbounds double, double* %11, i64 %135
%137 = load double, double* %136
%138 = getelementptr inbounds double, double* %0, i64 %135
store double %137, double* %138
%139 = add nuw nsw i64 %123, 4
%140 = icmp eq i64 %139, %14
br i1 %140, label %120, label %122
}