// File: /workspace/github_cpp_makefile_star2_O3/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, 0x4(%rsp)
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 0x7ac0
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
leaq 0x20(%rsp), %rcx
movq %r14, %rsi
callq 0xf660
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
je 0xc9ad
sarq $0x3, %rcx
movq (%r12), %rdx
movq 0x8(%rsp), %rsi
movq 0x40(%rsp), %rdi
xorl %r8d, %r8d
movslq (%rdx,%r8,4), %r9
cmpl $-0x1, (%rsi,%r9,4)
movsd (%rax,%r8,8), %xmm0
je 0xc998
movsd (%rdi,%r9,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0xc9a2
movl %r8d, (%rsi,%r9,4)
movsd %xmm0, (%rdi,%r9,8)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rcx
ja 0xc97b
movq (%r15), %rsi
leaq 0x58(%rsp), %rdi
movl $0x10, %edx
callq 0x4310
leaq 0xc8(%rsp), %rdi
callq 0x40b0
movl %eax, %r12d
leaq 0x10220(%rip), %rsi     # 0x1cbf6
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x5ea5
testb %r12b, %r12b
je 0xcb11
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xca07
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpl $0x0, 0x4(%rsp)
je 0xca95
xorl %r15d, %r15d
leaq 0x58(%rsp), %r12
leaq 0x127e3(%rip), %r13     # 0x1f204
movq (%rbx), %rax
movl %r15d, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %r15, %rax
jae 0xca8d
movq 0x8(%rsp), %rax
movl (%rax,%r15,4), %esi
movq %r12, %rdi
callq 0x4560
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x4330
movq %rbp, %rdi
movq %r15, %rsi
callq 0x41c0
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x4290
movsbl %al, %esi
movq %rbp, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x41d0
incq %r15
cmpq %r15, %r14
jne 0xca21
leaq 0x58(%rsp), %rdi
callq 0x4440
movq 0x1a522(%rip), %rax     # 0x26fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x60(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x58(%rsp,%rcx)
callq 0x4240
leaq 0x150(%rsp), %rdi
callq 0x4120
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xcae8
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xcaff
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a818(%rip), %rax     # 0x27330
movl (%rax), %ecx
shrl $0x1f, %ecx
movq 0x8(%rax,%rcx,8), %rbx
leaq 0xf64f(%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
movl $0x1, %edi
callq 0x4370
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xcb8b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0xcb8b
jmp 0xcb88
jmp 0xcb88
movq %rax, %rbx
jmp 0xcb95
movq %rax, %rbx
jmp 0xcbac
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4480
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xcbac
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xcbc3
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x4580
nop