// File: /workspace/github_cpp_makefile_star2_O1/mapequation[P]partition-validation/./partition-validation.h
// Function: Partitions::wpJaccardDist(Partition*, Partition*)
double Partitions::wpJaccardDist(Partition *partition1, Partition *partition2) {
    auto partition1Id = partition1->partitionId;
    auto partition2Id = partition2->partitionId;

    if (partition1Id > partition2Id)
        swap(partition1Id, partition2Id);

    auto lookup = wpJaccardDistLookUp.find(make_pair(partition1Id, partition2Id));

    if (lookup != end(wpJaccardDistLookUp))
        return lookup->second;

    auto partition1Size = partition1->clusterSizes.size();
    auto partition2Size = partition2->clusterSizes.size();

    vector<double> maxClusterSimilarityPartition1(partition1Size, 0.0);
    vector<double> maxClusterSimilarityPartition2(partition2Size, 0.0);

    unordered_map<pair<int, int>, int, pairhash> jointM;

    for (int k = 0; k < nNodes; k++) {
        for (auto id1: partition1->assignments[k]) {
            for (auto &id2: partition2->assignments[k]) {
                jointM[make_pair(id1, id2)]++;
            }
        }
    }

    for (auto &[ids, nCommon]: jointM) {
        int nTotal = partition1->clusterSizes[ids.first] + partition2->clusterSizes[ids.second] - nCommon;
        double clusterSim = 1.0 * nCommon / nTotal;
        maxClusterSimilarityPartition1[ids.first] = max(clusterSim, maxClusterSimilarityPartition1[ids.first]);
        maxClusterSimilarityPartition2[ids.second] = max(clusterSim, maxClusterSimilarityPartition2[ids.second]);
    }

    int nAssignments1 = 0;
    double sim1 = 0.0;

    for (auto i = 0; i < static_cast<int>(partition1Size); i++) {
        sim1 += maxClusterSimilarityPartition1[i] * partition1->clusterSizes[i];
        nAssignments1 += partition1->clusterSizes[i];
    }

    sim1 /= 1.0 * nAssignments1;

    int nAssignments2 = 0;
    double sim2 = 0.0;

    for (auto i = 0; i < static_cast<int>(partition2Size); i++) {
        sim2 += maxClusterSimilarityPartition2[i] * partition2->clusterSizes[i];
        nAssignments2 += partition2->clusterSizes[i];
    }

    sim2 /= 1.0 * nAssignments2;

    double dist = 1.0 - 0.5 * sim1 - 0.5 * sim2;

    wpJaccardDistLookUp[make_pair(partition1Id, partition2Id)] = dist;

    return dist;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
movl (%rsi), %eax
movl (%rdx), %ebx
cmpl %ebx, %eax
movl %ebx, %ecx
cmovgl %eax, %ecx
cmovll %eax, %ebx
shlq $0x20, %rcx
orq %rcx, %rbx
leaq 0x80(%rsp), %rsi
movq %rbx, (%rsi)
callq 0x802c
testq %rax, %rax
je 0x384a
movsd 0x10(%rax), %xmm0
jmp 0x3bbf
movq %rbx, 0x68(%rsp)
movq %r15, 0x18(%rsp)
movq 0x38(%r15), %rsi
movq 0x38(%r13), %r12
xorl %ebx, %ebx
leaq 0x80(%rsp), %r15
movq %rbx, (%r15)
leaq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rcx
movq %rsi, 0x30(%rsp)
movq %r15, %rdx
callq 0x6578
movq %rbx, (%r15)
leaq 0x38(%rsp), %rdi
leaq 0x80(%rsp), %rdx
movq %rsp, %rcx
movq %r12, 0x28(%rsp)
movq %r12, %rsi
callq 0x6578
leaq 0xb0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
cmpl $0x0, 0x4d8(%r14)
jle 0x3983
xorl %ecx, %ecx
leaq 0x80(%rsp), %rbp
movq %rsp, %r15
movq %r14, 0x70(%rsp)
movq %r13, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x78(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r12
movq %rcx, 0x8(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
cmpq %rax, %r12
je 0x3966
movq 0x8(%r13), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movq 0x8(%rax,%rcx,8), %r14
cmpq %r14, %rbx
je 0x3956
movl (%r12), %r13d
movl (%rbx), %eax
shlq $0x20, %rax
orq %r13, %rax
movq %rax, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x80de
incl (%rax)
addq $0x4, %rbx
cmpq %r14, %rbx
jne 0x3933
addq $0x4, %r12
cmpq 0x10(%rsp), %r12
movq 0x20(%rsp), %r13
jne 0x3918
movq 0x78(%rsp), %rcx
incq %rcx
movq 0x70(%rsp), %r14
movslq 0x4d8(%r14), %rax
cmpq %rax, %rcx
jl 0x38ee
movq 0x18(%rsp), %r15
addq $0x20, %r15
addq $0x20, %r13
movq 0x90(%rsp), %rbx
testq %rbx, %rbx
movq 0x28(%rsp), %r12
je 0x3a0b
leaq 0x8(%rbx), %rsi
movq %r15, %rdi
callq 0x83ea
movl (%rax), %ebp
leaq 0xc(%rbx), %rsi
movq %r13, %rdi
callq 0x83ea
addl (%rax), %ebp
movl 0x10(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subl %eax, %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
movslq 0x8(%rbx), %rax
movq 0x50(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
movslq 0xc(%rbx), %rax
movq 0x38(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x39a2
movl $0x0, (%rsp)
movsd 0x65ee(%rip), %xmm1     # 0xa008
movapd %xmm1, %xmm2
cmpl $0x0, 0x30(%rsp)
jle 0x3ab1
movq %r15, 0x18(%rsp)
xorl %ebx, %ebx
xorpd %xmm2, %xmm2
movq %rsp, %r15
xorl %eax, %eax
movq 0x18(%rsp), %r12
movsd %xmm2, 0x10(%rsp)
cltq
movq 0x50(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x83ea
movl (%rax), %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0x83ea
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm2
addsd %xmm1, %xmm2
addl (%rax), %ebx
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x30(%rsp), %eax
jl 0x3a3e
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
divsd %xmm0, %xmm2
movsd 0x655c(%rip), %xmm1     # 0xa008
movq 0x28(%rsp), %r12
movsd %xmm2, 0x10(%rsp)
movl $0x0, (%rsp)
testl %r12d, %r12d
jle 0x3b33
xorl %ebx, %ebx
xorpd %xmm1, %xmm1
movq %rsp, %r15
xorl %eax, %eax
movsd %xmm1, 0x8(%rsp)
cltq
movq 0x38(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x83ea
movl (%rax), %ebp
movq %r13, %rdi
movq %r15, %rsi
callq 0x83ea
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x20(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm1
addsd %xmm2, %xmm1
addl (%rax), %ebx
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl %r12d, %eax
jl 0x3ace
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %rsp, %rsi
movq 0x68(%rsp), %rax
movq %rax, (%rsi)
movq %r14, %rdi
callq 0x86b2
movsd 0x64bc(%rip), %xmm0     # 0xa010
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd 0x64b2(%rip), %xmm2     # 0xa018
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm1, (%rax)
leaq 0x80(%rsp), %rdi
callq 0x7276
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3ba2
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3bb9
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movsd 0x8(%rsp), %xmm0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3bde
movq %rax, %rbx
jmp 0x3c05
jmp 0x3bde
jmp 0x3bde
jmp 0x3bde
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x7276
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3c05
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3c1c
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x33e0