// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkstorage.cc
// Function: determine_edge_length(std::vector<MOLECULE, std::allocator<MOLECULE>>*, ATOM_NETWORK*, std::vector<MOLECULE, std::allocator<MOLECULE>>*, std::vector<CONNECTION, std::allocator<CONNECTION>>*)
double determine_edge_length(vector<MOLECULE> *molecules, ATOM_NETWORK *cell, vector<MOLECULE> *assembled_molecules, vector<CONNECTION> *two_way_connections) {
  bool verbose = false;
  int num_placed = 0;
  bool placed_ok = true;
  double sum_edge_lengths = 0;
  vector<bool> placed;
  int num_mols = molecules->size();
  for(int i=0; i<num_mols; i++) placed.push_back(false);
  vector<bool> connected;
  int num_cons = two_way_connections->size();
  for(int i=0; i<num_cons; i++) connected.push_back(false);
  for(int i=0; i<num_mols; i++) assembled_molecules->push_back(molecules->at(i)); //this vector starts out the same as the molecules vector, but the molecules are then each shifted into their relative positions to form the assembled_molecules
  while(num_placed<2 && placed_ok) {
    if(verbose) printf("DEBUG: num_placed = %d; placing...\n", num_placed);
    int new_num_placed = place_molecule(molecules, two_way_connections, cell, &placed, &connected, assembled_molecules, num_placed, &sum_edge_lengths);
    if(verbose) printf("DEBUG: after calling place_molecule, %d molecules have been placed\n", new_num_placed);
    if(new_num_placed==num_placed+1) {
      num_placed = new_num_placed;
    } else placed_ok = false;
  }
  if(!placed_ok || num_placed!=2) {
//    printf("ERROR: could not find a molecule which has not been placed and which is adjacent to an already placed molecule in order to connected two building blocks together to determine edge length - is the net valid?\n");
//    exit(EXIT_FAILURE);
if(verbose) printf("NOTICE: could not place any molecules - returning invalid distance\n");
    return -1;
  }
  return sum_edge_lengths;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, (%rsp)
andq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %rbp
andq $0x0, (%rbp)
movq %rdx, %r14
andl $0x0, 0x8(%rbp)
movq %rsi, 0x10(%rsp)
andq $0x0, 0x10(%rbp)
movq %rdi, %r12
andl $0x0, 0x18(%rbp)
andq $0x0, 0x20(%rbp)
movq 0x8(%rdi), %rax
subq (%rdi), %rax
movl $0xa8, %ecx
cqto
idivq %rcx
movq %rax, %r15
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movl %r15d, %ebx
subl $0x1, %ebx
jb 0x45bb1
movq %rbp, %rdi
xorl %esi, %esi
callq 0xa8f6
jmp 0x45ba0
leaq 0x18(%rsp), %rbp
andq $0x0, (%rbp)
andl $0x0, 0x8(%rbp)
andq $0x0, 0x10(%rbp)
andl $0x0, 0x18(%rbp)
andq $0x0, 0x20(%rbp)
movq (%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x1c
popq %rcx
cqto
idivq %rcx
movq %rax, %r13
xorl %eax, %eax
testl %r13d, %r13d
cmovlel %eax, %r13d
subl $0x1, %r13d
jb 0x45bfe
movq %rbp, %rdi
xorl %esi, %esi
callq 0xa8f6
jmp 0x45bec
movl %r15d, %ebx
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0x45c24
movq %r12, %rdi
movq %r13, %rsi
callq 0x4b9e8
movq %r14, %rdi
movq %rax, %rsi
callq 0x4bc3a
incq %r13
jmp 0x45c04
xorl %r15d, %r15d
movb $0x1, %cl
leaq 0x8(%rsp), %rbx
leaq 0x40(%rsp), %r13
leaq 0x18(%rsp), %rbp
cmpl $0x1, %r15d
jg 0x45c71
testb $0x1, %cl
je 0x45c71
movq %r12, %rdi
movq (%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r14, %r9
pushq %rbx
pushq %r15
callq 0x43809
popq %rcx
popq %rdx
leal 0x1(%r15), %ecx
cmpl %ecx, %eax
sete %cl
cmovel %eax, %r15d
jmp 0x45c38
movsd 0xba66f(%rip), %xmm0    # 0x1002e8
cmpl $0x2, %r15d
je 0x45c84
movaps %xmm0, %xmm1
jmp 0x45c8a
movsd 0x8(%rsp), %xmm1
testb $0x1, %cl
jne 0x45c92
movaps %xmm0, %xmm1
movsd %xmm1, (%rsp)
leaq 0x18(%rsp), %rdi
callq 0xa976
leaq 0x40(%rsp), %rdi
callq 0xa976
movsd (%rsp), %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x45cc8
jmp 0x45cc8
movq %rax, %rbx
jmp 0x45cd5
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa976
leaq 0x40(%rsp), %rdi
callq 0xa976
movq %rbx, %rdi
callq 0x4780