// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/buildup.c
// Function: Find_previous
struct bond *Find_previous(struct bond *bond, int n, int N_atoms,
			   struct residue *seq)
{
  // Find previous atom in same chain
  struct bond *previous=bond-1;
  int res=previous->atom->res;
  if((res+1)<bond->atom->res){
    printf("Gap %d-%d ", res, bond->atom->res);
  }

  int ichar=-1; char name_p[4]="   "; // Ex. B in CB
  if((seq->type==1)||(seq->type==-1)){ // Amino-acid
    ichar=Get_previous_AA(name_p, bond, res);
  }else if((seq->type==2)||(seq->type==3)||
	   (seq->type==-2)||(seq->type==-3)){ // Nucleic acid
    Get_previous_nuc(name_p, bond, seq->amm);
  }

  struct bond *prev=NULL, *pname=NULL;
  double dmin=1000000, dname=100000; int i;
  for(i=n; i>0; i--){
    if(previous->atom->res<(res-1))break;
    if((bond->atom->main)&&(previous->atom->main==0))goto next;
    if((((ichar>=0)&&(previous->atom->name[ichar]==name_p[0]))||
	(strncmp(previous->atom->name, name_p, 3)==0)||
	(strncmp(previous->atom->name, name_p, 2)==0))&&
       (previous->atom->name[0]!='H')){
      double d2=0, x; int j;
      for(j=0; j<3; j++){
	x=previous->r[j]-bond->r[j]; d2+=x*x;
      }
      if(d2< BONDTHR1_2)return(previous);
      if(d2<dname){pname=previous; dname=d2;}
    }else{ // Not the name I am looking for!
      double d2=0, x; int j;
      for(j=0; j<3; j++){
	x=previous->r[j]-bond->r[j]; d2+=x*x;
      }
      if(d2<dmin){prev=previous; dmin=d2;}
    }
  next:
    previous--;
  }
  /*// Look ahead
  previous=bond+1;
  for(i=n+1; i<N_atoms; i++){
    if(previous->atom->res>res)break;
    if((bond->atom->main)&&(previous->atom->main==0))goto next2;
    if((((ichar>=0)&&(previous->atom->name[ichar]==name_p[0]))||
	(strncmp(previous->atom->name, name_p, 3)==0)||
	(strncmp(previous->atom->name, name_p, 2)==0))&&
       (previous->atom->name[0]!='H')){
      float d2=0, x; int j;
      for(j=0; j<3; j++){
	x=previous->r[j]-bond->r[j]; d2+=x*x;
      }
      if(d2< BONDTHR1_2)return(previous);
      if(d2<dname){pname=previous; dname=d2;}
    }else{ // Not the name I am looking for!
      float d2=0, x; int j;
      for(j=0; j<3; j++){
	x=previous->r[j]-bond->r[j]; d2+=x*x;
      }
      if(d2<dmin){prev=previous; dmin=d2;}
    }
  next2:
    previous++;
    }*/


  if(pname!=NULL){
    prev=pname;
  }else{
    printf("WARNING, no proper previous atom of %s ", bond->atom->name);
    printf("res %d chain %d type %d %c\n", bond->atom->res,
	   bond->atom->chain, seq->type, seq->amm);
    printf("Expected previous: %s %d %c\n", name_p, ichar, name_p[0]);
  }

  if(prev==NULL){ 
    printf("ERROR, no previous atom of %s found\n", bond->atom->name);
    printf("n= %d i= %d ", n, i);
    printf("d(atom: %s%d%c previous: %s %d%c)= %.1f\n",
	 bond->atom->name, bond->atom->res, bond->atom->aa,
	 previous->atom->name, previous->atom->res, previous->atom->aa,
	   sqrt(dmin));
    exit(8);
  }
  printf("d(atom: %s%d%c previous: %s%d%c)= %.1f\n",
	 bond->atom->name, bond->atom->res, bond->atom->aa,
	 prev->atom->name, prev->atom->res, prev->atom->aa, sqrt(dmin));
  return(prev);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r15
movl %esi, %r12d
movq %rdi, %rbx
movq -0xc0(%rdi), %rax
movq (%rdi), %rcx
movl 0x64(%rax), %eax
movq %rax, 0x28(%rsp)
incl %eax
movl 0x64(%rcx), %edx
cmpl %edx, %eax
jge 0x15d37
leaq 0x40fc0(%rip), %rdi     # 0x56ceb
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
movl $0x202020, 0xc(%rsp)    # imm = 0x202020
movzwl 0x18(%r15), %eax
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x10(%rsp)
cmpl $0xfffc, %eax           # imm = 0xFFFC
movl %r12d, 0x14(%rsp)
movq %r15, 0x58(%rsp)
jg 0x15d7b
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x15d8a
cmpl $0x1, %eax
je 0x1602f
jmp 0x1606b
leal -0xfffd(%rax), %ecx
cmpl $0x2, %ecx
jae 0x16028
movzbl 0x13(%r15), %ebp
movq (%rbx), %r14
leaq 0x18(%r14), %r13
leaq 0x40aff(%rip), %rsi     # 0x5689c
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16056
leaq 0x41055(%rip), %rsi     # 0x56e0e
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1601e
leaq 0x4103d(%rip), %rsi     # 0x56e12
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1601e
leaq 0x40a94(%rip), %rsi     # 0x56885
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1601e
leaq 0x40a7f(%rip), %rsi     # 0x5688c
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16394
leaq 0x40a67(%rip), %rsi     # 0x56890
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x163ae
leaq 0x40fd1(%rip), %rsi     # 0x56e16
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x163a1
leaq 0x40a33(%rip), %rsi     # 0x56894
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x163a1
leaq 0x40a1b(%rip), %rsi     # 0x56898
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1646f
leaq 0x40f81(%rip), %rsi     # 0x56e1a
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1646f
leaq 0x40f69(%rip), %rsi     # 0x56e1e
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x164ae
leaq 0x40f51(%rip), %rsi     # 0x56e22
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x164ae
addl $-0x41, %ebp
cmpl $0x14, %ebp
ja 0x16637
movl $0x180004, %eax         # imm = 0x180004
btl %ebp, %eax
jae 0x164bb
leaq 0x40f1f(%rip), %rsi     # 0x56e26
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1662a
leaq 0x40f07(%rip), %rsi     # 0x56e2a
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16014
leaq 0x40eef(%rip), %rsi     # 0x56e2e
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1665d
leaq 0x40ed7(%rip), %rsi     # 0x56e32
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1665d
leaq 0x40ebf(%rip), %rsi     # 0x56e36
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16699
leaq 0x40ea7(%rip), %rsi     # 0x56e3a
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1667b
leaq 0x40e8f(%rip), %rsi     # 0x56e3e
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1667b
leaq 0x40e77(%rip), %rsi     # 0x56e42
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1667b
leaq 0x40e5f(%rip), %rsi     # 0x56e46
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166c8
leaq 0x40e47(%rip), %rsi     # 0x56e4a
movl $0x3, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
jne 0x1605e
movl $0x20314e, 0xc(%rsp)    # imm = 0x20314E
jmp 0x1605e
movl $0x202050, 0xc(%rsp)    # imm = 0x202050
jmp 0x1605e
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x1606b
movq (%rbx), %r14
movl 0x64(%r14), %ebp
cmpl 0x28(%rsp), %ebp
jle 0x16328
movb $0x0, 0xe(%rsp)
movw $0x2043, 0xc(%rsp)      # imm = 0x2043
movl $0x0, 0x10(%rsp)
jmp 0x1606b
movl $0x27334f, 0xc(%rsp)    # imm = 0x27334F
movl $0x0, 0x10(%rsp)
movl 0x14(%rsp), %r12d
leaq -0xc0(%rbx), %r15
testl %r12d, %r12d
jle 0x16239
movq 0x28(%rsp), %rax
decl %eax
movq %rax, 0x28(%rsp)
movl 0x18(%rsp), %eax
movq %rax, 0x60(%rsp)
leaq 0xc(%rsp), %rax
cvtss2sd 0x631db(%rip), %xmm0    # 0x79278
movsd %xmm0, 0x50(%rsp)
movb (%rax), %al
movb %al, 0x1f(%rsp)
leaq -0xb8(%rbx), %rbp
movsd 0x40898(%rip), %xmm0    # 0x56950
movsd 0x40898(%rip), %xmm1    # 0x56958
movsd %xmm1, 0x40(%rsp)
movq $0x0, 0x30(%rsp)
movl %r12d, %r13d
movq $0x0, 0x38(%rsp)
movq (%r15), %r12
movq 0x28(%rsp), %rax
cmpl %eax, 0x64(%r12)
jl 0x1622d
movq (%rbx), %rax
cmpl $0x0, 0x48(%rax)
je 0x16103
cmpl $0x0, 0x48(%r12)
je 0x1620c
movsd %xmm0, 0x20(%rsp)
cmpb $0x0, 0x10(%rsp)
je 0x16120
movq 0x60(%rsp), %rax
movb 0x1f(%rsp), %cl
cmpb %cl, 0x18(%r12,%rax)
je 0x16151
leaq 0x18(%r12), %r14
movl $0x3, %edx
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2070
testl %eax, %eax
je 0x16151
movl $0x2, %edx
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x2070
testl %eax, %eax
jne 0x16159
cmpb $0x48, 0x18(%r12)
jne 0x1619a
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd (%rbp,%rax,8), %xmm1
subsd 0x8(%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq $0x3, %rax
jne 0x1615f
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x38(%rsp), %rax
cmovaq %r15, %rax
movq %rax, 0x38(%rsp)
minsd %xmm1, %xmm0
jmp 0x1620c
xorpd %xmm2, %xmm2
xorl %eax, %eax
movsd (%rbp,%rax,8), %xmm1
subsd 0x8(%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm2
incq %rax
cmpq $0x3, %rax
jne 0x161a0
movsd 0x50(%rsp), %xmm0
ucomisd %xmm2, %xmm0
ja 0x161f1
movsd 0x40(%rsp), %xmm0
ucomisd %xmm2, %xmm0
movq 0x30(%rsp), %rax
cmovaq %r15, %rax
movq %rax, 0x30(%rsp)
movapd %xmm2, %xmm1
minsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
jmp 0x161f6
movq %r15, 0x48(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
ucomisd %xmm2, %xmm1
ja 0x16314
movq $-0xc0, %rcx
addq %rcx, %r15
leal -0x1(%r13), %eax
addq %rcx, %rbp
cmpl $0x1, %r13d
movl %eax, %r13d
jg 0x160db
xorl %r13d, %r13d
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %rax
jmp 0x16249
movsd 0x4070f(%rip), %xmm0    # 0x56950
xorl %r14d, %r14d
xorl %eax, %eax
movl %r12d, %r13d
movq %rax, %rcx
testq %rax, %rax
jne 0x162b4
movq (%rbx), %rsi
addq $0x18, %rsi
leaq 0x40a97(%rip), %rdi     # 0x56cf6
xorl %eax, %eax
movsd %xmm0, 0x20(%rsp)
callq 0x20f0
movq (%rbx), %rax
movl 0x64(%rax), %esi
movl 0x6c(%rax), %edx
movq 0x58(%rsp), %rax
movswl 0x18(%rax), %ecx
movsbl 0x13(%rax), %r8d
leaq 0x40a94(%rip), %rdi     # 0x56d1e
xorl %eax, %eax
callq 0x20f0
leaq 0xc(%rsp), %rsi
movsbl (%rsi), %ecx
leaq 0x40a9a(%rip), %rdi     # 0x56d3a
movl 0x18(%rsp), %edx
xorl %eax, %eax
callq 0x20f0
movsd 0x20(%rsp), %xmm0
movq %r14, %rcx
movq (%rbx), %rax
leaq 0x18(%rax), %r14
testq %rcx, %rcx
je 0x166f7
movl 0x64(%rax), %ebx
movsbl 0x68(%rax), %ebp
movq %rcx, 0x48(%rsp)
movq (%rcx), %rax
leaq 0x18(%rax), %r12
movl 0x64(%rax), %r13d
movsbl 0x68(%rax), %r15d
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x162f0
sqrtsd %xmm0, %xmm0
jmp 0x162f5
callq 0x2290
movl %r15d, (%rsp)
leaq 0x40ab2(%rip), %rdi     # 0x56db2
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
movq %r12, %r8
movl %r13d, %r9d
movb $0x1, %al
callq 0x20f0
movq 0x48(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0x19(%r14), %dl
movzbl %dl, %ecx
movzbl 0x18(%r14), %eax
cmpl $0x48, %eax
jne 0x1636b
addl $-0x31, %ecx
cmpl $0x1d, %ecx
ja 0x163e9
movl $0x20000007, %eax       # imm = 0x20000007
btl %ecx, %eax
jae 0x163e9
movb $0x20, 0xc(%rsp)
movl $0x1, 0x18(%rsp)
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x1606b
leal -0x41(%rcx), %edx
cmpl $0x7, %edx
ja 0x163bb
leaq 0x405ee(%rip), %rax     # 0x56968
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movb $0x0, 0xe(%rsp)
movw $0x204e, 0xc(%rsp)      # imm = 0x204E
jmp 0x1604c
movl $0x27354f, 0xc(%rsp)    # imm = 0x27354F
jmp 0x1605e
movl $0x273443, 0xc(%rsp)    # imm = 0x273443
jmp 0x1605e
movl $0x273543, 0xc(%rsp)    # imm = 0x273543
jmp 0x1605e
cmpl $0x5a, %ecx
je 0x164a4
cmpl $0x20, %ecx
jne 0x163f2
cmpl $0x43, %eax
je 0x1645e
cmpl $0x4f, %eax
je 0x16040
cmpl $0x4e, %eax
je 0x16040
jmp 0x16358
movb %dl, 0xc(%rsp)
jmp 0x16358
leaq 0x18(%r14), %r15
leaq 0x409dd(%rip), %rsi     # 0x56dda
movl $0x3, %edx
movq %r15, %rdi
callq 0x2070
testl %eax, %eax
je 0x16040
leaq 0x3fb13(%rip), %rsi     # 0x55f2c
movl $0x2, %edx
movq %r15, %rdi
callq 0x2070
testl %eax, %eax
je 0x16040
movl 0x6c(%r14), %ecx
leaq 0x409a5(%rip), %rdi     # 0x56dde
movl $0x0, 0x10(%rsp)
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
movw $0x2020, 0xc(%rsp)      # imm = 0x2020
movb $0x0, 0xe(%rsp)
jmp 0x1606b
movb $0x0, 0xe(%rsp)
movw $0x4143, 0xc(%rsp)      # imm = 0x4143
jmp 0x1604c
movl $0x273343, 0xc(%rsp)    # imm = 0x273343
jmp 0x1605e
movb $0x44, 0xc(%rsp)
jmp 0x16358
movb $0x42, 0xc(%rsp)
jmp 0x16358
movb $0x47, 0xc(%rsp)
jmp 0x16358
movb $0x5a, 0xc(%rsp)
jmp 0x16358
movb $0x45, 0xc(%rsp)
jmp 0x16358
movl $0x273243, 0xc(%rsp)    # imm = 0x273243
jmp 0x1605e
movl $0x41, %eax
btl %ebp, %eax
jae 0x16637
leaq 0x4097e(%rip), %rsi     # 0x56e4e
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1662a
leaq 0x40965(%rip), %rsi     # 0x56e51
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16619
leaq 0x4094c(%rip), %rsi     # 0x56e54
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x1666a
leaq 0x40933(%rip), %rsi     # 0x56e57
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x16688
leaq 0x4091a(%rip), %rsi     # 0x56e5a
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166b7
leaq 0x40901(%rip), %rsi     # 0x56e5d
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166a6
leaq 0x408e8(%rip), %rsi     # 0x56e60
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166a6
leaq 0x408cf(%rip), %rsi     # 0x56e63
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166a6
leaq 0x408b6(%rip), %rsi     # 0x56e66
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166e6
leaq 0x4089d(%rip), %rsi     # 0x56e69
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166d5
leaq 0x40884(%rip), %rsi     # 0x56e6c
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
je 0x166d5
leaq 0x4086b(%rip), %rsi     # 0x56e6f
movl $0x2, %edx
movq %r13, %rdi
callq 0x2070
testl %eax, %eax
jne 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x394e, 0xc(%rsp)      # imm = 0x394E
jmp 0x1605e
movl $0x273143, 0xc(%rsp)    # imm = 0x273143
jmp 0x1605e
movl 0x64(%r14), %edx
movl 0x6c(%r14), %ecx
leaq 0x40798(%rip), %rdi     # 0x56dde
movl $0x0, 0x10(%rsp)
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x16066
movl $0x203243, 0xc(%rsp)    # imm = 0x203243
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x3843, 0xc(%rsp)      # imm = 0x3843
jmp 0x1605e
movl $0x203443, 0xc(%rsp)    # imm = 0x203443
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x374e, 0xc(%rsp)      # imm = 0x374E
jmp 0x1605e
movl $0x20334e, 0xc(%rsp)    # imm = 0x20334E
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x3643, 0xc(%rsp)      # imm = 0x3643
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x3543, 0xc(%rsp)      # imm = 0x3543
jmp 0x1605e
movl $0x203543, 0xc(%rsp)    # imm = 0x203543
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x3243, 0xc(%rsp)      # imm = 0x3243
jmp 0x1605e
movb $0x0, 0xe(%rsp)
movw $0x314e, 0xc(%rsp)      # imm = 0x314E
jmp 0x1605e
leaq 0x40659(%rip), %rdi     # 0x56d57
movq %r14, %rsi
xorl %eax, %eax
movsd %xmm0, 0x20(%rsp)
callq 0x20f0
leaq 0x40667(%rip), %rdi     # 0x56d7c
movl 0x14(%rsp), %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movq (%rbx), %rax
leaq 0x18(%rax), %rbx
movl 0x64(%rax), %ebp
movsbl 0x68(%rax), %r14d
movq (%r15), %rax
leaq 0x18(%rax), %r15
movl 0x64(%rax), %r12d
movsbl 0x68(%rax), %r13d
xorpd %xmm1, %xmm1
movsd 0x20(%rsp), %xmm2
movapd %xmm2, %xmm0
ucomisd %xmm1, %xmm2
jb 0x1675c
sqrtsd %xmm0, %xmm0
jmp 0x16761
callq 0x2290
movl %r13d, (%rsp)
leaq 0x4061d(%rip), %rdi     # 0x56d89
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movq %r15, %r8
movl %r12d, %r9d
movb $0x1, %al
callq 0x20f0
movl $0x8, %edi
callq 0x2270