// File: /workspace/github_cpp_makefile_star2_O1/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 $0x20, %rsp
movq %rdi, %rbx
movq 0x28(%rdi), %rax
cmpq 0x20(%rdi), %rax
jne 0x1d2c
movq 0x40(%rbx), %rax
cmpq 0x38(%rbx), %rax
je 0x1ed6
movq %rbx, %rdi
callq 0x1716
leaq 0x70(%rbx), %rdi
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x1d46
movq %rax, 0x78(%rbx)
movl 0x50(%rbx), %esi
addl %esi, %esi
leaq 0x1c(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
callq 0x2e3a
leaq 0xa0(%rbx), %rdi
movq 0xa0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
je 0x1d79
movq %rax, 0xa8(%rbx)
movl 0x50(%rbx), %esi
incl %esi
callq 0x21de
movl $0x0, 0xc(%rsp)
leaq 0x88(%rbx), %r14
movq 0x88(%rbx), %rsi
movq %r14, %rdi
callq 0x30f4
movl 0x50(%rbx), %esi
movq %r14, %rdi
callq 0x2210
movl 0xc(%rsp), %eax
movsd 0x2250(%rip), %xmm0     # 0x4008
cmpl 0x50(%rbx), %eax
jae 0x1ebc
xorpd %xmm1, %xmm1
xorl %r12d, %r12d
leaq 0xc(%rsp), %r15
movl %r12d, %r13d
movq 0x58(%rbx), %rax
movq %r13, %rdx
shlq $0x4, %rdx
movsd 0x8(%rax,%rdx), %xmm0
ucomisd %xmm1, %xmm0
movsd %xmm1, 0x10(%rsp)
jne 0x1e5a
jp 0x1e5a
addq %rax, %rdx
movq 0x60(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %r13, %rcx
jbe 0x1e5a
movslq (%rdx), %rax
movq (%r14), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
addq $0x4, %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1e2c
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x1e37
callq 0x32f8
movsd 0x10(%rsp), %xmm1
incl %r12d
movq 0x58(%rbx), %rax
movq %r12, %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movsd 0x8(%rax,%rcx), %xmm0
ucomisd %xmm1, %xmm0
movq %r12, %r13
jne 0x1e5a
jnp 0x1df2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c84
movl 0xc(%rsp), %eax
cmpl 0x50(%rbx), %eax
je 0x1ec2
movq 0x58(%rbx), %rax
movq 0x60(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %r13, %rcx
je 0x1e9c
shlq $0x4, %r13
movsd 0x8(%rax,%r13), %xmm1
movl 0xc(%rsp), %eax
cmpl 0x50(%rbx), %eax
jb 0x1dcd
jmp 0x1eb4
movq 0x5135(%rip), %rdi      # 0x6fd8
leaq 0x21d5(%rip), %rsi      # 0x407f
movl $0x3b, %edx
callq 0x1130
movsd 0x214c(%rip), %xmm0     # 0x4008
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorps %xmm0, %xmm0
jmp 0x1ec8
nop