// File: /workspace/github_cpp_makefile_star2_O3/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 $0x228, %rsp            # imm = 0x228
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r14
leaq 0x280(%rdi), %rbx
leaq 0x1125d(%rip), %rsi     # 0x1c23a
movq %rbx, %rdi
callq 0x40e0
testl %eax, %eax
je 0xaffc
movq (%r14), %rsi
movq %rbx, %rdi
callq 0xab4c
movq %rax, %rbx
jmp 0xb2ea
leaq 0x260(%r14), %r15
leaq 0x11230(%rip), %rsi     # 0x1c23a
movq %r15, %rdi
callq 0x40e0
testl %eax, %eax
je 0xb1f2
movq (%r15), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x4280
movl %eax, %ebp
movl $0xf000, %r12d          # imm = 0xF000
andl 0x18(%rbx), %r12d
leaq 0x11741(%rip), %rsi     # 0x1c77e
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x5ea5
testl %ebp, %ebp
jne 0xb40e
cmpl $0x8000, %r12d          # imm = 0x8000
jne 0xb40e
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb07a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42d0
movl $0x30, %edi
callq 0x42c0
movq %rax, %rbx
movq %rax, %rdi
callq 0x6d84
movq (%r15), %rsi
leaq 0x20(%rsp), %rdi
movl $0x8, %edx
callq 0x45a0
leaq 0x98(%rsp), %rdi
callq 0x40b0
movl %eax, %ebp
leaq 0x116ef(%rip), %rsi     # 0x1c7a6
movq %rsp, %rdi
movq %r15, %rdx
callq 0x5ea5
testb %bpl, %bpl
je 0xb44f
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb0e6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x7204
leaq 0x20(%rsp), %rdi
callq 0x40a0
leaq 0x1c22c(%rip), %rcx     # 0x27330
movl (%rcx), %eax
shrl $0x1f, %eax
movq 0x8(%rcx,%rax,8), %r15
leaq 0x116c6(%rip), %rsi     # 0x1c7db
movl $0x2c, %edx
movq %r15, %rdi
callq 0x4330
movq 0x260(%r14), %rsi
movq 0x268(%r14), %rdx
movq %r15, %rdi
callq 0x4330
movq %rax, %r15
leaq 0x116c6(%rip), %rsi     # 0x1c808
movl $0x7, %edx
movq %rax, %rdi
callq 0x4330
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %esi # imm = 0xAAAAAAAB
movq %r15, %rdi
callq 0x41c0
leaq 0x11872(%rip), %rsi     # 0x1c9e1
movl $0x2, %edx
movq %rax, %rdi
callq 0x4330
movq (%rbx), %rax
movq (%rax), %rbp
movq 0x8(%rax), %r15
movq (%r14), %rax
movq (%rax), %rax
movq (%rax), %r12
movq 0x8(%rax), %r13
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1166b(%rip), %rsi     # 0x1c810
leaq 0x116af(%rip), %rdx     # 0x1c85b
callq 0x6058
subq %r12, %r13
shrq $0x3, %r13
subq %rbp, %r15
shrq $0x3, %r15
cmpl %r13d, %r15d
jne 0xb48f
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb1e3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
leaq 0x20(%rsp), %rdi
callq 0x40c0
jmp 0xb2ea
movl $0x30, %edi
callq 0x42c0
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 0x6e3c
leaq 0xe0(%r14), %r15
leaq 0x11628(%rip), %rsi     # 0x1c85c
movq %r15, %rdi
callq 0x40e0
testl %eax, %eax
je 0xb28a
leaq 0x13207(%rip), %rsi     # 0x1e44e
movq %r15, %rdi
callq 0x40e0
testl %eax, %eax
jne 0xb4d7
addl 0xa8(%r14), %ebp
movq (%r14), %rsi
movl %ebp, %edi
movq %rbx, %rdx
callq 0x889e
leaq 0x1c0be(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %r15
leaq 0x1161e(%rip), %rsi     # 0x1c8a1
movl $0x34, %edx
jmp 0xb2bb
addl 0xa8(%r14), %ebp
movq (%r14), %rsi
movl %ebp, %edi
movq %rbx, %rdx
callq 0x87d0
leaq 0x1c08b(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %r15
leaq 0x115ab(%rip), %rsi     # 0x1c861
movl $0x35, %edx
movq %r15, %rdi
callq 0x4330
movq 0x90(%r14), %rax
movl (%rax,%r12,4), %esi
movq %r15, %rdi
callq 0x4560
leaq 0x115ba(%rip), %rsi     # 0x1c897
movl $0x9, %edx
movq %rax, %rdi
callq 0x4330
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r15, %rax
testl %eax, %eax
je 0xb318
movq 0x18(%rbx), %rdi
movl %eax, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x4190
movq (%r14), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0xaaaaaaab, %ecx, %esi # imm = 0xAAAAAAAB
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x952a
movq (%r14), %rdi
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x8f00
movq (%r14), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
imulq %r15, %rsi
testl %esi, %esi
je 0xb38f
movq 0x20(%rsp), %rax
movq 0x18(%rcx), %rcx
movq 0x18(%rbx), %rdx
movl %esi, %esi
xorl %edi, %edi
movl (%rax,%rdi,4), %r8d
movsd (%rcx,%rdi,8), %xmm0
addsd (%rdx,%r8,8), %xmm0
movsd %xmm0, (%rdx,%r8,8)
incq %rdi
cmpq %rdi, %rsi
jne 0xb372
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
imulq %r15, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0xb3e2
movq 0x18(%rbx), %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
addsd (%rdx,%rsi,8), %xmm0
incq %rsi
cmpq %rsi, %rcx
jne 0xb3b2
testq %rcx, %rcx
je 0xb3e2
movq 0x18(%rbx), %rcx
movl %eax, %eax
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xb3cc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xb3f9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
movq %rbx, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bf1b(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x10d52(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
jmp 0xb4cd
leaq 0x1beda(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x10d11(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
jmp 0xb4cd
leaq 0x1be9a(%rip), %rcx     # 0x27330
movl (%rcx), %eax
shrl $0x1f, %eax
movq 0x8(%rcx,%rax,8), %rbx
leaq 0x10cd1(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
movl $0x1, %edi
callq 0x4370
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x113ef(%rip), %rsi     # 0x1c8d6
leaq 0x11421(%rip), %rdx     # 0x1c90f
leaq 0x20(%rsp), %rdi
callq 0x6058
leaq 0x1be31(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x10c68(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
jmp 0xb4cd
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
jne 0xb58e
jmp 0xb5d7
jmp 0xb5c5
jmp 0xb59c
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
jmp 0xb569
movq %rax, %r14
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb5cd
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xb5cd
movq %rax, %r14
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb5d7
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0xb5be
jmp 0xb5ca
jmp 0xb5ca
movq %rax, %r14
movl $0x30, %esi
movq %rbx, %rdi
jmp 0xb5be
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xb5d7
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
jmp 0xb5d7
movq %rax, %r14
jmp 0xb5d7
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x40c0
movq %r14, %rdi
callq 0x4580
nop