// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
cltq
imulq $0xc0, %rax, %rdi
callq 0x1180
movq %rax, -0x20(%rbp)
movss 0x6e999(%rip), %xmm0    # 0x8b7ec
mulss 0x6e991(%rip), %xmm0    # 0x8b7ec
movss %xmm0, 0x7f3d5(%rip)    # 0x9c238
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x1d016
movq -0x30(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jge 0x1ce9f
jmp 0x1d008
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rax
movswl 0x18(%rax), %esi
callq 0x1d050
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x48(%rax)
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x44(%rbp)
cmpl $0x3, -0x44(%rbp)
jge 0x1cf05
movq -0x30(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, 0x8(%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1ced9
movq -0x38(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x38(%rbp), %rax
movw $0x0, 0x70(%rax)
movq -0x38(%rbp), %rax
movl $0xffffffff, 0x34(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movl $0xffffffff, 0x38(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movl $0xffffffff, 0x3c(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movl 0x6c(%rax), %eax
movsbl -0x25(%rbp), %ecx
cmpl %ecx, %eax
je 0x1cf64
movq -0x30(%rbp), %rax
movl 0x6c(%rax), %eax
movb %al, -0x25(%rbp)
movq -0x20(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x40(%rbp)
jmp 0x1cfd0
cmpl $0x0, -0x24(%rbp)
je 0x1cfc6
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x4(%rbp), %edx
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq 0x64(%rax), %rax
shlq $0x5, %rax
addq %rax, %rcx
callq 0x1d1b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x1cfc4
movl -0x24(%rbp), %esi
movq -0x30(%rbp), %rdx
addq $0x18, %rdx
movq -0x30(%rbp), %rax
movl 0x64(%rax), %ecx
leaq 0x5eaf4(%rip), %rdi     # 0x7baa7
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x1cfce
movq $0x0, -0x40(%rbp)
jmp 0x1cfd0
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
cmpq $0x0, -0x40(%rbp)
je 0x1cfee
movq -0x40(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x38(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1ce84
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0xc0, %rcx, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movl -0x4(%rbp), %esi
movl -0x24(%rbp), %edx
leaq 0x5ea9a(%rip), %rdi     # 0x7bad6
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)