// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r14
leaq 0x280(%rdi), %rbx
leaq 0xbc40(%rip), %rsi      # 0x151ff
movq %rbx, %rdi
callq 0x5556
pushq $0x18
popq %r13
testb %al, %al
je 0x95e2
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x926e
movq %rax, %rbx
jmp 0x9880
leaq 0x260(%r14), %r15
leaq 0xbc0f(%rip), %rsi      # 0x151ff
movq %r15, %rdi
callq 0x5556
testb %al, %al
je 0x9772
movq %r15, %rdi
callq 0x8734
movl %eax, %ebx
leaq 0xc11d(%rip), %rsi      # 0x1572e
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x54af
movzbl %bl, %edi
movq %r12, %rsi
callq 0x5364
leaq 0x30(%rsp), %rdi
callq 0x45e8
pushq $0x30
popq %rdi
callq 0x42b0
movq %rax, %rbx
movq %rax, %rdi
callq 0x614c
movq (%r15), %rsi
leaq 0x30(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4550
leaq 0xa8(%rsp), %rdi
callq 0x40a0
movl %eax, %ebp
leaq 0xc0e7(%rip), %rsi      # 0x15756
leaq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0x54af
movzbl %bpl, %edi
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x6514
leaq 0x30(%rsp), %rdi
callq 0x4090
leaq 0x17c66(%rip), %rax     # 0x21318
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rdi
leaq 0xc0c8(%rip), %rsi      # 0x1578b
callq 0x4290
movq %rax, %rdi
movq %r15, %rsi
callq 0x4270
leaq 0xc0de(%rip), %rsi      # 0x157b8
movq %rax, %rdi
callq 0x4290
movq %rax, %rdi
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %r13
movl %eax, %esi
callq 0x41e0
leaq 0xc292(%rip), %rsi      # 0x15991
movq %rax, %rdi
callq 0x4290
movq (%rbx), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
movq (%r14), %rax
movq (%rax), %rax
movq (%rax), %r13
movq 0x8(%rax), %rbp
leaq 0xc09b(%rip), %rsi      # 0x157c0
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x53a6
subq %r13, %rbp
shrq $0x3, %rbp
subq %r12, %r15
shrq $0x3, %r15
xorl %edi, %edi
cmpl %ebp, %r15d
sete %dil
leaq 0x10(%rsp), %rsi
callq 0x5364
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x30(%rsp), %rdi
callq 0x40c0
pushq $0x18
popq %r13
jmp 0x9880
pushq $0x30
popq %rdi
callq 0x42b0
movq %rax, %rbx
movslq %r12d, %r12
movq (%r14), %rax
movq 0x90(%r14), %rcx
movl (%rcx,%r12,4), %esi
movq (%rax), %rax
movq 0x8(%rax), %rdx
subq (%rax), %rdx
shrq $0x3, %rdx
movq %rbx, %rdi
callq 0x61d4
leaq 0xe0(%r14), %r15
leaq 0xc05a(%rip), %rsi      # 0x1580c
movq %r15, %rdi
callq 0x5549
testb %al, %al
je 0x97ec
addl 0xa8(%r14), %ebp
movq (%r14), %rsi
movl %ebp, %edi
movq %rbx, %rdx
callq 0x7704
leaq 0x17b3f(%rip), %rax     # 0x21318
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rdi
leaq 0xc027(%rip), %rsi      # 0x15811
jmp 0x982b
leaq 0xdc0b(%rip), %rsi      # 0x173fe
movq %r15, %rdi
callq 0x5549
testb %al, %al
je 0x9854
addl 0xa8(%r14), %ebp
movq (%r14), %rsi
movl %ebp, %edi
movq %rbx, %rdx
callq 0x77ac
leaq 0x17afe(%rip), %rax     # 0x21318
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rdi
leaq 0xc026(%rip), %rsi      # 0x15851
callq 0x4290
movq 0x90(%r14), %rcx
movl (%rcx,%r12,4), %esi
movq %rax, %rdi
callq 0x4510
leaq 0xbffd(%rip), %rsi      # 0x15847
movq %rax, %rdi
callq 0x4290
jmp 0x9880
leaq 0xc02b(%rip), %rsi      # 0x15886
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x53a6
leaq 0x30(%rsp), %rsi
xorl %edi, %edi
callq 0x5364
leaq 0x30(%rsp), %rdi
callq 0x45e8
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %r13
movl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x98a3
movq 0x18(%rbx), %rdx
andq $0x0, (%rdx,%rcx,8)
incq %rcx
jmp 0x9890
movq (%r14), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %r13
movl %eax, %esi
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x81b0
movq (%r14), %rdi
leaq 0x30(%rsp), %rdx
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x7c7e
movq (%r14), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %r13
movq 0x30(%rsp), %rdx
movl %eax, %eax
xorl %esi, %esi
cmpq %rsi, %rax
je 0x9914
movl (%rdx,%rsi,4), %edi
movq 0x18(%rcx), %r8
movsd (%r8,%rsi,8), %xmm0
movq 0x18(%rbx), %r8
addsd (%r8,%rdi,8), %xmm0
movsd %xmm0, (%r8,%rdi,8)
incq %rsi
jmp 0x98ed
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %r13
movl %eax, %eax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x993b
movq 0x18(%rbx), %rdx
addsd (%rdx,%rcx,8), %xmm0
incq %rcx
jmp 0x9928
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x9959
movq 0x18(%rbx), %rdx
movsd (%rdx,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
jmp 0x993d
leaq 0x30(%rsp), %rdi
callq 0x8498
movq %rbx, %rax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x99a3
jmp 0x99c1
jmp 0x9980
jmp 0x99c6
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x45e8
jmp 0x99c9
jmp 0x99c6
jmp 0x9993
movq %rax, %r14
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0x42c0
jmp 0x99d3
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x45e8
jmp 0x99d3
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x8498
jmp 0x99d3
movq %rax, %r14
jmp 0x99d3
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x40c0
movq %r14, %rdi
callq 0x4530
nop