// File: /workspace/github_cpp_makefile_star2_O1/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)
movq %rdx, %r14
movq %rsi, 0x60(%rsp)
movq %rdi, %r12
xorl %ebx, %ebx
movq %rbx, 0x58(%rsp)
movq %rbx, 0x30(%rsp)
movl %ebx, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
movl %ebx, 0x48(%rsp)
movq %rbx, 0x50(%rsp)
movq 0x8(%rdi), %rbp
subq (%rdi), %rbp
sarq $0x3, %rbp
movabsq $-0x30c30c30c30c30c3, %rax # imm = 0xCF3CF3CF3CF3CF3D
imulq %rax, %rbp
testl %ebp, %ebp
jle 0x5e9a0
leaq 0x30(%rsp), %r13
movl %ebp, %r15d
movq %r13, %rdi
xorl %esi, %esi
callq 0xe9e6
decl %r15d
jne 0x5e991
movq %rbx, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movl %ebx, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq (%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x2, %rax
imull $0xb6db6db7, %eax, %ebx # imm = 0xB6DB6DB7
testl %ebx, %ebx
jle 0x5e9e3
leaq 0x8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0xe9e6
decl %ebx
jne 0x5e9d5
testl %ebp, %ebp
jle 0x5ea33
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %ebx, %ebx
xorl %r13d, %r13d
movq (%r12), %rsi
movq 0x8(%r12), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x30c30c30c30c30c3, %rax # imm = 0xCF3CF3CF3CF3CF3D
imulq %rax, %rdx
cmpq %r13, %rdx
jbe 0x5eb25
addq %rbx, %rsi
movq %r14, %rdi
callq 0x68142
incq %r13
addq $0xa8, %rbx
cmpq %r13, %rbp
jne 0x5e9f2
movb $0x1, %bl
leaq 0x30(%rsp), %r13
leaq 0x8(%rsp), %rbp
xorl %r15d, %r15d
movq %r12, %rdi
movq (%rsp), %rsi
movq 0x60(%rsp), %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r14, %r9
leaq 0x58(%rsp), %rax
pushq %rax
pushq %r15
callq 0x5a3e0
addq $0x10, %rsp
leal 0x1(%r15), %ecx
cmpl %ecx, %eax
movzbl %bl, %ebx
movl $0x0, %ecx
cmovnel %ecx, %ebx
cmovel %eax, %r15d
cmpl $0x1, %r15d
jg 0x5ea88
testb $0x1, %bl
jne 0x5ea42
movsd 0x58(%rsp), %xmm0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm0, (%rsp)
je 0x5eac8
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x5eafd
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl %eax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movsd 0xf47cb(%rip), %xmm1    # 0x1532d0
testb $0x1, %bl
jne 0x5eb0d
movaps %xmm1, %xmm0
cmpl $0x2, %r15d
je 0x5eb16
movaps %xmm1, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf0b79(%rip), %rdi     # 0x14f6a5
movq %r13, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5eb41
jmp 0x5eb41
jmp 0x5eb41
movq %rax, %rbx
jmp 0x5eb74
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5eb74
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x5eba4
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movl %eax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq %rbx, %rdi
callq 0x4780