// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
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 0x90(%rsp), %rsi
movq %rbx, (%rsi)
callq 0x6dca
testq %rax, %rax
je 0x368c
movsd 0x10(%rax), %xmm0
jmp 0x399b
movq %rbx, 0x28(%rsp)
movq 0x38(%r13), %rsi
movq 0x38(%r12), %r14
leaq 0x90(%rsp), %rbx
andq $0x0, (%rbx)
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movq %rsi, 0x48(%rsp)
movq %rbx, %rdx
callq 0x55b6
andq $0x0, (%rbx)
leaq 0x60(%rsp), %rdi
leaq 0x90(%rsp), %rdx
movq %rsp, %rcx
movq %r14, 0x40(%rsp)
movq %r14, %rsi
callq 0x55b6
movq %r13, 0x38(%rsp)
leaq 0x20(%r13), %rax
movq %rax, 0x20(%rsp)
movq %r12, 0x18(%rsp)
leaq 0x20(%r12), %r13
leaq 0xc0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
leaq 0xa0(%rsp), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movl $0x3f800000, 0x10(%rax) # imm = 0x3F800000
movupd %xmm0, 0x18(%rax)
xorl %ecx, %ecx
leaq 0x90(%rsp), %rbx
movq %rsp, %r12
movq %r15, 0x30(%rsp)
movq %r13, 0x58(%rsp)
movslq 0x4d8(%r15), %rax
cmpq %rax, %rcx
jge 0x37d6
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x50(%rsp)
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %r15
movq %rcx, 0x10(%rsp)
movq 0x8(%rax,%rcx), %rax
movq %rax, 0x8(%rsp)
cmpq 0x8(%rsp), %r15
je 0x37c4
movl (%r15), %ebp
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx), %r14
movq 0x8(%rax,%rcx), %r13
cmpq %r13, %r14
je 0x37b9
movl (%r14), %eax
shlq $0x20, %rax
orq %rbp, %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6f56
incl (%rax)
addq $0x4, %r14
jmp 0x3793
addq $0x4, %r15
movq 0x58(%rsp), %r13
jmp 0x3772
movq 0x50(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %r15
jmp 0x373d
leaq 0xa0(%rsp), %r14
movq (%r14), %r14
testq %r14, %r14
movq 0x20(%rsp), %rdi
je 0x3846
leaq 0x8(%r14), %rsi
callq 0x72e8
movl (%rax), %ebx
leaq 0xc(%r14), %rsi
movq %r13, %rdi
callq 0x72e8
addl (%rax), %ebx
movl 0x10(%r14), %eax
subl %eax, %ebx
cvtsi2sd %eax, %xmm0
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
movslq 0x8(%r14), %rax
movq 0x78(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
movslq 0xc(%r14), %rax
movq 0x60(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
jmp 0x37de
xorpd %xmm1, %xmm1
xorl %eax, %eax
movq %rsp, %rbx
xorl %ebp, %ebp
movq 0x20(%rsp), %r12
movl %eax, (%rsp)
cmpl 0x48(%rsp), %eax
jge 0x38b2
movsd %xmm1, 0x10(%rsp)
cltq
movq 0x78(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72e8
movl (%rax), %r14d
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72e8
cvtsi2sd %r14d, %xmm0
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x10(%rsp), %xmm1
addsd %xmm2, %xmm1
addl (%rax), %ebp
movl (%rsp), %eax
incl %eax
jmp 0x3856
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorpd %xmm0, %xmm0
xorl %eax, %eax
movq %rsp, %rbx
xorl %ebp, %ebp
movsd %xmm0, 0x8(%rsp)
movl %eax, (%rsp)
cmpl 0x40(%rsp), %eax
jge 0x3927
cltq
movq 0x60(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x72e8
movl (%rax), %r14d
movq %r13, %rdi
movq %rbx, %rsi
callq 0x72e8
cvtsi2sd %r14d, %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
addl (%rax), %ebp
movl (%rsp), %eax
incl %eax
jmp 0x38cb
movq %rsp, %rsi
movq 0x28(%rsp), %rax
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x7620
cvtsi2sd %ebp, %xmm0
movsd 0x56c2(%rip), %xmm1     # 0x9008
movsd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm2
addsd 0x56b8(%rip), %xmm2     # 0x9010
movsd 0x8(%rsp), %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rsp)
movsd %xmm3, (%rax)
leaq 0x90(%rsp), %rdi
callq 0x5f66
leaq 0x60(%rsp), %rdi
callq 0x6e96
leaq 0x78(%rsp), %rdi
callq 0x6e96
movsd 0x8(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39ba
movq %rax, %rbx
jmp 0x39d4
jmp 0x39ba
jmp 0x39ba
jmp 0x39ba
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x5f66
leaq 0x60(%rsp), %rdi
callq 0x6e96
leaq 0x78(%rsp), %rdi
callq 0x6e96
movq %rbx, %rdi
callq 0x33e0