// File: hanhwi[P]SimPoint/analysiscode/Simpoint.cpp
// Function: Simpoint::loadInitialCenters(int, int) const
Dataset *Simpoint::loadInitialCenters(int runNumber, int seedNumber) const {
    Dataset *centers = NULL;
    // user has provided initial labels?
    if (options.loadInitialLabelsName != "") {
        centers = loadInitialCentersFromLabels(options.loadInitialLabelsName,
                                               *wholeDataset);
    // user has provided initial centers?
    } else if (options.loadInitialCentersName != "") {
        Utilities::check(isRegularFile(options.loadInitialCentersName),
                "loadInitialCenters() not regular file: " +
                options.loadInitialCentersName);
        centers = new Dataset;
        ifstream input(options.loadInitialCentersName.c_str());
        Utilities::check(input.is_open(), "Simpoint::loadInitialCenters(): could not open file " +
                                options.loadInitialCentersName);
        centers->read(input);
        input.close();
        Logger::log() << "  Loaded initial k-means centers from file '"
             << options.loadInitialCentersName << "' (k = " 
             << centers->numRows() << ")\n";
        Utilities::check(centers->numCols() == wholeDataset->numCols(),
            "loadInitialCenters(): initial centers dimension != "
            "projected data dimension");

        // user has not provided initial labels or centers; create the initial centers
    } else {
        centers = new Dataset(options.kValues[runNumber],
                                     wholeDataset->numCols());
        if (options.kMeansInitType == "samp") {
            KMeans::initializeRandomly(options.randSeedKMeansInit + seedNumber,
                    *wholeDataset, centers);
            Logger::log() << "  Initialized k-means centers using random sampling: " 
                << options.kValues[runNumber] << " centers\n";
        } else if (options.kMeansInitType == "ff") {
            KMeans::initializeFurthestFirst(options.randSeedKMeansInit + seedNumber,
                    *wholeDataset, centers);
            Logger::log() << "  Initialized k-means centers using furthest-first: " 
                << options.kValues[runNumber] << " centers\n";
        } else {
            Utilities::check(false, 
                    "loadInitialCenters(): unknown k-means initialization type");
        }
    }

    // Set the (VLI) weights for the centers properly. If vectors should not be
    // VLI-weighted, the appropriate weights should (will) be applied outside
    // this scope, after this function completes.
    for (unsigned int i = 0; i < centers->numRows(); i++) {
        centers->setWeight(i, 0.0);
    }
    vector<int> labels(wholeDataset->numRows());
    KMeans::findLabelsAndDists(*wholeDataset, *centers, &labels);
    for (unsigned int i = 0; i < wholeDataset->numRows(); i++) {
        centers->setWeight(labels[i],
                wholeDataset->getWeight(i) + centers->getWeight(labels[i]));
    }

    // make sure the center weights add to 1.0
    double totalWeight = 0.0;
    for (unsigned int i = 0; i < centers->numRows(); i++) {
        totalWeight += centers->getWeight(i);
    }
    for (unsigned int i = 0; i < centers->numRows(); i++) {
        centers->setWeight(i, centers->getWeight(i) / totalWeight);
    }

    return centers;
}

// Assembly:
subq $0x418, %rsp            # imm = 0x418
movq %rdi, 0x410(%rsp)
movl %esi, 0x40c(%rsp)
movl %edx, 0x408(%rsp)
movq 0x410(%rsp), %rdi
movq %rdi, 0x120(%rsp)
movq $0x0, 0x400(%rsp)
addq $0x58, %rdi
addq $0x228, %rdi            # imm = 0x228
leaq 0x1ee24(%rip), %rsi     # 0x331ff
callq 0x7b70
testb $0x1, %al
jne 0x143e6
jmp 0x14411
movq 0x120(%rsp), %rax
movq %rax, %rdi
addq $0x58, %rdi
addq $0x228, %rdi            # imm = 0x228
movq (%rax), %rsi
callq 0x13cd0
movq %rax, 0x400(%rsp)
jmp 0x14aa1
movq 0x120(%rsp), %rdi
addq $0x58, %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x1edd4(%rip), %rsi     # 0x331ff
callq 0x7b70
testb $0x1, %al
jne 0x14439
jmp 0x147f1
movq 0x120(%rsp), %rdi
addq $0x260, %rdi            # imm = 0x260
movq %rdi, 0x108(%rsp)
callq 0x12540
movq 0x108(%rsp), %rdx
movb %al, 0x117(%rsp)
leaq 0x1f2b3(%rip), %rsi     # 0x3371e
leaq 0x3e0(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x7880
movb 0x117(%rsp), %al
movq 0x118(%rsp), %rsi
movzbl %al, %edi
callq 0x7480
jmp 0x14499
leaq 0x3e0(%rsp), %rdi
callq 0x5788
movl $0x30, %edi
callq 0x5380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x100(%rsp)
callq 0xae00
jmp 0x144c5
movq 0x120(%rsp), %rdi
movq 0x100(%rsp), %rax
movq %rax, 0x400(%rsp)
addq $0x260, %rdi            # imm = 0x260
callq 0x5190
movq %rax, %rsi
leaq 0x1c8(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
movl $0x8, %edx
callq 0x56d0
movq 0xf0(%rsp), %rdi
callq 0x5630
movb %al, 0xff(%rsp)
jmp 0x1451c
movq 0x120(%rsp), %rdx
addq $0x260, %rdx            # imm = 0x260
leaq 0x1f214(%rip), %rsi     # 0x33746
leaq 0x1a8(%rsp), %rdi
callq 0x7880
jmp 0x14541
movb 0xff(%rsp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x1a8(%rsp), %rsi
callq 0x7480
jmp 0x1455d
leaq 0x1a8(%rsp), %rdi
callq 0x5788
movq 0x400(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0xb4a0
jmp 0x14581
leaq 0x1c8(%rsp), %rdi
callq 0x50d0
jmp 0x14590
xorl %edi, %edi
callq 0x7ba0
movq %rax, 0xe8(%rsp)
jmp 0x145a1
movq 0xe8(%rsp), %rdi
leaq 0x1f1cb(%rip), %rsi     # 0x3377b
callq 0x5360
movq %rax, 0xe0(%rsp)
jmp 0x145bf
movq 0xe0(%rsp), %rdi
movq 0x120(%rsp), %rsi
addq $0x260, %rsi            # imm = 0x260
callq 0x5320
movq %rax, 0xd8(%rsp)
jmp 0x145e5
movq 0xd8(%rsp), %rdi
leaq 0x1f1b4(%rip), %rsi     # 0x337a8
callq 0x5360
movq %rax, 0xd0(%rsp)
jmp 0x14603
movq 0x400(%rsp), %rdi
callq 0xc0c0
movl %eax, 0xcc(%rsp)
jmp 0x14619
movl 0xcc(%rsp), %esi
movq 0xd0(%rsp), %rdi
callq 0x5520
movq %rax, 0xc0(%rsp)
jmp 0x14637
movq 0xc0(%rsp), %rdi
leaq 0x1f33b(%rip), %rsi     # 0x33981
callq 0x5360
jmp 0x1464d
movq 0x400(%rsp), %rdi
callq 0xc0d0
movl %eax, 0xbc(%rsp)
jmp 0x14663
movq 0x120(%rsp), %rax
movq (%rax), %rdi
callq 0xc0d0
movl %eax, 0xb8(%rsp)
jmp 0x1467c
movl 0xb8(%rsp), %ecx
movl 0xbc(%rsp), %eax
subl %ecx, %eax
sete %al
movb %al, 0xaf(%rsp)
leaq 0x187(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x56a0
movq 0xb0(%rsp), %rdx
leaq 0x1f0f6(%rip), %rsi     # 0x337b0
leaq 0x188(%rsp), %rdi
callq 0x74e0
jmp 0x146c9
movb 0xaf(%rsp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x188(%rsp), %rsi
callq 0x7480
jmp 0x146e5
leaq 0x188(%rsp), %rdi
callq 0x5788
leaq 0x187(%rsp), %rdi
callq 0x53e0
leaq 0x1c8(%rsp), %rdi
callq 0x5100
jmp 0x14a9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x3e0(%rsp), %rdi
callq 0x5788
jmp 0x14df1
movq 0x100(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
movl $0x30, %esi
callq 0x5390
jmp 0x14df1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
jmp 0x147df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x5788
jmp 0x147df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
jmp 0x147d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x5788
leaq 0x187(%rsp), %rdi
callq 0x53e0
leaq 0x1c8(%rsp), %rdi
callq 0x5100
jmp 0x14df1
movl $0x30, %edi
callq 0x5380
movq 0x120(%rsp), %rdi
movq %rax, 0x98(%rsp)
addq $0x90, %rdi
movslq 0x40c(%rsp), %rsi
callq 0x10e10
movq %rax, %rcx
movq 0x120(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0xa4(%rsp)
movq (%rax), %rdi
callq 0xc0d0
movl %eax, 0xa8(%rsp)
jmp 0x14844
movl 0xa8(%rsp), %edx
movl 0xa4(%rsp), %esi
movq 0x98(%rsp), %rdi
callq 0xaf10
jmp 0x14861
movq 0x120(%rsp), %rdi
movq 0x98(%rsp), %rax
movq %rax, 0x400(%rsp)
addq $0x58, %rdi
addq $0x88, %rdi
leaq 0x1ef71(%rip), %rsi     # 0x337fc
callq 0x7b40
testb $0x1, %al
jne 0x14899
jmp 0x14947
movq 0x120(%rsp), %rax
movl 0xa8(%rax), %edi
addl 0x408(%rsp), %edi
movq (%rax), %rsi
movq 0x400(%rsp), %rdx
callq 0xf2e0
xorl %edi, %edi
callq 0x7ba0
movq %rax, %rdi
leaq 0x1ef32(%rip), %rsi     # 0x33801
callq 0x5360
movq 0x120(%rsp), %rdi
movq %rax, 0x90(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
movslq 0x40c(%rsp), %rsi
callq 0x10e10
movq 0x90(%rsp), %rdi
movl (%rax), %esi
callq 0x5680
movq %rax, %rdi
leaq 0x1ef25(%rip), %rsi     # 0x33837
callq 0x5360
jmp 0x14a9d
movq 0x98(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
movl $0x30, %esi
callq 0x5390
jmp 0x14df1
movq 0x120(%rsp), %rdi
addq $0x58, %rdi
addq $0x88, %rdi
leaq 0x20a8d(%rip), %rsi     # 0x353ee
callq 0x7b40
testb $0x1, %al
jne 0x1496f
jmp 0x149f2
movq 0x120(%rsp), %rax
movl 0xa8(%rax), %edi
addl 0x408(%rsp), %edi
movq (%rax), %rsi
movq 0x400(%rsp), %rdx
callq 0xf3b0
xorl %edi, %edi
callq 0x7ba0
movq %rax, %rdi
leaq 0x1ee9c(%rip), %rsi     # 0x33841
callq 0x5360
movq 0x120(%rsp), %rdi
movq %rax, 0x88(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
movslq 0x40c(%rsp), %rsi
callq 0x10e10
movq 0x88(%rsp), %rdi
movl (%rax), %esi
callq 0x5680
movq %rax, %rdi
leaq 0x1ee4f(%rip), %rsi     # 0x33837
callq 0x5360
jmp 0x14a9b
leaq 0x15f(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x56a0
movq 0x80(%rsp), %rdx
leaq 0x1ee60(%rip), %rsi     # 0x33876
leaq 0x160(%rsp), %rdi
callq 0x74e0
jmp 0x14a25
xorl %edi, %edi
leaq 0x160(%rsp), %rsi
callq 0x7480
jmp 0x14a36
leaq 0x160(%rsp), %rdi
callq 0x5788
leaq 0x15f(%rsp), %rdi
callq 0x53e0
jmp 0x14a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
jmp 0x14a89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x5788
leaq 0x15f(%rsp), %rdi
callq 0x53e0
jmp 0x14df1
jmp 0x14a9d
jmp 0x14a9f
jmp 0x14aa1
movl $0x0, 0x158(%rsp)
movl 0x158(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x400(%rsp), %rdi
callq 0xc0c0
movl %eax, %ecx
movl 0x7c(%rsp), %eax
cmpl %ecx, %eax
jae 0x14af8
movq 0x400(%rsp), %rdi
movl 0x158(%rsp), %esi
xorps %xmm0, %xmm0
callq 0xc150
movl 0x158(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x158(%rsp)
jmp 0x14aac
movq 0x120(%rsp), %rax
movq (%rax), %rdi
callq 0xc0c0
movl %eax, %eax
movq %rax, 0x68(%rsp)
leaq 0x13f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x10e30
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x140(%rsp), %rdi
callq 0x10e40
jmp 0x14b3a
leaq 0x13f(%rsp), %rdi
callq 0x10ec0
movq 0x120(%rsp), %rax
movq (%rax), %rdi
movq 0x400(%rsp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq 0x140(%rsp), %rdx
callq 0x101e0
jmp 0x14b6d
movl $0x0, 0x138(%rsp)
movq 0x120(%rsp), %rax
movl 0x138(%rsp), %ecx
movl %ecx, 0x60(%rsp)
movq (%rax), %rdi
callq 0xc0c0
movl %eax, 0x64(%rsp)
jmp 0x14b99
movl 0x60(%rsp), %eax
movl 0x64(%rsp), %ecx
cmpl %ecx, %eax
jae 0x14caf
movq 0x400(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x138(%rsp), %eax
movl %eax, %esi
leaq 0x140(%rsp), %rdi
callq 0x10dd0
movq %rax, %rcx
movq 0x120(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x54(%rsp)
movq (%rax), %rdi
movl 0x138(%rsp), %esi
callq 0x10d30
movsd %xmm0, 0x58(%rsp)
jmp 0x14bf4
movq 0x400(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0x138(%rsp), %eax
movl %eax, %esi
leaq 0x140(%rsp), %rdi
callq 0x10dd0
movq 0x38(%rsp), %rdi
movl (%rax), %esi
callq 0x10d30
movsd %xmm0, 0x40(%rsp)
jmp 0x14c2b
movl 0x54(%rsp), %esi
movq 0x48(%rsp), %rdi
movsd 0x40(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
addsd %xmm1, %xmm0
callq 0xc150
jmp 0x14c4b
jmp 0x14c4d
movl 0x138(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x138(%rsp)
jmp 0x14b78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x13f(%rsp), %rdi
callq 0x10ec0
jmp 0x14df1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3d8(%rsp)
movl %eax, 0x3d4(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x10ed0
jmp 0x14df1
xorps %xmm0, %xmm0
movsd %xmm0, 0x130(%rsp)
movl $0x0, 0x12c(%rsp)
movl 0x12c(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x400(%rsp), %rdi
callq 0xc0c0
movl %eax, 0x34(%rsp)
jmp 0x14ce4
movl 0x30(%rsp), %eax
movl 0x34(%rsp), %ecx
cmpl %ecx, %eax
jae 0x14d37
movq 0x400(%rsp), %rdi
movl 0x12c(%rsp), %esi
callq 0x10d30
movsd %xmm0, 0x28(%rsp)
jmp 0x14d0c
movsd 0x28(%rsp), %xmm0
addsd 0x130(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp)
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
jmp 0x14cc6
movl $0x0, 0x128(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x400(%rsp), %rdi
callq 0xc0c0
movl %eax, 0x24(%rsp)
jmp 0x14d60
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
cmpl %ecx, %eax
jae 0x14dcc
movq 0x400(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movl 0x128(%rsp), %esi
movl %esi, 0x14(%rsp)
callq 0x10d30
movsd %xmm0, 0x18(%rsp)
jmp 0x14d91
movl 0x14(%rsp), %esi
movq 0x8(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x130(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0xc150
jmp 0x14db4
jmp 0x14db6
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x14d42
movq 0x400(%rsp), %rax
movq %rax, (%rsp)
leaq 0x140(%rsp), %rdi
callq 0x10ed0
movq (%rsp), %rax
addq $0x418, %rsp            # imm = 0x418
retq
movq 0x3d8(%rsp), %rdi
callq 0x5690
nop