// File: /workspace/github_cpp_makefile_star2_O2/hanhwi[P]SimPoint/analysiscode/Simpoint.cpp
// Function: Simpoint::loadInitialCentersFromLabels(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Dataset const&)
Dataset *Simpoint::loadInitialCentersFromLabels(const string &file, const Dataset &data) {
    Utilities::check(isRegularFile(file), 
        "Simpoint::loadInitialCentersFromLabels() not regular file: " + file);
    int n = data.numRows(), d = data.numCols();
    ifstream input(file.c_str());
    Utilities::check(input.is_open(),
        "Simpoint::loadInitialCentersFromLabels() could not open file " + file);

    // load all the labels, find the largest one in the process (this is
    // the number of clusters)
    map<string, int> labelMap; // map from user-given (external) label to actual (internal) label
    vector<int> labels(n);
    for (int i = 0; i < n; i++) {
        string externalLabel;
        input >> externalLabel;
        map<string, int>::iterator itr = labelMap.find(externalLabel);
        if (itr == labelMap.end()) {
            int lmsize = labelMap.size();
            labelMap[externalLabel] = lmsize;
            itr = labelMap.find(externalLabel);
        }
        labels[i] = itr->second;
    }

    int k = labelMap.size();

    // create the initial centers
    Dataset *centers = new Dataset(k, d);
    for (int i = 0; i < k; i++) { centers->setWeight(i, 0.0); }

    // assign each datapoint to each center
    for (int i = 0; i < n; i++) {
        double wt = data.getWeight(i);
        (*centers)[labels[i]].multAndAdd(data[i], wt);
        centers->setWeight(labels[i], centers->getWeight(labels[i]) + wt);
    }

    // normalize each center
    for (int i = 0; i < k; i++) { (*centers)[i] /= centers->getWeight(i); }

    return centers;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rsi, %rbx
movq %rdi, %r12
callq 0x8734
movl %eax, %ebp
leaq 0xc421(%rip), %rsi      # 0x156b4
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
callq 0x54af
movzbl %bpl, %edi
movq %r14, %rsi
callq 0x5364
leaq 0x80(%rsp), %rdi
callq 0x45e8
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
movq %rax, %r14
movq 0x8(%rcx), %r15
subq (%rcx), %r15
movq (%r12), %rsi
leaq 0x80(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x4550
leaq 0xf8(%rsp), %rdi
callq 0x40a0
movl %eax, %ebp
leaq 0xc3eb(%rip), %rsi      # 0x156f0
leaq 0x50(%rsp), %rdi
movq %r12, %rdx
callq 0x54af
movzbl %bpl, %edi
leaq 0x50(%rsp), %rsi
callq 0x5364
movq %rbx, 0x30(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x45e8
leaq 0x58(%rsp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
movslq %r14d, %rsi
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x81b0
shrq $0x3, %r15
movq %r15, 0x8(%rsp)
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
leaq 0x20(%rsp), %rbp
leaq 0x80(%rsp), %r13
cmpq %r15, %r14
je 0x941b
movq %rbp, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x4390
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x5560
cmpq %r12, %rax
jne 0x93fd
movq %rbp, %r13
movq %r14, %rbp
movq %r12, %rbx
movq 0x78(%rsp), %r12
leaq 0x50(%rsp), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0xc1dc
movl %r12d, (%rax)
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x5560
movq %rbx, %r12
movq %rbp, %r14
movq %r13, %rbp
leaq 0x80(%rsp), %r13
leaq 0x10(%rsp), %rdi
movl 0x40(%rax), %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
callq 0x45e8
incq %r15
jmp 0x9381
movl 0x78(%rsp), %r13d
pushq $0x30
popq %rdi
callq 0x42b0
movq %rax, %r12
movq %rax, %rdi
movl %r13d, %esi
movq 0x8(%rsp), %rdx
callq 0x61d4
xorl %eax, %eax
testl %r13d, %r13d
cmovlel %eax, %r13d
cmpq %rax, %r13
je 0x9458
movq 0x18(%r12), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x9444
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x94b8
movq 0x30(%rsp), %rcx
movq 0x18(%rcx), %rax
movsd (%rax,%rbp,8), %xmm0
movq 0x38(%rsp), %rax
movslq (%rax,%rbp,4), %rax
imulq $0x18, %rax, %rdi
addq (%r12), %rdi
movq (%rcx), %rsi
addq %r15, %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x59d6
movq 0x38(%rsp), %rax
movl (%rax,%rbp,4), %eax
movq 0x18(%r12), %rcx
movsd 0x8(%rsp), %xmm0
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rbp
addq $0x18, %r15
jmp 0x945d
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x94e2
movq 0x18(%r12), %rax
movsd (%rax,%r14,8), %xmm0
movq (%r12), %rdi
addq %rbx, %rdi
callq 0x59a8
incq %r14
addq $0x18, %rbx
jmp 0x94bd
leaq 0x38(%rsp), %rdi
callq 0x8498
leaq 0x50(%rsp), %rdi
callq 0xc6bc
leaq 0x80(%rsp), %rdi
callq 0x40c0
movq %r12, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x30
popq %rsi
movq %r12, %rdi
callq 0x42c0
jmp 0x956f
jmp 0x955b
movq %rax, %rbx
jmp 0x9579
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x45e8
jmp 0x9583
movq %rax, %rbx
jmp 0x9583
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x45e8
jmp 0x9590
jmp 0x9562
jmp 0x9562
jmp 0x955b
movq %rax, %rbx
jmp 0x956f
jmp 0x9562
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x45e8
leaq 0x38(%rsp), %rdi
callq 0x8498
leaq 0x50(%rsp), %rdi
callq 0xc6bc
leaq 0x80(%rsp), %rdi
callq 0x40c0
movq %rbx, %rdi
callq 0x4530