// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: build_framework(std::vector<MOLECULE, std::allocator<MOLECULE>>*, ATOM_NETWORK*, std::vector<MOLECULE, std::allocator<MOLECULE>>*, double, double)
ATOM_NETWORK build_framework(vector<MOLECULE> *molecules, ATOM_NETWORK *cell, vector<MOLECULE> *assembled_molecules, double mean_edge_length, double unit_edge_length) {
  //1) set up the unit cell based on the underlying cell and the calculated edge length as a scaling factor
  ATOM_NETWORK alt_framework;
  alt_framework.make(mean_edge_length*cell->a/unit_edge_length, mean_edge_length*cell->b/unit_edge_length, mean_edge_length*cell->c/unit_edge_length, cell->alpha, cell->beta, cell->gamma);
  //2) for each vertex fractional position in the underlying cell, put the appropriate oriented molecule at the corresponding fractional position in the new cell, using the centre of mass of the molecule
  int num_mols = molecules->size();
  int num_vertices = cell->vertices.size();
  if(num_mols!=num_vertices) {
    printf("ERROR: the number of oriented molecules (%d) is not equal to the number of vertices in the underlying cell (%d)\n", num_mols, num_vertices);
  }
  for(int i=0; i<num_mols; i++) {
    XYZ abc = cell->vertices.at(i).abc;
    XYZ new_xyz = alt_framework.abc_to_xyz_returning_XYZ(abc);
    MOLECULE old_m = molecules->at(i);
    XYZ shift = new_xyz - old_m.com;
    assembled_molecules->push_back(translate(old_m, shift));
  }
  //3) put atoms into the cell, converting to fractional coords
  put_atoms_in_atom_network(&alt_framework, assembled_molecules);
  return alt_framework;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movaps %xmm1, 0x20(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0x5112c
movsd 0x18(%r15), %xmm0
movapd 0x40(%rsp), %xmm3
mulsd %xmm3, %xmm0
movapd 0x20(%rsp), %xmm4
divsd %xmm4, %xmm0
movsd 0x30(%r15), %xmm1
movupd 0x8(%r15), %xmm2
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm2, %xmm3
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
divpd %xmm4, %xmm3
movupd %xmm3, 0x8(%r14)
movsd %xmm0, 0x18(%r14)
movups 0x20(%r15), %xmm0
movups %xmm0, 0x20(%r14)
movsd %xmm1, 0x30(%r14)
movq %r14, %rdi
callq 0x51db4
movq %r14, 0x20(%rsp)
movq 0x8(%rbx), %r12
movq %rbx, 0x58(%rsp)
subq (%rbx), %r12
sarq $0x3, %r12
movabsq $-0x30c30c30c30c30c3, %rcx # imm = 0xCF3CF3CF3CF3CF3D
movq 0x3c8(%r15), %rax
movq %r15, 0x40(%rsp)
subq 0x3c0(%r15), %rax
imulq %rcx, %r12
shrq $0x4, %rax
imull $0xb6db6db7, %eax, %edx # imm = 0xB6DB6DB7
cmpl %edx, %r12d
je 0x5e003
leaq 0xf5543(%rip), %rdi     # 0x15353c
movl %r12d, %esi
xorl %eax, %eax
callq 0x4060
testl %r12d, %r12d
jle 0x5e2cb
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x10, %r14d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x40(%rsp), %rcx
movq 0x3c0(%rcx), %rax
movq 0x3c8(%rcx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x5e303
movsd -0x10(%rax,%r14), %xmm0
movsd -0x8(%rax,%r14), %xmm1
movsd (%rax,%r14), %xmm2
leaq 0x120(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x52dd8
movq 0x58(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
movabsq $-0x30c30c30c30c30c3, %rax # imm = 0xCF3CF3CF3CF3CF3D
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x5e2f2
addq %rbx, %rsi
leaq 0x78(%rsp), %rdi
callq 0x67616
leaq 0x60(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x8461e
leaq 0x138(%rsp), %r13
movq %r13, %rdi
leaq 0x78(%rsp), %rsi
callq 0x67616
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x1e0(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x9daf8
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x69a60
movq 0x258(%rsp), %rdi
testq %rdi, %rdi
je 0x5e12a
movq 0x268(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x240(%rsp), %rdi
testq %rdi, %rdi
je 0x5e147
movq 0x250(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x228(%rsp), %rdi
testq %rdi, %rdi
je 0x5e164
movq 0x238(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x210(%rsp), %rdi
callq 0x2f4c2
leaq 0x1f8(%rsp), %rdi
callq 0x2f4c2
movq 0x1e0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e19b
movq 0x1f0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x1b0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e1b8
movq 0x1c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x5e1d5
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x5e1f2
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x168(%rsp), %rdi
callq 0x2f4c2
leaq 0x150(%rsp), %rdi
callq 0x2f4c2
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0x5e229
movq 0x148(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e246
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x5e263
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e280
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xa8(%rsp), %rdi
callq 0x2f4c2
leaq 0x90(%rsp), %rdi
callq 0x2f4c2
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x5e2b4
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %rbp
addq $0x70, %r14
addq $0xa8, %rbx
cmpq %rbp, %r12
jne 0x5e01d
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x5d8c4
movq %r14, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xef3fc(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xef3eb(%rip), %rdi     # 0x14d6f5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5e316
movq %rax, %rbx
jmp 0x5e35e
jmp 0x5e321
jmp 0x5e321
jmp 0x5e321
movq %rax, %rbx
jmp 0x5e359
jmp 0x5e328
movq %rax, %rbx
jmp 0x5e34f
movq %rax, %rbx
jmp 0x5e342
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
callq 0x6771a
leaq 0x138(%rsp), %rdi
callq 0x6771a
leaq 0x78(%rsp), %rdi
callq 0x6771a
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xec94
movq %rbx, %rdi
callq 0x4780