// File: mapequation[P]partition-validation/./partition-validation.h
// Function: Partitions::validatePartitions(int)
void Partitions::validatePartitions(int fold) {
    int nValidated = 0;

    auto validationPartitionPtrs = vector<Partition *>(nValidationPartitions);
    for (int i = 0; i < nValidationPartitions; i++) {
        validationPartitionPtrs[i] = &partitions[nPartitions - (fold + 1) * nValidationPartitions + i];
    }

    cout << "--> Number of validation partitions out of " << nValidationPartitions
         << " that fits in one of " << nClusters << " clusters is..." << flush;

    vector<int> validatedPartitions(nValidationPartitions, 0);

#pragma omp parallel for
    for (auto i = 0; i < nValidationPartitions; i++) {
        for (auto j = 0; j < nClusters; j++) {
            if (wpJaccardDist(validationPartitionPtrs[i], clusters[j][0]) < distThreshold) {
#pragma omp atomic
                nValidated++;
                validatedPartitions[i] += 1;
                break;
            }
        }
    }

    cout << nValidated << ". " << endl;
    nTotValidated += nValidated;
    nTotTested += nValidationPartitions;

    if (validationSamples == 0) {
        auto validationOutFileName = outFileName;
        auto periodPos = validationOutFileName.find_last_of('.');
        if (periodPos == string::npos) {
            validationOutFileName += "_validation";
        } else {
            validationOutFileName.insert(periodPos, "_validation");
        }

        cout << "Writing validation results to " << validationOutFileName << endl;

        my_ofstream ofs;
        ofs.open(validationOutFileName.c_str());

        for (int i = 0; i < nValidationPartitions; i++) {
            ofs << validationPartitionPtrs[i]->partitionId + 1 << " " << validatedPartitions[i] << endl;
        }

        ofs.close();
    } else {
        validationOfs << nValidated << " " << nClusters << endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movl $0x0, -0x10(%rbp)
movslq 0x4e8(%rax), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x8770
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x8790
jmp 0x468b
leaq -0x29(%rbp), %rdi
callq 0x8800
movl $0x0, -0x40(%rbp)
movq -0x2b0(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl 0x4e8(%rcx), %eax
jge 0x471e
movq -0x2b0(%rbp), %rdx
movq %rdx, %rdi
addq $0x50, %rdi
movl 0x4dc(%rdx), %eax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
imull 0x4e8(%rdx), %ecx
subl %ecx, %eax
addl -0x40(%rbp), %eax
movslq %eax, %rsi
callq 0x8b10
movq %rax, -0x2b8(%rbp)
movslq -0x40(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8b30
movq -0x2b8(%rbp), %rcx
movq %rcx, (%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x469b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x8800
jmp 0x4c82
movq 0x208ab(%rip), %rdi     # 0x24fd0
leaq 0x13911(%rip), %rsi     # 0x1803d
callq 0x32c0
movq %rax, -0x2c0(%rbp)
jmp 0x473a
movq -0x2c0(%rbp), %rdi
movq -0x2b0(%rbp), %rax
movl 0x4e8(%rax), %esi
callq 0x3490
movq %rax, -0x2c8(%rbp)
jmp 0x475c
movq -0x2c8(%rbp), %rdi
leaq 0x138ff(%rip), %rsi     # 0x18069
callq 0x32c0
movq %rax, -0x2d0(%rbp)
jmp 0x4778
movq -0x2d0(%rbp), %rdi
movq -0x2b0(%rbp), %rax
movl 0x4e0(%rax), %esi
callq 0x3490
movq %rax, -0x2d8(%rbp)
jmp 0x479a
movq -0x2d8(%rbp), %rdi
leaq 0x138d7(%rip), %rsi     # 0x1807f
callq 0x32c0
movq %rax, -0x2e0(%rbp)
jmp 0x47b6
movq -0x2e0(%rbp), %rdi
movq 0x20814(%rip), %rsi     # 0x24fd8
callq 0x3310
jmp 0x47cb
movq -0x2b0(%rbp), %rax
movslq 0x4e8(%rax), %rax
movq %rax, -0x2f0(%rbp)
movl $0x0, -0x5c(%rbp)
leaq -0x5d(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x8d70
movq -0x2f0(%rbp), %rsi
movq -0x2e8(%rbp), %rcx
leaq -0x58(%rbp), %rdi
leaq -0x5c(%rbp), %rdx
callq 0x8d90
jmp 0x4814
leaq -0x5d(%rbp), %rdi
callq 0x8e10
movl $0x0, -0x64(%rbp)
movq -0x2b0(%rbp), %rcx
movl -0x64(%rbp), %eax
cmpl 0x4e8(%rcx), %eax
jge 0x4946
movl $0x0, -0x68(%rbp)
movq -0x2b0(%rbp), %rcx
movl -0x68(%rbp), %eax
cmpl 0x4e0(%rcx), %eax
jge 0x4936
movslq -0x64(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8b30
movq -0x2b0(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x300(%rbp)
addq $0x38, %rdi
movslq -0x68(%rbp), %rsi
callq 0x8ce0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8b30
movq -0x2b0(%rbp), %rdi
movq -0x300(%rbp), %rsi
movq (%rax), %rdx
callq 0x37c0
movsd %xmm0, -0x2f8(%rbp)
jmp 0x48ae
movsd -0x2f8(%rbp), %xmm1
movq -0x2b0(%rbp), %rax
movsd 0x90(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4926
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movslq -0x64(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x8e30
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4936
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x5d(%rbp), %rdi
callq 0x8e10
jmp 0x4c79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4c70
jmp 0x4928
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x4841
jmp 0x4938
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x4824
movl -0x10(%rbp), %esi
movq 0x20680(%rip), %rdi     # 0x24fd0
callq 0x3490
movq %rax, -0x308(%rbp)
jmp 0x495e
movq -0x308(%rbp), %rdi
leaq 0x13723(%rip), %rsi     # 0x1808f
callq 0x32c0
movq %rax, -0x310(%rbp)
jmp 0x497a
movq -0x310(%rbp), %rdi
movq 0x20638(%rip), %rsi     # 0x24fc0
callq 0x3310
jmp 0x498f
movq -0x2b0(%rbp), %rax
movl -0x10(%rbp), %ecx
addl 0x4f0(%rax), %ecx
movl %ecx, 0x4f0(%rax)
movl 0x4e8(%rax), %ecx
addl 0x4f4(%rax), %ecx
movl %ecx, 0x4f4(%rax)
cmpl $0x0, 0x4ec(%rax)
jne 0x4be1
movq -0x2b0(%rbp), %rsi
addq $0x70, %rsi
leaq -0x88(%rbp), %rdi
callq 0x3130
jmp 0x49dd
leaq -0x88(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x3510
movq %rax, -0x90(%rbp)
cmpq $-0x1, -0x90(%rbp)
jne 0x4a2e
leaq 0x13685(%rip), %rsi     # 0x18092
leaq -0x88(%rbp), %rdi
callq 0x32a0
jmp 0x4a1b
jmp 0x4a4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4bd0
movq -0x90(%rbp), %rsi
leaq 0x13656(%rip), %rdx     # 0x18092
leaq -0x88(%rbp), %rdi
callq 0x30b0
jmp 0x4a4a
jmp 0x4a4c
movq 0x2057d(%rip), %rdi     # 0x24fd0
leaq 0x13644(%rip), %rsi     # 0x1809e
callq 0x32c0
movq %rax, -0x318(%rbp)
jmp 0x4a68
movq -0x318(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3280
movq %rax, -0x320(%rbp)
jmp 0x4a84
movq -0x320(%rbp), %rdi
movq 0x2052e(%rip), %rsi     # 0x24fc0
callq 0x3310
jmp 0x4a99
leaq -0x290(%rbp), %rdi
movl $0xf, %esi
callq 0x8e50
jmp 0x4aac
leaq -0x88(%rbp), %rdi
callq 0x3120
movq %rax, %rsi
leaq -0x290(%rbp), %rdi
movl $0x10, %edx
callq 0x3050
jmp 0x4ace
movl $0x0, -0x294(%rbp)
movq -0x2b0(%rbp), %rcx
movl -0x294(%rbp), %eax
cmpl 0x4e8(%rcx), %eax
jge 0x4ba5
movslq -0x294(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8b30
movq (%rax), %rax
movl (%rax), %esi
incl %esi
leaq -0x290(%rbp), %rdi
callq 0x3490
movq %rax, -0x328(%rbp)
jmp 0x4b1d
movq -0x328(%rbp), %rdi
leaq 0x13565(%rip), %rsi     # 0x18090
callq 0x32c0
movq %rax, -0x330(%rbp)
jmp 0x4b39
movslq -0x294(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x8e30
movq -0x330(%rbp), %rdi
movl (%rax), %esi
callq 0x3490
movq %rax, -0x338(%rbp)
jmp 0x4b60
movq -0x338(%rbp), %rdi
movq 0x20452(%rip), %rsi     # 0x24fc0
callq 0x3310
jmp 0x4b75
jmp 0x4b77
movl -0x294(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x294(%rbp)
jmp 0x4ad8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x8f10
jmp 0x4bd0
leaq -0x290(%rbp), %rdi
callq 0x3410
jmp 0x4bb3
leaq -0x290(%rbp), %rdi
callq 0x8f10
leaq -0x88(%rbp), %rdi
callq 0x31a0
jmp 0x4c55
leaq -0x88(%rbp), %rdi
callq 0x31a0
jmp 0x4c70
movq -0x2b0(%rbp), %rdi
addq $0x2d8, %rdi            # imm = 0x2D8
movl -0x10(%rbp), %esi
callq 0x3490
movq %rax, -0x340(%rbp)
jmp 0x4c00
movq -0x340(%rbp), %rdi
leaq 0x13482(%rip), %rsi     # 0x18090
callq 0x32c0
movq %rax, -0x348(%rbp)
jmp 0x4c1c
movq -0x348(%rbp), %rdi
movq -0x2b0(%rbp), %rax
movl 0x4e0(%rax), %esi
callq 0x3490
movq %rax, -0x350(%rbp)
jmp 0x4c3e
movq -0x350(%rbp), %rdi
movq 0x20374(%rip), %rsi     # 0x24fc0
callq 0x3310
jmp 0x4c53
jmp 0x4c55
leaq -0x58(%rbp), %rdi
callq 0x8f50
leaq -0x28(%rbp), %rdi
callq 0x8c80
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x8f50
leaq -0x28(%rbp), %rdi
callq 0x8c80
movq -0x38(%rbp), %rdi
callq 0x34a0
nopl (%rax,%rax)