// File: /workspace/github_cpp_makefile_star2_O2/kelvinabrokwa[P]bottleneck/./CBottleneckDistance.cpp
// Function: CBottleneckDistance::Distance(double)
double CBottleneckDistance::Distance(double maxLevel)
{
    // If both diagrams are empty the distance is 0
    if (Generators1.size() == 0 &&  Generators2.size() == 0)
        return 0;

    PrepareEdges();

    // Clear the pairing
    Pair.clear();
    Pair.assign(2 * Max_Size, -1);

    // Clearing Layers
    Layers.clear();
    Layers.resize(Max_Size + 1);

    // No vertices are matched
    unsigned int matching = 0;

    // Clear the connection matrix and set it to the right size
    Connections.clear();
    Connections.resize(Max_Size);

    // The maximal weight of the edges which are used for the matching
    double current_weight = 0;

    // First non added edge is an iterator pointing to the first edge
    // in Edges which was added to the Connections */
    unsigned int first_not_added_edge = 0;

    // Repeat till all the vertices are matched
    while(matching < Max_Size) {

        // Add the edges with the current weight (distance) to the connection matrix
        while (Edges[first_not_added_edge].weight == current_weight && first_not_added_edge < Edges.size()) {
            // Add the edge to Connections
            Connections[Edges[first_not_added_edge].vertex_1].push_back(Edges[first_not_added_edge].vertex_2);
            ++first_not_added_edge;
        }

        // Do matching
        Hopcroft_Karp(matching);
        if (matching == Max_Size)
            return current_weight;

        // Check if we did not run out of edges. This should never happen.
        if (first_not_added_edge == Edges.size()) {
            std::cout << "Serious problem - Not enough eddges to find the matching! \n";
            return -1;
        }

        // Increase the value of the current weight
        current_weight = Edges[ first_not_added_edge ].weight;
    }

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x28(%rdi), %rax
cmpq 0x20(%rdi), %rax
jne 0x197b
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x1ac6
movq %rbx, %rdi
callq 0x154c
leaq 0x70(%rbx), %rdi
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x1995
movq %rax, 0x78(%rbx)
movl 0x50(%rbx), %esi
addl %esi, %esi
leaq 0x14(%rsp), %rdx
orl $-0x1, (%rdx)
callq 0x2c44
leaq 0xa0(%rbx), %rdi
movq 0xa0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
je 0x19c5
movq %rax, 0xa8(%rbx)
movl 0x50(%rbx), %esi
incl %esi
callq 0x1d32
leaq 0x10(%rsp), %r14
andl $0x0, (%r14)
leaq 0x88(%rbx), %r15
movq %r15, %rdi
callq 0x1d64
movl 0x50(%rbx), %esi
movq %r15, %rdi
callq 0x1d6c
movl 0x50(%rbx), %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ecx, %ecx
xorl %ebp, %ebp
cmpl %eax, %ecx
jae 0x1aa3
movl %ebp, %r13d
movq 0x58(%rbx), %rsi
movq %r13, %r12
shlq $0x4, %r12
movsd 0x8(%rsi,%r12), %xmm0
ucomisd 0x8(%rsp), %xmm0
jne 0x1a54
jp 0x1a54
movq 0x60(%rbx), %rax
subq %rsi, %rax
sarq $0x4, %rax
cmpq %r13, %rax
jbe 0x1a54
addq %r12, %rsi
movslq (%rsi), %rax
imulq $0x18, %rax, %rdi
addq (%r15), %rdi
addq $0x4, %rsi
callq 0x1da2
incl %ebp
jmp 0x1a0b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18da
movl 0x10(%rsp), %ecx
movl 0x50(%rbx), %eax
cmpl %eax, %ecx
je 0x1ab1
movq 0x58(%rbx), %rdx
movq 0x60(%rbx), %rsi
subq %rdx, %rsi
sarq $0x4, %rsi
cmpq %r13, %rsi
je 0x1a90
movsd 0x8(%rdx,%r12), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x1a03
movq 0x5541(%rip), %rdi      # 0x6fd8
leaq 0x25e1(%rip), %rsi      # 0x407f
callq 0x10d0
movsd 0x255d(%rip), %xmm0     # 0x4008
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
jmp 0x1aab