// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x28(%rdi), %rax
cmpq 0x20(%rdi), %rax
jne 0x1d06
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x1ea6
movq %rbx, %rdi
callq 0x1700
leaq 0x70(%rbx), %rdi
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x1d20
movq %rax, 0x78(%rbx)
movl 0x50(%rbx), %esi
addl %esi, %esi
leaq 0xc(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
callq 0x2e16
leaq 0xa0(%rbx), %rdi
movq 0xa0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
je 0x1d53
movq %rax, 0xa8(%rbx)
movl 0x50(%rbx), %esi
incl %esi
callq 0x21c2
movl $0x0, 0x8(%rsp)
leaq 0x88(%rbx), %r14
movq 0x88(%rbx), %rsi
movq %r14, %rdi
callq 0x349c
movl 0x50(%rbx), %esi
movq %r14, %rdi
callq 0x21f4
movsd 0x227a(%rip), %xmm0     # 0x4008
cmpl $0x0, 0x50(%rbx)
je 0x1e8e
movq 0x58(%rbx), %rax
xorpd %xmm1, %xmm1
xorl %r12d, %r12d
leaq 0x8(%rsp), %r15
movl %r12d, %r13d
movq %r13, %rdx
shlq $0x4, %rdx
movsd 0x8(%rax,%rdx), %xmm0
ucomisd %xmm1, %xmm0
movsd %xmm1, (%rsp)
jne 0x1e2f
jp 0x1e2f
addq %rax, %rdx
movq 0x60(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %r13, %rcx
jbe 0x1e2f
movslq (%rdx), %rcx
movq (%r14), %rsi
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rdi
addq $0x4, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1e02
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x1e10
callq 0x3698
movsd (%rsp), %xmm1
movq 0x58(%rbx), %rax
incl %r12d
movq %r12, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movsd 0x8(%rax,%rcx), %xmm0
ucomisd %xmm1, %xmm0
movq %r12, %r13
jne 0x1e2f
jnp 0x1dc8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c5e
movl 0x8(%rsp), %ecx
movl 0x50(%rbx), %edx
cmpl %edx, %ecx
je 0x1e93
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rsi
subq %rax, %rsi
sarq $0x4, %rsi
cmpq %r13, %rsi
je 0x1e6e
shlq $0x4, %r13
movsd 0x8(%rax,%r13), %xmm1
cmpl %edx, %ecx
jb 0x1da8
jmp 0x1e86
movq 0x5163(%rip), %rdi      # 0x6fd8
leaq 0x2233(%rip), %rsi      # 0x40af
movl $0x3b, %edx
callq 0x1130
movsd 0x217a(%rip), %xmm0     # 0x4008
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorps %xmm0, %xmm0
jmp 0x1e98
nop