// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq %rdi, %r15
movq (%rdi), %rdi
leaq 0x80(%rsp), %r14
movq %r14, %rsi
callq 0x4280
movl %eax, %ebp
movl $0xf000, %r12d          # imm = 0xF000
andl 0x18(%r14), %r12d
leaq 0x11bc1(%rip), %rsi     # 0x1c704
leaq 0x80(%rsp), %rdi
movq %r15, %rdx
callq 0x5ed9
testl %ebp, %ebp
jne 0xae17
cmpl $0x8000, %r12d          # imm = 0x8000
jne 0xae17
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xab89
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x8(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %r14
movq 0x8(%r12), %r13
subq (%r12), %r13
movq (%r15), %rsi
leaq 0x80(%rsp), %rdi
movl $0x8, %edx
callq 0x45a0
leaq 0xf8(%rsp), %rdi
callq 0x40b0
movl %eax, %ebp
leaq 0x11b77(%rip), %rsi     # 0x1c740
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x5ed9
testb %bpl, %bpl
je 0xae5e
subq %r12, %r14
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xac0f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r13, 0x78(%rsp)
leaq 0x50(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movslq %ebx, %rsi
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x950a
movq %rbx, (%rsp)
testl %ebx, %ebx
leaq 0x50(%rsp), %rbx
jle 0xacf0
leaq 0x38(%rsp), %r14
movq (%rsp), %rbp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
leaq 0x28(%rsp), %r12
leaq 0x48(%rsp), %r13
movq %r14, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x43c0
movq %r13, %rdi
movq %r12, %rsi
callq 0x5f62
cmpq %rbx, %rax
jne 0xacc5
movq 0x70(%rsp), %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0xf572
movl %ebx, (%rax)
movq %r13, %rdi
movq %r12, %rsi
callq 0x5f62
leaq 0x50(%rsp), %rbx
movl 0x40(%rax), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0xace8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
incq %r15
cmpq %r15, %rbp
jne 0xac70
movq 0x70(%rsp), %r12
movl $0x30, %edi
callq 0x42c0
movq %rax, %r15
movq 0x78(%rsp), %rdx
shrq $0x3, %rdx
movq %rax, %rdi
movl %r12d, %esi
callq 0x6e50
movq 0x8(%rsp), %rbx
movq (%rsp), %rbp
testl %r12d, %r12d
jle 0xad3c
movq 0x18(%r15), %rdi
movl %r12d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x4190
testl %ebp, %ebp
jle 0xada2
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
movsd (%rax,%r13,8), %xmm0
movq 0x10(%rsp), %rax
movslq (%rax,%r13,4), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x3, %rdi
addq (%r15), %rdi
movq (%rbx), %rsi
addq %r14, %rsi
movsd %xmm0, (%rsp)
callq 0x659c
movq 0x10(%rsp), %rax
movl (%rax,%r13,4), %eax
movq 0x18(%r15), %rcx
movsd (%rsp), %xmm0
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %r13
addq $0x18, %r14
cmpq %r13, %rbp
jne 0xad4c
testl %r12d, %r12d
jle 0xadd4
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x18(%r15), %rax
movsd (%rax,%r14,8), %xmm0
movq (%r15), %rdi
addq %rbx, %rdi
callq 0x656c
incq %r14
addq $0x18, %rbx
cmpq %r14, %r12
jne 0xadb3
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xadeb
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
leaq 0x48(%rsp), %rdi
callq 0xfc58
leaq 0x80(%rsp), %rdi
callq 0x40c0
movq %r15, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c512(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x11349(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
jmp 0xae9d
leaq 0x1c4cb(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x11302(%rip), %rsi     # 0x1c178
movl $0x8, %edx
movq %rbx, %rdi
callq 0x4330
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x4330
movq %rax, %rdi
callq 0x4160
movl $0x1, %edi
callq 0x4370
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf59
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xaf59
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaf66
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xaf66
movq %rax, %rbx
movl $0x30, %esi
movq %r15, %rdi
jmp 0xaf33
jmp 0xaf17
movq %rax, %rbx
jmp 0xaf4f
movq %rax, %rbx
jmp 0xaf59
jmp 0xaf1e
jmp 0xaf1e
jmp 0xaf17
movq %rax, %rbx
jmp 0xaf38
jmp 0xaf1e
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0xaf38
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xaf4f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
leaq 0x48(%rsp), %rdi
callq 0xfc58
leaq 0x80(%rsp), %rdi
callq 0x40c0
movq %rbx, %rdi
callq 0x4580