// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/buildup.c
// Function: Set_bonds_topology
struct bond *Set_bonds_topology(int N_atoms, atom *atoms, struct residue *seq)
{
  struct bond *bonds=malloc((N_atoms+1)*sizeof(struct bond));
  BONDTHR1_2=BONDTHR1*BONDTHR1;

  if(DEBUG)printf("Setting bond topology\n");
  int i;
  char chain=atoms[0].chain;
  atom *atom=atoms;
  struct bond *bond=bonds, *previous;
  for(i=0; i<N_atoms; i++){
    //ALIGN
    if(atom->ali<0)continue; // for 2 str, not aligned atoms are omitted
    atom->main=Is_atom_main(atom->name, seq->type);
    bond->i_atom=i;
    bond->atom=atom;
    for(int j=0; j<3; j++)bond->r[j]=atom->r[j];
    bond->terminal=1;
    bond->d_phi=0; bond->len=-1; bond->angle=-1; bond->torsion=-1;
    // The first atom of a chain is joined to the third one
    // of the first chain (n=3)
    if(atom->chain!=chain){
      chain=atom->chain;
      previous=bonds+2;
    }else if(i){
      previous=Find_previous(bond, i, N_atoms, seq+bond->atom->res);
      if(previous==NULL){
	printf("ERROR, atom %d %s res %d has no previous atom\n",
	       i, atom->name, atom->res); exit(8);
      }
    }else{previous=NULL;}
    bond->previous=previous;
    if(previous)previous->terminal=0;
    bond++; atom++;
  }
  bonds[i].atom=NULL; // Last bond
  printf("%d atoms, %d bonds for building the molecule\n", N_atoms, i);
  return(bonds);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movq %rsi, %r15
movl %edi, %ebx
movslq %edi, %r14
movq %r14, %rax
shlq $0x6, %rax
leaq (%rax,%rax,2), %rdi
addq $0xc0, %rdi
callq 0x21d0
movq %rax, %rbp
movss 0x52d98(%rip), %xmm0    # 0x6882c
mulss %xmm0, %xmm0
movss %xmm0, 0x637d8(%rip)    # 0x79278
testl %r14d, %r14d
jle 0x15b85
movb 0x6c(%r15), %r12b
movq %rbp, %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq %rbp, 0x8(%rsp)
cmpl $0x0, 0x54(%r15)
js 0x15b70
leaq 0x18(%r15), %r14
movq (%rsp), %rax
movswl 0x18(%rax), %esi
movq %r14, %rdi
callq 0x15bde
movl %eax, 0x48(%r15)
movl %r13d, 0x20(%rbp)
movq %r15, (%rbp)
movq 0x10(%r15), %rax
movq %rax, 0x18(%rbp)
movups (%r15), %xmm0
movups %xmm0, 0x8(%rbp)
movl $0x1, 0x30(%rbp)
movw $0x0, 0x70(%rbp)
movq $-0x1, 0x34(%rbp)
movl $0xffffffff, 0x3c(%rbp) # imm = 0xFFFFFFFF
movl 0x6c(%r15), %eax
movsbl %r12b, %ecx
cmpl %ecx, %eax
jne 0x15b49
testl %r13d, %r13d
je 0x15b53
movslq 0x64(%r15), %rcx
shlq $0x5, %rcx
addq (%rsp), %rcx
movq %rbp, %rdi
movl %r13d, %esi
callq 0x15cf2
testq %rax, %rax
jne 0x15b55
jmp 0x15bbc
movl %eax, %r12d
movq 0x10(%rsp), %rax
jmp 0x15b55
xorl %eax, %eax
movq %rax, 0x28(%rbp)
testq %rax, %rax
je 0x15b65
movl $0x0, 0x30(%rax)
addq $0xc0, %rbp
addq $0x70, %r15
incl %r13d
cmpl %r13d, %ebx
jne 0x15ac3
movl %ebx, %edx
movq 0x8(%rsp), %rbp
jmp 0x15b87
xorl %edx, %edx
movl %edx, %eax
leaq (%rax,%rax,2), %rax
shlq $0x6, %rax
movq $0x0, (%rbp,%rax)
leaq 0x40e31(%rip), %rdi     # 0x569d2
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x64(%r15), %ecx
leaq 0x40ddc(%rip), %rdi     # 0x569a3
movl %r13d, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2270