// File: /workspace/github_cpp_makefile_star2_O3/mapequation[P]partition-validation/./partition-validation.h
// Function: Partitions::clusterPartitions(int)
void Partitions::clusterPartitions(int fold) {
#ifdef _OPENMP
    // Initiate locks to keep track of best solutions
    omp_lock_t lock;
    omp_init_lock(&lock);
#endif

    cout << "Clustering " << nTrainingPartitions << " partitions:" << endl;

    auto partitionPtrs = vector<Partition *>(nTrainingPartitions);

    if (validationSamples > 0) {
        // Shuffle partitions for new training and validation set
        shuffle(begin(partitions), end(partitions), mtRands[0]);
    }

    for (auto i = 0; i < nTrainingPartitions; i++) {
        auto limit = nPartitions - (fold + 1) * nValidationPartitions;
        auto offset = i >= limit ? nValidationPartitions : 0;
        partitionPtrs[i] = &partitions[i + offset];
    }

    if (crossValidateK > 0 || validationSamples > 0) {
        // Order randomized partitions
        sort(begin(partitionPtrs), end(partitionPtrs),
             [](Partition *a, Partition *b) { return a->partitionId < b->partitionId; });
    }

    clusters.clear();
    clusters.push_back({partitionPtrs[0]});
    nClusters++;

    for (int i = 1; i < nTrainingPartitions; i++) {
        auto fitsInCluster = false;
        for (int j = 0; j < nClusters; j++) {
            if (wpJaccardDist(partitionPtrs[i], clusters[j][0]) < distThreshold) {
                fitsInCluster = true;
                clusters[j].push_back(partitionPtrs[i]);
                break;
            }
        }
        if (!fitsInCluster) {
            clusters.push_back({partitionPtrs[i]});
            nClusters++;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq 0xa366(%rip), %r14      # 0xdfd8
leaq 0x6427(%rip), %rsi      # 0xa0a0
movl $0xb, %edx
movq %r14, %rdi
callq 0x32a0
movl 0x4e4(%rbx), %esi
movq %r14, %rdi
callq 0x33d0
movq %rax, %r14
leaq 0x640e(%rip), %rsi      # 0xa0ac
movl $0xc, %edx
movq %rax, %rdi
callq 0x32a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movslq 0x4e4(%rbx), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x667a
cmpl $0x0, 0x4ec(%rbx)
jle 0x3d05
movq 0x50(%rbx), %rdi
movq 0x58(%rbx), %rsi
movq 0x98(%rbx), %rdx
callq 0x6707
movslq 0x4e4(%rbx), %rax
testq %rax, %rax
jle 0x3d52
notl %ebp
movl 0x4e8(%rbx), %ecx
imull %ecx, %ebp
addl 0x4dc(%rbx), %ebp
movslq %ebp, %rdx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rdx, %rdi
movl %ecx, %r8d
cmovll %esi, %r8d
addl %edi, %r8d
movslq %r8d, %r8
imulq $0x58, %r8, %r8
addq 0x50(%rbx), %r8
movq 0x28(%rsp), %r9
movq %r8, (%r9,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x3d29
cmpl $0x0, 0x68(%rbx)
jg 0x3d65
cmpl $0x0, 0x4ec(%rbx)
jle 0x3df0
movq 0x28(%rsp), %r12
movq 0x30(%rsp), %r14
cmpq %r14, %r12
je 0x3df0
movq %r14, %r15
subq %r12, %r15
movq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x6247
cmpq $0x81, %r15
jl 0x3de5
leaq 0x80(%r12), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x6478
cmpq %r14, %r15
je 0x3df0
movq -0x8(%r15), %rcx
movq (%r15), %rax
movl (%rax), %edx
movq %r15, %rsi
cmpl %edx, (%rcx)
jle 0x3ddc
movq %r15, %rsi
movq %rcx, (%rsi)
movq -0x10(%rsi), %rcx
addq $-0x8, %rsi
cmpl %edx, (%rcx)
jg 0x3dcd
movq %rax, (%rsi)
addq $0x8, %r15
jmp 0x3db5
movq %r12, %rdi
movq %r14, %rsi
callq 0x6478
leaq 0x38(%rbx), %r14
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x8a4e
movq 0x28(%rsp), %rax
movq (%rax), %rax
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x68da
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x8a98
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3e48
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
incl 0x4e0(%rbx)
cmpl $0x2, 0x4e4(%rbx)
jl 0x3f45
movl $0x1, %ebp
leaq 0x10(%rsp), %r15
cmpl $0x0, 0x4e0(%rbx)
jle 0x3eb1
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq 0x38(%rbx), %rax
movq (%rax,%r12), %rax
movq (%rax), %rdx
movq %rbx, %rdi
callq 0x37fc
movsd 0x90(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3f00
incq %r13
movslq 0x4e0(%rbx), %rax
addq $0x18, %r12
cmpq %rax, %r13
jl 0x3e74
movq 0x28(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %edx
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x68da
movq %r14, %rdi
movq %r15, %rsi
callq 0x8a98
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3ef8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
incl 0x4e0(%rbx)
jmp 0x3f32
movq (%r14), %rax
leaq (,%rbp,8), %rdx
addq 0x28(%rsp), %rdx
leaq (%rax,%r12), %rdi
movq 0x8(%rax,%r12), %rsi
cmpq 0x10(%rax,%r12), %rsi
je 0x3f2d
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x3f32
callq 0x8d16
incq %rbp
movslq 0x4e4(%rbx), %rax
cmpq %rax, %rbp
jl 0x3e65
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3f5c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3f91
jmp 0x3f75
jmp 0x3f91
jmp 0x3f91
jmp 0x3f91
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3f94
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
jmp 0x3f94
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3fab
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x33e0
nop