// File: /workspace/github_cpp_makefile_star2_O1/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 $0x268, %rsp            # imm = 0x268
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0x514f4
movsd 0x8(%r15), %xmm0
movsd 0x28(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x20(%rsp), %xmm3
divsd %xmm3, %xmm0
movsd 0x10(%r15), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm3, %xmm1
mulsd 0x18(%r15), %xmm2
divsd %xmm3, %xmm2
movapd %xmm2, %xmm4
movups 0x20(%r15), %xmm2
movsd 0x30(%r15), %xmm3
movsd %xmm0, 0x8(%r14)
movsd %xmm1, 0x10(%r14)
movsd %xmm4, 0x18(%r14)
movups %xmm2, 0x20(%r14)
movsd %xmm3, 0x30(%r14)
movq %r14, %rdi
callq 0x521f4
movq %r14, 0x20(%rsp)
movq 0x8(%rbx), %r12
movq %rbx, 0x38(%rsp)
subq (%rbx), %r12
sarq $0x3, %r12
movabsq $-0x30c30c30c30c30c3, %rcx # imm = 0xCF3CF3CF3CF3CF3D
movq 0x3c8(%r15), %rax
movq %r15, 0x28(%rsp)
subq 0x3c0(%r15), %rax
imulq %rcx, %r12
shrq $0x4, %rax
imull $0xb6db6db7, %eax, %edx # imm = 0xB6DB6DB7
cmpl %edx, %r12d
je 0x5e5ca
leaq 0xf6e8c(%rip), %rdi     # 0x15544c
movl %r12d, %esi
xorl %eax, %eax
callq 0x4060
testl %r12d, %r12d
jle 0x5e88e
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x10, %r14d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x28(%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 0x5e8c6
movsd -0x10(%rax,%r14), %xmm0
movsd -0x8(%rax,%r14), %xmm1
movsd (%rax,%r14), %xmm2
leaq 0x100(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x530d6
movq 0x38(%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 0x5e8b5
addq %rbx, %rsi
leaq 0x58(%rsp), %rdi
callq 0x67f48
leaq 0x40(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x85da6
leaq 0x118(%rsp), %r13
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
callq 0x67f48
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x40(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x1c0(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x9f6e4
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x6a4a0
movq 0x238(%rsp), %rdi
testq %rdi, %rdi
je 0x5e6f3
movq 0x248(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x220(%rsp), %rdi
testq %rdi, %rdi
je 0x5e710
movq 0x230(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x5e72d
movq 0x218(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x1f0(%rsp), %rdi
callq 0x2f6f0
leaq 0x1d8(%rsp), %rdi
callq 0x2f6f0
movq 0x1c0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e764
movq 0x1d0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x5e781
movq 0x1a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x178(%rsp), %rdi
testq %rdi, %rdi
je 0x5e79e
movq 0x188(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x5e7bb
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x148(%rsp), %rdi
callq 0x2f6f0
leaq 0x130(%rsp), %rdi
callq 0x2f6f0
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x5e7f2
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e80f
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x5e82c
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5e849
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x88(%rsp), %rdi
callq 0x2f6f0
leaq 0x70(%rsp), %rdi
callq 0x2f6f0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5e877
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incq %rbp
addq $0x70, %r14
addq $0xa8, %rbx
cmpq %rbp, %r12
jne 0x5e5e4
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x5de56
movq %r14, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf0de9(%rip), %rdi     # 0x14f6a5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
leaq 0xf0dd8(%rip), %rdi     # 0x14f6a5
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5e8d9
movq %rax, %rbx
jmp 0x5e921
jmp 0x5e8e4
jmp 0x5e8e4
jmp 0x5e8e4
movq %rax, %rbx
jmp 0x5e91c
jmp 0x5e8eb
movq %rax, %rbx
jmp 0x5e912
movq %rax, %rbx
jmp 0x5e905
movq %rax, %rbx
leaq 0x1c0(%rsp), %rdi
callq 0x6804c
leaq 0x118(%rsp), %rdi
callq 0x6804c
leaq 0x58(%rsp), %rdi
callq 0x6804c
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0xec14
movq %rbx, %rdi
callq 0x4780