// File: Luthaf[P]zeopp/networkstorage.cc
// Function: find_two_way_connections(ATOM_NETWORK*, std::vector<CONNECTION, std::allocator<CONNECTION>>*)
bool find_two_way_connections(ATOM_NETWORK *cell, vector<CONNECTION> *two_way_connections) {
  bool verbose = false;
  //1) for each VERTEX in the ATOM_NETWORK, look at the edge positions and find which VERTEX it overlaps with periodically - it might be itself!
  vector<CONNECTION> connections;
  int num_v = cell->vertices.size();
  if(verbose) printf("DEBUG: num_v = %d\n", num_v);
  for(int i=0; i<num_v; i++) {
    VERTEX vert = cell->vertices.at(i);
    int num_e = vert.edges.size();
    if(verbose) printf("DEBUG: num_e = %d\n", num_e);
    for(int j=0; j<num_e; j++) {
      XYZ e = vert.edges.at(j);
      int overlap_v_index = -1;
      for(int k=0; k<num_v && overlap_v_index==-1; k++) {
        XYZ v = cell->vertices.at(k).abc;
if(verbose) printf("DEBUG: checking for overlap between edge end position %.3f %.3f %.3f and other vertex position %.3f %.3f %.3f\n", e.x, e.y, e.z, v.x, v.y, v.z);
        if(overlaps_abc(e, v, cell))
          overlap_v_index = k;
      }
      if(overlap_v_index==-1) {
        printf("ERROR: could not construct net: no vertex could be found which overlaps periodically with vertex %d edge %d - check cgd file (did you forget the \":H\" in the symmetry group?)\n", i, j);
        exit(EXIT_FAILURE);
      } else {
        XYZ v = cell->vertices.at(overlap_v_index).abc;
        XYZ shift = e-v;
        int a_shift = (int)(round(shift.x));
        int b_shift = (int)(round(shift.y));
        int c_shift = (int)(round(shift.z));
        if(verbose) printf("DEBUG: vertex %d edge %d at %.3f %.3f %.3f overlaps with vertex %d at %.3f %.3f %.3f with periodicity (%d %d %d)\n", i, j, e.x, e.y, e.z, overlap_v_index, cell->vertices.at(overlap_v_index).abc.x, cell->vertices.at(overlap_v_index).abc.y, cell->vertices.at(overlap_v_index).abc.z, a_shift, b_shift, c_shift);
        CONNECTION c(i, overlap_v_index, j, a_shift, b_shift, c_shift);
        connections.push_back(c);
      }
    }
  }
  int num_connections = connections.size();
  if(verbose) printf("DEBUG: there are %d one-way connections\n", num_connections);
  if(num_connections%2!=0) {
    printf("ERROR: there are an odd number (%d) of one-way connections between vertices - this should not be the case because connections are expressed redundantly\n", num_connections);
    exit(EXIT_FAILURE);
  }
  //2) connections only go one way right now - we cannot yet position molecules because we need to know which edge is used in each VERTEX!
  vector<bool> considered;
  for(int i=0; i<num_connections; i++) considered.push_back(false);
  for(int i=0; i<num_connections; i++) {
    if(!considered.at(i)) { //we are looking at one-way connections - if we have not yet found a match between this connection and another, try and find one
      bool matched = false;
      CONNECTION ci = connections.at(i);
      for(int j=0; j<num_connections; j++) { //we continue searching for matches even after finding one - because we want to handle the error case where edges are declared ambiguously (would be caused by invalid cgd net)
        if(!considered.at(j)) {
          CONNECTION cj = connections.at(j);
          if(matches(ci,cj)) {
            if(matched) {
              printf("ERROR: determined that vertex %d edge %d overlaps with more than one vertex!\n", ci.v1, ci.e1);
              exit(EXIT_FAILURE);
            }
            CONNECTION cij = ci;
            cij.e2 = cj.e1;
            if(verbose) printf("DEBUG: vertex %d edge %d overlaps with vertex %d edge %d with periodicity (%d %d %d)\n", cij.v1, cij.e1, cij.v2, cij.e2, cij.a, cij.b, cij.c);
            two_way_connections->push_back(cij);
            considered.at(i) = true;
            considered.at(j) = true;
            matched = true;
          }
        }
      }
      if(!matched) {
        printf("ERROR: could not find corresponding connection for vertex %d edge %d overlapping with vertex %d\n", ci.v1, ci.e1, ci.v2);
        exit(EXIT_FAILURE);
      }
    }
  }
  int num_two_way_connections = two_way_connections->size();
  if(verbose) printf("DEBUG: there are %d two-way connections\n", num_two_way_connections);
  //3) now we know all the two-way connections, we can recursively traverse until we establish whether the net is disconnected - we need to know this in order to avoid trying the connection-based assembly method later, only to find that it fails
  vector<bool> visited_vertex;
  for(int i=0; i<num_v; i++) visited_vertex.push_back(false);
  recursive_visit_vertices(0, two_way_connections, &visited_vertex);
  bool is_disconnected = false;
  for(int i=0; i<num_v && !is_disconnected; i++) {
    if(!visited_vertex.at(i)) is_disconnected = true;
  }
  return is_disconnected;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xaf4c0
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
callq 0xae470
movl %eax, -0x34(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa122f
movl -0x34(%rbp), %esi
leaq 0x157800(%rip), %rdi    # 0x1f8a13
xorl %eax, %eax
callq 0x5070
jmp 0xa121c
jmp 0xa122f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa1d4a
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa1730
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0x48(%rbp), %rsi
callq 0xae4a0
movq %rax, -0x308(%rbp)
jmp 0xa125f
movq -0x308(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0xae4e0
jmp 0xa1274
leaq -0xb8(%rbp), %rdi
addq $0x20, %rdi
callq 0xae590
movl %eax, -0xbc(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa12c5
movl -0xbc(%rbp), %esi
leaq 0x157789(%rip), %rdi    # 0x1f8a26
xorl %eax, %eax
callq 0x5070
jmp 0xa12a6
jmp 0xa12c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x12650
jmp 0xa1d4a
movl $0x0, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0xa1716
leaq -0x98(%rbp), %rdi
movslq -0xc0(%rbp), %rsi
callq 0xae5c0
movq %rax, -0x310(%rbp)
jmp 0xa12fd
movq -0x310(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xd8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xc8(%rbp)
movl $0xffffffff, -0xdc(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xe0(%rbp)
movl -0xe0(%rbp), %ecx
xorl %eax, %eax
cmpl -0x34(%rbp), %ecx
movb %al, -0x311(%rbp)
jge 0xa135b
cmpl $-0x1, -0xdc(%rbp)
sete %al
movb %al, -0x311(%rbp)
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0xa136a
jmp 0xa149e
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0xe0(%rbp), %rsi
callq 0xae4a0
movq %rax, -0x320(%rbp)
jmp 0xa138a
movq -0x320(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xf8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xf0(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xe8(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa13f9
movsd -0xd8(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movsd -0xc8(%rbp), %xmm2
movsd -0xf8(%rbp), %xmm3
movsd -0xf0(%rbp), %xmm4
movsd -0xe8(%rbp), %xmm5
leaq 0x15764b(%rip), %rdi    # 0x1f8a39
movb $0x6, %al
callq 0x5070
jmp 0xa13f7
jmp 0xa13f9
movq -0xc8(%rbp), %rax
movq %rax, -0x100(%rbp)
movups -0xd8(%rbp), %xmm0
movaps %xmm0, -0x110(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x120(%rbp)
movups -0xf8(%rbp), %xmm0
movaps %xmm0, -0x130(%rbp)
movq -0x8(%rbp), %rdi
movq -0x120(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x28(%rax)
movaps -0x130(%rbp), %xmm0
movups %xmm0, 0x18(%rax)
movq -0x100(%rbp), %rcx
movq %rcx, 0x10(%rax)
movaps -0x110(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x9f840
movb %al, -0x321(%rbp)
jmp 0xa1470
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0xa147c
jmp 0xa1488
movl -0xe0(%rbp), %eax
movl %eax, -0xdc(%rbp)
jmp 0xa148a
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0xa1338
cmpl $-0x1, -0xdc(%rbp)
jne 0xa14ca
movl -0x48(%rbp), %esi
movl -0xc0(%rbp), %edx
leaq 0x1575f1(%rip), %rdi    # 0x1f8aa8
xorl %eax, %eax
callq 0x5070
jmp 0xa14c0
movl $0x1, %edi
callq 0x67c0
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0xdc(%rbp), %rsi
callq 0xae4a0
movq %rax, -0x330(%rbp)
jmp 0xa14ea
movq -0x330(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x140(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x150(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0xeadf0
jmp 0xa1522
movsd -0x168(%rbp), %xmm0
callq 0x5210
cvttsd2si %xmm0, %eax
movl %eax, -0x16c(%rbp)
movsd -0x160(%rbp), %xmm0
callq 0x5210
cvttsd2si %xmm0, %eax
movl %eax, -0x170(%rbp)
movsd -0x158(%rbp), %xmm0
callq 0x5210
cvttsd2si %xmm0, %eax
movl %eax, -0x174(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa16b6
movl -0x48(%rbp), %eax
movl %eax, -0x360(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0x35c(%rbp)
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x358(%rbp)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x350(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0x348(%rbp)
movl -0xdc(%rbp), %eax
movl %eax, -0x33c(%rbp)
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq %eax, %rsi
callq 0xae4a0
movq %rax, -0x338(%rbp)
jmp 0xa15de
movq -0x338(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x370(%rbp)
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0xdc(%rbp), %rsi
callq 0xae4a0
movq %rax, -0x368(%rbp)
jmp 0xa1611
movq -0x368(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x380(%rbp)
movq -0x8(%rbp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movslq -0xdc(%rbp), %rsi
callq 0xae4a0
movq %rax, -0x378(%rbp)
jmp 0xa1645
movsd -0x380(%rbp), %xmm4
movsd -0x370(%rbp), %xmm3
movl -0x33c(%rbp), %ecx
movsd -0x348(%rbp), %xmm2
movsd -0x350(%rbp), %xmm1
movsd -0x358(%rbp), %xmm0
movl -0x35c(%rbp), %edx
movl -0x360(%rbp), %esi
movq -0x378(%rbp), %rax
movsd 0x10(%rax), %xmm5
movl -0x16c(%rbp), %r8d
movl -0x170(%rbp), %r9d
movl -0x174(%rbp), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x1574ac(%rip), %rdi    # 0x1f8b57
movb $0x6, %al
callq 0x5070
jmp 0xa16b4
jmp 0xa16b6
movl -0x48(%rbp), %esi
movl -0xdc(%rbp), %edx
movl -0xc0(%rbp), %ecx
movl -0x16c(%rbp), %r8d
movl -0x170(%rbp), %r9d
movl -0x174(%rbp), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq -0x190(%rbp), %rdi
callq 0x110a00
jmp 0xa16ec
leaq -0x30(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0xaf4e0
jmp 0xa16fe
jmp 0xa1700
jmp 0xa1702
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0xa12cf
leaq -0xb8(%rbp), %rdi
callq 0x12650
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa1236
leaq -0x30(%rbp), %rdi
callq 0xaf420
movl %eax, -0x194(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa175d
movl -0x194(%rbp), %esi
leaq 0x157477(%rip), %rdi    # 0x1f8bc9
xorl %eax, %eax
callq 0x5070
jmp 0xa175b
jmp 0xa175d
movl -0x194(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xa1790
movl -0x194(%rbp), %esi
leaq 0x157475(%rip), %rdi    # 0x1f8bf2
xorl %eax, %eax
callq 0x5070
jmp 0xa1786
movl $0x1, %edi
callq 0x67c0
leaq -0x1c0(%rbp), %rdi
callq 0xf670
movl $0x0, -0x1c4(%rbp)
movl -0x1c4(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0xa17e8
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
callq 0xf700
jmp 0xa17c4
jmp 0xa17c6
movl -0x1c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4(%rbp)
jmp 0xa17a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa1d3e
movl $0x0, -0x1c8(%rbp)
movl -0x1c8(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0xa1bb0
movslq -0x1c8(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x390(%rbp)
movq %rax, -0x388(%rbp)
jmp 0xa1827
movq -0x390(%rbp), %rax
movq -0x388(%rbp), %rcx
movq %rcx, -0x1d8(%rbp)
movq %rax, -0x1d0(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x101a0
xorb $-0x1, %al
testb $0x1, %al
jne 0xa185a
jmp 0xa1b9a
movb $0x0, -0x1d9(%rbp)
movslq -0x1c8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xaf0e0
movq %rax, -0x398(%rbp)
jmp 0xa187a
movq -0x398(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x1f8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x1f0(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x1e8(%rbp)
movl 0x18(%rax), %eax
movl %eax, -0x1e0(%rbp)
movl $0x0, -0x1fc(%rbp)
movl -0x1fc(%rbp), %eax
cmpl -0x194(%rbp), %eax
jge 0xa1b63
movslq -0x1fc(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x3a8(%rbp)
movq %rax, -0x3a0(%rbp)
jmp 0xa18e9
movq -0x3a8(%rbp), %rax
movq -0x3a0(%rbp), %rcx
movq %rcx, -0x210(%rbp)
movq %rax, -0x208(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x101a0
xorb $-0x1, %al
testb $0x1, %al
jne 0xa191c
jmp 0xa1b4d
movslq -0x1fc(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xaf0e0
movq %rax, -0x3b0(%rbp)
jmp 0xa1935
movq -0x3b0(%rbp), %rax
movups (%rax), %xmm0
movups 0xc(%rax), %xmm1
movups %xmm1, -0x224(%rbp)
movaps %xmm0, -0x230(%rbp)
movups -0x1f8(%rbp), %xmm0
movups -0x1ec(%rbp), %xmm1
movups %xmm1, -0x244(%rbp)
movaps %xmm0, -0x250(%rbp)
movups -0x224(%rbp), %xmm0
movups %xmm0, -0x264(%rbp)
movaps -0x230(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
movups -0x264(%rbp), %xmm0
movq %rsp, %rax
movups %xmm0, 0x2c(%rax)
movaps -0x270(%rbp), %xmm0
movups %xmm0, 0x20(%rax)
movups -0x244(%rbp), %xmm0
movups %xmm0, 0xc(%rax)
movaps -0x250(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x110d50
movb %al, -0x3b1(%rbp)
jmp 0xa19c4
movb -0x3b1(%rbp), %al
testb $0x1, %al
jne 0xa19d3
jmp 0xa1b4b
testb $0x1, -0x1d9(%rbp)
je 0xa1a02
movl -0x1f8(%rbp), %esi
movl -0x1f0(%rbp), %edx
leaq 0x15729c(%rip), %rdi    # 0x1f8c8b
xorl %eax, %eax
callq 0x5070
jmp 0xa19f8
movl $0x1, %edi
callq 0x67c0
movq -0x1f8(%rbp), %rax
movq %rax, -0x28c(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x284(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x27c(%rbp)
movl -0x1e0(%rbp), %eax
movl %eax, -0x274(%rbp)
movl -0x228(%rbp), %eax
movl %eax, -0x280(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa1a92
movl -0x284(%rbp), %edx
movl -0x28c(%rbp), %esi
movl -0x288(%rbp), %ecx
movl -0x280(%rbp), %r8d
movl -0x27c(%rbp), %r9d
movl -0x278(%rbp), %edi
movl -0x274(%rbp), %r10d
movq %rsp, %rax
movl %r10d, 0x8(%rax)
movl %edi, (%rax)
leaq 0x157252(%rip), %rdi    # 0x1f8cd9
xorl %eax, %eax
callq 0x5070
jmp 0xa1a90
jmp 0xa1a92
movq -0x10(%rbp), %rdi
leaq -0x28c(%rbp), %rsi
callq 0xaf4e0
jmp 0xa1aa4
movslq -0x1c8(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x3c8(%rbp)
movq %rax, -0x3c0(%rbp)
jmp 0xa1ac7
movq -0x3c8(%rbp), %rax
movq -0x3c0(%rbp), %rcx
movq %rcx, -0x2a0(%rbp)
movq %rax, -0x298(%rbp)
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movslq -0x1fc(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x3d8(%rbp)
movq %rax, -0x3d0(%rbp)
jmp 0xa1b17
movq -0x3d8(%rbp), %rax
movq -0x3d0(%rbp), %rcx
movq %rcx, -0x2b0(%rbp)
movq %rax, -0x2a8(%rbp)
leaq -0x2b0(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movb $0x1, -0x1d9(%rbp)
jmp 0xa1b4d
jmp 0xa1b4f
movl -0x1fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1fc(%rbp)
jmp 0xa18b4
testb $0x1, -0x1d9(%rbp)
jne 0xa1b98
movl -0x1f0(%rbp), %edx
movl -0x1f8(%rbp), %esi
movl -0x1f4(%rbp), %ecx
leaq 0x1571aa(%rip), %rdi    # 0x1f8d2f
xorl %eax, %eax
callq 0x5070
jmp 0xa1b8e
movl $0x1, %edi
callq 0x67c0
jmp 0xa1b9a
jmp 0xa1b9c
movl -0x1c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c8(%rbp)
jmp 0xa17f2
movq -0x10(%rbp), %rdi
callq 0xaf420
movl %eax, -0x2b4(%rbp)
testb $0x1, -0x11(%rbp)
je 0xa1bdd
movl -0x2b4(%rbp), %esi
leaq 0x1571be(%rip), %rdi    # 0x1f8d90
xorl %eax, %eax
callq 0x5070
jmp 0xa1bdb
jmp 0xa1bdd
leaq -0x2e0(%rbp), %rdi
callq 0xf670
movl $0x0, -0x2e4(%rbp)
movl -0x2e4(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xa1c3e
leaq -0x2e0(%rbp), %rdi
xorl %esi, %esi
callq 0xf700
jmp 0xa1c0e
jmp 0xa1c10
movl -0x2e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e4(%rbp)
jmp 0xa1bf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0xf9b0
jmp 0xa1d3e
movq -0x10(%rbp), %rsi
xorl %edi, %edi
leaq -0x2e0(%rbp), %rdx
callq 0x111ea0
jmp 0xa1c52
movb $0x0, -0x2e5(%rbp)
movl $0x0, -0x2ec(%rbp)
movl -0x2ec(%rbp), %ecx
xorl %eax, %eax
cmpl -0x34(%rbp), %ecx
movb %al, -0x3d9(%rbp)
jge 0xa1c84
movb -0x2e5(%rbp), %al
xorb $-0x1, %al
movb %al, -0x3d9(%rbp)
movb -0x3d9(%rbp), %al
testb $0x1, %al
jne 0xa1c90
jmp 0xa1d00
movslq -0x2ec(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x3f0(%rbp)
movq %rax, -0x3e8(%rbp)
jmp 0xa1cb3
movq -0x3f0(%rbp), %rax
movq -0x3e8(%rbp), %rcx
movq %rcx, -0x300(%rbp)
movq %rax, -0x2f8(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x101a0
xorb $-0x1, %al
testb $0x1, %al
jne 0xa1ce3
jmp 0xa1cea
movb $0x1, -0x2e5(%rbp)
jmp 0xa1cec
movl -0x2ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ec(%rbp)
jmp 0xa1c63
movb -0x2e5(%rbp), %al
movb %al, -0x3f1(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0xf9b0
leaq -0x1c0(%rbp), %rdi
callq 0xf9b0
leaq -0x30(%rbp), %rdi
callq 0xaf550
movb -0x3f1(%rbp), %al
andb $0x1, %al
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
leaq -0x1c0(%rbp), %rdi
callq 0xf9b0
leaq -0x30(%rbp), %rdi
callq 0xaf550
movq -0x40(%rbp), %rdi
callq 0x58f0
nopl (%rax)