// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movq %rsi, %rbx
movq %rdi, %r15
movl (%rsi), %eax
movl (%rdx), %r12d
cmpl %r12d, %eax
movl %r12d, %ecx
cmovgl %eax, %ecx
cmovll %eax, %r12d
shlq $0x20, %rcx
orq %rcx, %r12
leaq 0x90(%rsp), %rsi
movq %r12, (%rsi)
callq 0x8152
testq %rax, %rax
je 0x384e
movsd 0x10(%rax), %xmm0
jmp 0x3bf3
movq 0x38(%rbx), %rsi
movq 0x38(%rbp), %r13
xorl %eax, %eax
leaq 0x90(%rsp), %r14
movq %rax, (%r14)
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %rsi, 0x38(%rsp)
movq %r14, %rdx
callq 0x6558
xorl %eax, %eax
movq %rax, (%r14)
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rdx
movq %rsp, %rcx
movq %r13, %rsi
callq 0x6558
leaq 0x20(%rbx), %rdi
leaq 0x20(%rbp), %r14
leaq 0xc0(%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)
movl 0x4d8(%r15), %eax
testl %eax, %eax
movq %r15, 0x18(%rsp)
movq %r14, 0x28(%rsp)
jle 0x3a37
movq %rdi, 0x30(%rsp)
movq %r13, 0x70(%rsp)
movq %r12, 0x78(%rsp)
xorl %edx, %edx
leaq 0x90(%rsp), %r14
movq %rsp, %r12
movq %rbp, 0x20(%rsp)
movq %rbx, 0x80(%rsp)
movq 0x8(%rbx), %rcx
movq %rdx, 0x88(%rsp)
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %r13
movq %rdx, 0x8(%rsp)
movq 0x8(%rcx,%rdx,8), %rcx
movq %rcx, 0x10(%rsp)
cmpq %rcx, %r13
je 0x398c
movq 0x8(%rbp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x8(%rax,%rcx,8), %rbx
cmpq %rbx, %rbp
je 0x3971
movl (%r13), %r15d
movl (%rbp), %eax
shlq $0x20, %rax
orq %r15, %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x8210
incl (%rax)
addq $0x4, %rbp
cmpq %rbx, %rbp
jne 0x394d
addq $0x4, %r13
cmpq 0x10(%rsp), %r13
movq 0x20(%rsp), %rbp
jne 0x3932
movq 0x18(%rsp), %rax
movl 0x4d8(%rax), %eax
movq 0x88(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
movq 0x80(%rsp), %rbx
jl 0x390a
movq 0xa0(%rsp), %rbx
testq %rbx, %rbx
movq 0x18(%rsp), %r15
movq 0x78(%rsp), %r12
movq 0x70(%rsp), %r13
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rdi
je 0x3a37
leaq 0x8(%rbx), %rsi
callq 0x8518
movl (%rax), %ebp
leaq 0xc(%rbx), %rsi
movq %r14, %rdi
callq 0x8518
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 0x58(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
movslq 0xc(%rbx), %rax
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
movq (%rbx), %rbx
testq %rbx, %rbx
jmp 0x39ca
movl $0x0, (%rsp)
movsd 0x65c2(%rip), %xmm1     # 0xa008
movapd %xmm1, %xmm2
cmpl $0x0, 0x38(%rsp)
jle 0x3add
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
movq %rsp, %rbx
xorl %eax, %eax
movsd %xmm2, 0x10(%rsp)
cltq
movq 0x58(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rdi, %r15
movq %rbx, %rsi
callq 0x8518
movl (%rax), %r14d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8518
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm2
addsd %xmm1, %xmm2
addl (%rax), %ebp
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x38(%rsp), %eax
movq %r15, %rdi
jl 0x3a60
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm2
movq 0x28(%rsp), %r14
movq 0x18(%rsp), %r15
movsd 0x652b(%rip), %xmm1     # 0xa008
movsd %xmm2, 0x10(%rsp)
movl $0x0, (%rsp)
testl %r13d, %r13d
jle 0x3b6c
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
movq %rsp, %rbx
xorl %eax, %eax
movsd %xmm1, 0x8(%rsp)
cltq
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8518
movq %r14, %r15
movl (%rax), %r14d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8518
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0x20(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm1
addsd %xmm2, %xmm1
addl (%rax), %ebp
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl %r13d, %eax
movq %r15, %r14
jl 0x3afa
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movq 0x18(%rsp), %r15
movsd %xmm1, 0x8(%rsp)
movq %rsp, %rsi
movq %r12, (%rsi)
movq %r15, %rdi
callq 0x87ae
movsd 0x6488(%rip), %xmm0     # 0xa010
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd 0x647e(%rip), %xmm2     # 0xa018
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm1, (%rax)
leaq 0x90(%rsp), %rdi
callq 0x73da
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3bd6
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3bed
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movsd 0x8(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c12
movq %rax, %rbx
jmp 0x3c39
jmp 0x3c12
jmp 0x3c12
jmp 0x3c12
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x73da
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3c39
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3c50
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x33e0