// File: hanhwi[P]SimPoint/analysiscode/KMeans.cpp
// Function: KMeans::initializeFurthestFirst(int, Dataset const&, Dataset*)
void KMeans::initializeFurthestFirst(int randSeed, const Dataset &data,
        Dataset *centers) {
    if ((! centers) || (centers->numRows() <= 0)) {
        return;
    }

    Random rand(randSeed);

    int ndx = rand.randInt() % data.numRows();
    (*centers)[0] = data[ndx];

    Datapoint distances(data.numRows());

    for (unsigned int i = 1; i < centers->numRows(); i++) {
        for (unsigned int j = 0; j < data.numRows(); j++) {
            double d = data[j].distSquared((*centers)[i - 1]);
            if ((i == 1) || (d < distances[j])) {
                distances[j] = d;
            }
        }

        int next = distances.maxNdx();
        (*centers)[i] = data[next];
    }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movl %edi, 0x1c4(%rsp)
movq %rsi, 0x1b8(%rsp)
movq %rdx, 0x1b0(%rsp)
cmpq $0x0, 0x1b0(%rsp)
je 0xf3eb
movq 0x1b0(%rsp), %rdi
callq 0xc0c0
cmpl $0x0, %eax
ja 0xf3f0
jmp 0xf637
movslq 0x1c4(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x10cb0
leaq 0x98(%rsp), %rdi
callq 0x10d10
movl %eax, 0x44(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0xc0c0
movl %eax, %ecx
movl 0x44(%rsp), %eax
xorl %edx, %edx
divl %ecx
movl %edx, 0x94(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0xc0f0
movq %rax, 0x48(%rsp)
movq 0x1b0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc130
movq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0xdd20
movq 0x1b8(%rsp), %rdi
callq 0xc0c0
movl %eax, %esi
leaq 0x78(%rsp), %rdi
callq 0x8d60
movl $0x1, 0x74(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0xc0c0
movl %eax, 0x40(%rsp)
jmp 0xf4a8
movl 0x3c(%rsp), %eax
movl 0x40(%rsp), %ecx
cmpl %ecx, %eax
jae 0xf62d
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0xc0c0
movl %eax, 0x38(%rsp)
jmp 0xf4db
movl 0x34(%rsp), %eax
movl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jae 0xf5c3
movq 0x1b8(%rsp), %rdi
movl 0x60(%rsp), %eax
movl %eax, %esi
callq 0xc0f0
movq %rax, 0x20(%rsp)
movq 0x1b0(%rsp), %rdi
movl 0x74(%rsp), %eax
decl %eax
movl %eax, %esi
callq 0xc130
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x8e30
movsd %xmm0, 0x28(%rsp)
jmp 0xf52d
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
cmpl $0x1, 0x74(%rsp)
je 0xf56c
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x60(%rsp), %eax
movl %eax, %esi
leaq 0x78(%rsp), %rdi
callq 0x9ba0
movsd 0x18(%rsp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xf5b1
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x60(%rsp), %eax
movl %eax, %esi
leaq 0x78(%rsp), %rdi
callq 0x9ba0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0xf5b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x9bc0
jmp 0xf63f
jmp 0xf5b3
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xf4c0
xorl %esi, %esi
movl %esi, %ecx
leaq 0x78(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8f20
movl %eax, 0xc(%rsp)
jmp 0xf5dc
movl 0xc(%rsp), %eax
movl %eax, 0x54(%rsp)
movq 0x1b8(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xc0f0
movq %rax, (%rsp)
movq 0x1b0(%rsp), %rdi
movl 0x74(%rsp), %eax
movl %eax, %esi
callq 0xc130
movq (%rsp), %rsi
movq %rax, %rdi
callq 0xdd20
jmp 0xf61b
jmp 0xf61d
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0xf48d
leaq 0x78(%rsp), %rdi
callq 0x9bc0
addq $0x1c8, %rsp            # imm = 0x1C8
retq
movq 0x68(%rsp), %rdi
callq 0x5690
nopl (%rax)