// File: 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:
subq $0x308, %rsp            # imm = 0x308
movq %rdi, 0x300(%rsp)
movq %rsi, 0x2f8(%rsp)
movq %rdx, 0x2f0(%rsp)
movq %rcx, 0x2e8(%rsp)
movl %r8d, 0x2e4(%rsp)
movl 0x2e4(%rsp), %eax
movq %rax, 0x48(%rsp)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x2c0(%rsp)
leaq 0x2bf(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x99c0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rcx
leaq 0x2c8(%rsp), %rdi
leaq 0x2c0(%rsp), %rdx
callq 0xbee0
jmp 0x16bc0
leaq 0x2bf(%rsp), %rdi
callq 0x9a50
movl 0x2e4(%rsp), %eax
movq %rax, 0x38(%rsp)
movl $0xffffffff, 0x28c(%rsp) # imm = 0xFFFFFFFF
leaq 0x28b(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x10e30
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rcx
leaq 0x290(%rsp), %rdi
leaq 0x28c(%rsp), %rdx
callq 0x1a9a0
jmp 0x16c17
leaq 0x28b(%rsp), %rdi
callq 0x10ec0
movl $0x0, 0x284(%rsp)
movl 0x284(%rsp), %eax
movq %rax, 0x30(%rsp)
movq 0x2f0(%rsp), %rdi
callq 0x9b60
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x16da6
movq 0x2e8(%rsp), %rdi
movl 0x284(%rsp), %eax
movl %eax, %esi
callq 0x10e10
movl (%rax), %eax
movl %eax, 0x280(%rsp)
movslq 0x280(%rsp), %rsi
leaq 0x290(%rsp), %rdi
callq 0x10dd0
cmpl $-0x1, (%rax)
je 0x16cdb
movq 0x2f0(%rsp), %rdi
movl 0x284(%rsp), %eax
movl %eax, %esi
callq 0x9b80
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x280(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
callq 0x9ba0
movsd 0x28(%rsp), %xmm1
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16d8e
movl 0x284(%rsp), %eax
movl %eax, 0x1c(%rsp)
movslq 0x280(%rsp), %rsi
leaq 0x290(%rsp), %rdi
callq 0x10dd0
movl 0x1c(%rsp), %ecx
movl %ecx, (%rax)
movq 0x2f0(%rsp), %rdi
movl 0x284(%rsp), %eax
movl %eax, %esi
callq 0x9b80
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movslq 0x280(%rsp), %rsi
leaq 0x2c8(%rsp), %rdi
callq 0x9ba0
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x16d8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x2bf(%rsp), %rdi
callq 0x9a50
jmp 0x16f86
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x28b(%rsp), %rdi
callq 0x10ec0
jmp 0x16f79
jmp 0x16d90
movl 0x284(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x284(%rsp)
jmp 0x16c2f
movq 0x300(%rsp), %rdi
callq 0x5190
movq %rax, %rsi
leaq 0x80(%rsp), %rdi
movl $0x10, %edx
callq 0x53f0
jmp 0x16dca
leaq 0x80(%rsp), %rdi
callq 0x5290
movb %al, 0x1b(%rsp)
jmp 0x16ddd
movq 0x300(%rsp), %rdx
leaq 0x1cdaa(%rip), %rsi     # 0x33b96
leaq 0x60(%rsp), %rdi
callq 0x7880
jmp 0x16df8
movb 0x1b(%rsp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x60(%rsp), %rsi
callq 0x7480
jmp 0x16e0e
leaq 0x60(%rsp), %rdi
callq 0x5788
movl $0x0, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x2e4(%rsp), %eax
jae 0x16f21
movq 0x2f8(%rsp), %rdi
movl 0x5c(%rsp), %eax
movl %eax, %esi
callq 0x1aa20
movb %al, 0x1a(%rsp)
jmp 0x16e4a
movb 0x1a(%rsp), %al
testb $0x1, %al
jne 0x16e57
jmp 0x16f0f
movl 0x5c(%rsp), %eax
movl %eax, %esi
leaq 0x290(%rsp), %rdi
callq 0x10dd0
movl (%rax), %esi
leaq 0x80(%rsp), %rdi
callq 0x5680
movq %rax, 0x10(%rsp)
jmp 0x16e80
movq 0x10(%rsp), %rdi
leaq 0x1f318(%rip), %rsi     # 0x361a4
callq 0x5360
movq %rax, 0x8(%rsp)
jmp 0x16e98
movq 0x8(%rsp), %rdi
movl 0x5c(%rsp), %esi
callq 0x5520
movq %rax, (%rsp)
jmp 0x16eac
movq (%rsp), %rdi
movq 0x2d109(%rip), %rsi     # 0x43fc0
callq 0x53c0
jmp 0x16ebe
jmp 0x16f0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x16f6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x16f5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5788
jmp 0x16f5f
jmp 0x16f11
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x16e20
leaq 0x80(%rsp), %rdi
callq 0x5560
jmp 0x16f30
leaq 0x80(%rsp), %rdi
callq 0x55a0
leaq 0x290(%rsp), %rdi
callq 0x10ed0
leaq 0x2c8(%rsp), %rdi
callq 0x9960
addq $0x308, %rsp            # imm = 0x308
retq
leaq 0x80(%rsp), %rdi
callq 0x55a0
leaq 0x290(%rsp), %rdi
callq 0x10ed0
leaq 0x2c8(%rsp), %rdi
callq 0x9960
movq 0x2b0(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)