// File: /workspace/github_cpp_makefile_star2_O3/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 0x11b79(%rip), %rsi     # 0x1c704
leaq 0x80(%rsp), %rdi
movq %r15, %rdx
callq 0x5ea5
testl %ebp, %ebp
jne 0xae5f
cmpl $0x8000, %r12d          # imm = 0x8000
jne 0xae5f
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xabd1
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 0x11b2f(%rip), %rsi     # 0x1c740
leaq 0x48(%rsp), %rdi
movq %r15, %rdx
callq 0x5ea5
testb %bpl, %bpl
je 0xaea6
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 0xac57
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 0x952a
movq %rbx, (%rsp)
testl %ebx, %ebx
leaq 0x50(%rsp), %rbx
jle 0xad38
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 0x5f2e
cmpq %rbx, %rax
jne 0xad0d
movq 0x70(%rsp), %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0xf4fa
movl %ebx, (%rax)
movq %r13, %rdi
movq %r12, %rsi
callq 0x5f2e
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 0xad30
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
incq %r15
cmpq %r15, %rbp
jne 0xacb8
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 0x6e3c
movq 0x8(%rsp), %rbx
movq (%rsp), %rbp
testl %r12d, %r12d
jle 0xad84
movq 0x18(%r15), %rdi
movl %r12d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x4190
testl %ebp, %ebp
jle 0xadea
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rax
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x18(%rbx), %rcx
movsd (%rcx,%r13,8), %xmm0
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 0x6584
movq 0x10(%rsp), %rax
movl (%rax,%r13,4), %ecx
movq 0x18(%r15), %rdx
movsd (%rsp), %xmm0
addsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %r13
addq $0x18, %r14
cmpq %r13, %rbp
jne 0xad99
testl %r12d, %r12d
jle 0xae1c
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 0x6554
incq %r14
addq $0x18, %rbx
cmpq %r14, %r12
jne 0xadfb
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xae33
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
leaq 0x48(%rsp), %rdi
callq 0xfbee
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 0x1c4ca(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x11301(%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 0xaee5
leaq 0x1c483(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0x112ba(%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 0xafa1
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xafa1
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xafae
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xafae
movq %rax, %rbx
movl $0x30, %esi
movq %r15, %rdi
jmp 0xaf7b
jmp 0xaf5f
movq %rax, %rbx
jmp 0xaf97
movq %rax, %rbx
jmp 0xafa1
jmp 0xaf66
jmp 0xaf66
jmp 0xaf5f
movq %rax, %rbx
jmp 0xaf80
jmp 0xaf66
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0xaf80
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xaf97
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
leaq 0x48(%rsp), %rdi
callq 0xfbee
leaq 0x80(%rsp), %rdi
callq 0x40c0
movq %rbx, %rdi
callq 0x4580