// File: /workspace/github_cpp_makefile_star2_O2/hanhwi[P]SimPoint/analysiscode/Simpoint.cpp
// Function: Simpoint::saveSimpoints(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<bool, std::allocator<bool>> const&, Datapoint const&, std::vector<int, std::allocator<int>> const&, unsigned int)
void Simpoint::saveSimpoints(const string &filename, const vector<bool> &largestClusters,
        const Datapoint &distsToCenters, const vector<int> &labels, unsigned int k) {

    vector<double> minDists(k, -1.0);
    vector<int> simpoints(k, -1);
    for (unsigned int i = 0; i < distsToCenters.size(); i++) {
        int label = labels[i];
        if ((simpoints[label] == -1) || (distsToCenters[i] < minDists[label])) {
            simpoints[label] = i;
            minDists[label] = distsToCenters[i];
        }
    }

    ofstream output(filename.c_str());
    Utilities::check(output.is_open(), "Simpoint::saveSimpoints(): could not open file " +
                            filename);
    for (unsigned int i = 0; i < k; i++) {
        if (largestClusters[i]) {
            output << simpoints[i] << " " << i << endl;
        }
    }
    output.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
movl %r8d, %r14d
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
leaq 0x58(%rsp), %rbp
movq %rax, (%rbp)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rcx
movq %r14, %rsi
movq %rbp, %rdx
callq 0x6bd2
orl $-0x1, (%rbp)
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r14, %rsi
callq 0xc326
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq (%r12), %rdx
movq 0x8(%rsp), %rsi
xorl %edi, %edi
movq 0x40(%rsp), %r8
movl %edi, %r10d
cmpq %r10, %rcx
jbe 0xa6f1
movslq (%rdx,%r10,4), %r9
cmpl $-0x1, (%rsi,%r9,4)
movsd (%rax,%r10,8), %xmm0
je 0xa6e3
movsd (%r8,%r9,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xa6ed
movl %edi, (%rsi,%r9,4)
movsd %xmm0, (%r8,%r9,8)
incl %edi
jmp 0xa6be
movq (%r15), %rsi
leaq 0x58(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x42f0
leaq 0xc8(%rsp), %rdi
callq 0x40a0
movl %eax, %ebp
leaq 0xb48f(%rip), %rsi      # 0x15ba6
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x54af
movzbl %bpl, %edi
leaq 0x20(%rsp), %rsi
callq 0x5364
leaq 0x20(%rsp), %rdi
callq 0x45e8
xorl %r15d, %r15d
leaq 0x58(%rsp), %r12
leaq 0xda69(%rip), %r13      # 0x181b4
cmpq %r15, %r14
je 0xa793
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc37c
testb %al, %al
je 0xa78e
movq 0x8(%rsp), %rax
movl (%rax,%r15,4), %esi
movq %r12, %rdi
callq 0x4510
movq %rax, %rdi
movq %r13, %rsi
callq 0x4290
movq %rax, %rdi
movq %r15, %rsi
callq 0x41e0
movq %rax, %rdi
callq 0x4180
incq %r15
jmp 0xa74b
leaq 0x58(%rsp), %rdi
callq 0x4400
leaq 0x58(%rsp), %rdi
callq 0x4440
leaq 0x8(%rsp), %rdi
callq 0x8498
leaq 0x40(%rsp), %rdi
callq 0x5f0a
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa7ea
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x45e8
jmp 0xa7ed
jmp 0xa7ea
movq %rax, %rbx
jmp 0xa7f7
movq %rax, %rbx
jmp 0xa801
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4440
leaq 0x8(%rsp), %rdi
callq 0x8498
leaq 0x40(%rsp), %rdi
callq 0x5f0a
movq %rbx, %rdi
callq 0x4530
nop