// File: minimind[P]simple-graph/unittest/../graph/graph.hpp
// Function: void add<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>(Graph<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>&, Graph<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const&, bool)
void add( Graph<N,E>& a, const Graph<N,E>& b, const bool keepSameKeys )
{
  const unsigned long keyAdd = keepSameKeys ? 0 : a.m_counter;

  // The problem here is that the keys might change. So we need to create new keys and hence new node iterators in the edges.
  // We do this by going through all the nodes and edges and adding a.m_counter to all the keys.
  for ( typename SimpleGraph::ConstNodeIterator<N,E> i = b.nodes.begin();
        i != b.nodes.end();
        ++i )
  {
    if ( a.nodes.m_nodes.find( i.key() + keyAdd ) != a.nodes.m_nodes.end() )
    {
      throw std::runtime_error( "Cannot add node as key already exists" );
    }

    a.nodes.m_nodes.insert( std::make_pair(
      i.key() + keyAdd,
      boost::shared_ptr< SimpleGraph::SimpleNode<N,E> >( new SimpleGraph::SimpleNode<N,E>( *i, i.key() + keyAdd ) ) ) );
  }

  // Now we copy the edges
  for ( typename SimpleGraph::ConstEdgeIterator<N,E> j = b.edges.begin();
        j != b.edges.end();
        ++j )
  {
    typename SimpleGraph::NodeIterator<N,E> left = a.nodes.find( j.left().key() + keyAdd );
    if ( left == a.nodes.end() )
    {
      throw std::runtime_error( "Cannot copy graph as cannot find left node" );
    }

    typename SimpleGraph::NodeIterator<N,E> right = a.nodes.find( j.right().key() + keyAdd );
    if ( right == a.nodes.end() )
    {
      throw std::runtime_error( "Cannot copy graph as cannot find right node" );
    }

    a.add_edge( *j, left, right );
  }

  if ( keepSameKeys )
  {
    if ( a.m_counter < b.m_counter )
    {
      a.m_counter = b.m_counter;
    }
  }
  else
  {
    a.m_counter += b.m_counter;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
je 0x54f2b
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
jmp 0x54f3a
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x575a0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x57600
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x575d0
testb $0x1, %al
jne 0x54f75
jmp 0x55184
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x57690
movq -0xe8(%rbp), %rdi
addq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x40(%rbp), %rsi
callq 0x57660
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x576b0
movq %rax, -0x48(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x57630
testb $0x1, %al
jne 0x54fc5
jmp 0x55021
movl $0x10, %edi
callq 0xb290
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xf0(%rbp)
leaq 0x255b0(%rip), %rsi     # 0x7a593
callq 0xb1c0
jmp 0x54fea
movq -0xf0(%rbp), %rdi
movq 0x57ff8(%rip), %rsi     # 0xacff0
movq 0x57fa1(%rip), %rdx     # 0xacfa0
callq 0xb8d0
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0xb400
jmp 0x553e6
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x57690
movq -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x40, %edi
callq 0xb530
movq -0x108(%rbp), %rdi
movq %rax, -0x100(%rbp)
callq 0x57720
movq %rax, -0xf8(%rbp)
jmp 0x5506d
leaq -0x28(%rbp), %rdi
callq 0x57690
movq %rax, -0x118(%rbp)
jmp 0x5507f
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rdi
movq -0x118(%rbp), %rdx
movq -0x20(%rbp), %rax
addq %rax, %rdx
callq 0x55a70
jmp 0x550a2
movq -0x100(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x55ab0
movq -0x120(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x576e0
jmp 0x550d2
movq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x559f0
movb %dl, -0x129(%rbp)
movq %rax, -0x128(%rbp)
jmp 0x550f1
movb -0x129(%rbp), %al
movq -0x128(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movb %al, -0x90(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x55b20
leaq -0x88(%rbp), %rdi
callq 0x55b40
leaq -0x28(%rbp), %rdi
callq 0x57750
jmp 0x54f52
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x40, %esi
callq 0xb550
jmp 0x553e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x55173
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x55b20
leaq -0x88(%rbp), %rdi
callq 0x55b40
jmp 0x553e6
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x57780
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x577e0
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x577b0
testb $0x1, %al
jne 0x551c8
jmp 0x5539f
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x57850
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x57690
movq -0x138(%rbp), %rdi
movq %rax, %rsi
addq -0x20(%rbp), %rsi
callq 0x57810
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x578c0
movq %rax, -0xc0(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x57890
testb $0x1, %al
jne 0x55235
jmp 0x55291
movl $0x10, %edi
callq 0xb290
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x140(%rbp)
leaq 0x25366(%rip), %rsi     # 0x7a5b9
callq 0xb1c0
jmp 0x5525a
movq -0x140(%rbp), %rdi
movq 0x57d88(%rip), %rsi     # 0xacff0
movq 0x57d31(%rip), %rdx     # 0xacfa0
callq 0xb8d0
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0xb400
jmp 0x553e6
movq -0x8(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x578f0
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x57690
movq -0x148(%rbp), %rdi
movq %rax, %rsi
addq -0x20(%rbp), %rsi
callq 0x57810
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x578c0
movq %rax, -0xd8(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x57890
testb $0x1, %al
jne 0x552fe
jmp 0x5535a
movl $0x10, %edi
callq 0xb290
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x150(%rbp)
leaq 0x252c8(%rip), %rsi     # 0x7a5e4
callq 0xb1c0
jmp 0x55323
movq -0x150(%rbp), %rdi
movq 0x57cbf(%rip), %rsi     # 0xacff0
movq 0x57c68(%rip), %rdx     # 0xacfa0
callq 0xb8d0
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0xb400
jmp 0x553e6
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x57930
movq -0x158(%rbp), %rdi
movq %rax, %rsi
leaq -0xb0(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0x54c90
leaq -0xa0(%rbp), %rdi
callq 0x57960
jmp 0x55198
testb $0x1, -0x11(%rbp)
je 0x553c9
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x553c7
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x553dd
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x8(%rbp), %rax
addq 0x48(%rax), %rcx
movq %rcx, 0x48(%rax)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xb920
nop