// File: /workspace/github_cpp_makefile_star2_O3/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, 0x8(%rsp)
movq %rbx, 0x38(%rsp)
movl %ebx, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movl %ebx, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x8(%rdi), %rbp
subq (%rdi), %rbp
sarq $0x3, %rbp
movabsq $-0x30c30c30c30c30c3, %rax # imm = 0xCF3CF3CF3CF3CF3D
imulq %rax, %rbp
testl %ebp, %ebp
jle 0x5e3dd
leaq 0x38(%rsp), %r15
movl %ebp, %r13d
movq %r15, %rdi
xorl %esi, %esi
callq 0xea58
decl %r13d
jne 0x5e3ce
movq %rbx, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movl %ebx, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq (%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x2, %rax
imull $0xb6db6db7, %eax, %ebx # imm = 0xB6DB6DB7
testl %ebx, %ebx
jle 0x5e420
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xea58
decl %ebx
jne 0x5e412
testl %ebp, %ebp
jle 0x5e470
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 0x5e518
addq %rbx, %rsi
movq %r14, %rdi
callq 0x67810
incq %r13
addq $0xa8, %rbx
cmpq %r13, %rbp
jne 0x5e42f
xorl %ebx, %ebx
leaq 0x10(%rsp), %r15
movq %r12, %rdi
movq (%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x38(%rsp), %rcx
movq %r15, %r8
movq %r14, %r9
leaq 0x8(%rsp), %rax
pushq %rax
pushq %rbx
callq 0x59f23
addq $0x10, %rsp
movl %eax, %ebp
leal 0x1(%rbx), %r13d
cmpl %r13d, %eax
cmovel %eax, %ebx
cmpl $0x1, %ebx
jg 0x5e4b4
cmpl %r13d, %ebp
je 0x5e477
movsd 0x8(%rsp), %xmm0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm0, (%rsp)
je 0x5e4db
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5e4f7
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd (%rsp), %xmm0
xorl %r13d, %ebp
xorl $0x2, %ebx
orl %ebp, %ebx
je 0x5e509
movsd 0xf2e57(%rip), %xmm0    # 0x151360
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xef1d6(%rip), %rdi     # 0x14d6f5
movq %r13, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5e534
jmp 0x5e534
jmp 0x5e534
movq %rax, %rbx
jmp 0x5e54e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5e54e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5e565
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780