// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %esi, %r15d
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 0x1458b
leaq 0x3c6d0(%rip), %rdi     # 0x50c4f
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
movl $0x202020, 0x10(%rsp)   # imm = 0x202020
movzwl 0x18(%r14), %eax
pushq $-0x1
popq %rbp
movb $0x20, 0xf(%rsp)
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
movq %r14, 0x58(%rsp)
jb 0x145e9
leal -0xfffd(%rax), %ecx
cmpl $0x2, %ecx
jb 0x145e9
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x145c8
cmpl $0x1, %eax
jne 0x14a89
movq (%rbx), %rsi
movl 0x64(%rsi), %edx
cmpl 0x28(%rsp), %edx
jle 0x1468d
movb $0x0, 0x12(%rsp)
movw $0x2043, 0x10(%rsp)     # imm = 0x2043
jmp 0x14a84
movzbl 0x13(%r14), %edi
movq (%rbx), %rax
movzbl 0x18(%rax), %ecx
cmpl $0x43, %ecx
je 0x14654
cmpl $0x4f, %ecx
je 0x14626
cmpl $0x50, %ecx
jne 0x1461d
cmpb $0x20, 0x19(%rax)
jne 0x1461d
cmpb $0x20, 0x1a(%rax)
jne 0x1461d
movl $0x27334f, 0x10(%rsp)   # imm = 0x27334F
jmp 0x14725
xorl %esi, %esi
xorl %edx, %edx
jmp 0x1479e
movzbl 0x19(%rax), %edx
movb $0x1, %sil
leal -0x32(%rdx), %r8d
cmpl $0x3, %r8d
ja 0x146fb
leaq 0x3c27a(%rip), %rdx     # 0x508bc
movslq (%rdx,%r8,4), %r8
addq %rdx, %r8
jmpq *%r8
cmpb $0x27, 0x1a(%rax)
jne 0x1461f
jmp 0x14680
movzbl 0x19(%rax), %esi
movb $0x1, %dl
addl $-0x31, %esi
cmpl $0x4, %esi
ja 0x1479c
leaq 0x3c23b(%rip), %r8      # 0x508a8
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
cmpb $0x27, 0x1a(%rax)
jne 0x1479c
movl $0x273243, 0x10(%rsp)   # imm = 0x273243
jmp 0x14a84
movb 0x19(%rsi), %r8b
movzbl %r8b, %ecx
movzbl 0x18(%rsi), %edi
pushq $0x1
popq %rax
cmpl $0x48, %edi
jne 0x146cb
addl $-0x31, %ecx
cmpl $0x1d, %ecx
ja 0x149f1
movl $0x20000007, %edx       # imm = 0x20000007
btl %ecx, %edx
jae 0x149f1
movb $0x20, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
jmp 0x14a93
leal -0x41(%rcx), %r8d
cmpl $0x7, %r8d
ja 0x1496d
leaq 0x3c1ec(%rip), %r9      # 0x508cc
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movb $0x0, 0x12(%rsp)
movw $0x204e, 0x10(%rsp)     # imm = 0x204E
jmp 0x149bb
cmpl $0x50, %edx
jne 0x1461f
movzbl 0x1a(%rax), %edx
cmpl $0x32, %edx
je 0x14758
cmpl $0x31, %edx
je 0x14758
jmp 0x1461f
cmpb $0x27, 0x1a(%rax)
jne 0x1479c
movl $0x27354f, 0x10(%rsp)   # imm = 0x27354F
movb $0x4f, 0xf(%rsp)
jmp 0x14a89
cmpb $0x27, 0x1a(%rax)
jne 0x1461f
jmp 0x14741
cmpb $0x27, 0x1a(%rax)
jne 0x1479c
movl $0x273443, 0x10(%rsp)   # imm = 0x273443
jmp 0x14a84
cmpb $0x27, 0x1a(%rax)
jne 0x1461f
movl $0x202050, 0x10(%rsp)   # imm = 0x202050
movb $0x50, 0xf(%rsp)
jmp 0x14a89
cmpb $0x27, 0x1a(%rax)
jne 0x1461f
jmp 0x1478f
cmpb $0x27, 0x1a(%rax)
jne 0x1479c
movl $0x273543, 0x10(%rsp)   # imm = 0x273543
jmp 0x14a84
cmpb $0x27, 0x1a(%rax)
jne 0x1479c
movl $0x273343, 0x10(%rsp)   # imm = 0x273343
jmp 0x14a84
xorl %esi, %esi
addl $-0x41, %edi
cmpl $0x14, %edi
ja 0x148f5
movl $0x180004, %r8d         # imm = 0x180004
btl %edi, %r8d
jae 0x147e4
cmpb $0x4e, %cl
jne 0x147c7
cmpb $0x31, 0x19(%rax)
jne 0x147c7
cmpb $0x20, 0x1a(%rax)
je 0x14805
testb %dl, %dl
je 0x14812
cmpb $0x32, 0x19(%rax)
jne 0x14812
cmpb $0x20, 0x1a(%rax)
jne 0x14812
movl $0x20314e, 0x10(%rsp)   # imm = 0x20314E
jmp 0x149bb
pushq $0x41
popq %r8
btl %edi, %r8d
jae 0x148f5
cmpb $0x4e, %cl
jne 0x148be
cmpb $0x39, 0x19(%rax)
jne 0x148be
movl $0x273143, 0x10(%rsp)   # imm = 0x273143
jmp 0x14a84
testb %sil, %sil
je 0x14823
cmpb $0x32, 0x19(%rax)
jne 0x14823
cmpb $0x20, 0x1a(%rax)
je 0x14834
cmpb $0x4e, %cl
jne 0x14841
cmpb $0x33, 0x19(%rax)
jne 0x14841
cmpb $0x20, 0x1a(%rax)
jne 0x14841
movl $0x203243, 0x10(%rsp)   # imm = 0x203243
jmp 0x14a84
testb %dl, %dl
je 0x1485e
cmpb $0x34, 0x19(%rax)
jne 0x1485e
cmpb $0x20, 0x1a(%rax)
jne 0x1485e
movl $0x20334e, 0x10(%rsp)   # imm = 0x20334E
jmp 0x149bb
testb %sil, %sil
je 0x1486f
cmpb $0x34, 0x19(%rax)
jne 0x1486f
cmpb $0x20, 0x1a(%rax)
je 0x148b1
cmpb $0x4e, %cl
jne 0x14880
cmpb $0x34, 0x19(%rax)
jne 0x14880
cmpb $0x20, 0x1a(%rax)
je 0x148b1
testb %dl, %dl
je 0x14a89
movzbl 0x19(%rax), %ecx
cmpl $0x37, %ecx
je 0x14a12
cmpl $0x36, %ecx
je 0x14a06
cmpl $0x35, %ecx
jne 0x14a89
cmpb $0x20, 0x1a(%rax)
jne 0x14a89
movl $0x203443, 0x10(%rsp)   # imm = 0x203443
jmp 0x14a84
testb %dl, %dl
je 0x148d9
cmpb $0x38, 0x19(%rax)
jne 0x148d9
movb $0x0, 0x12(%rsp)
movw $0x394e, 0x10(%rsp)     # imm = 0x394E
jmp 0x149bb
cmpb $0x4e, %cl
jne 0x1491a
cmpb $0x37, 0x19(%rax)
jne 0x1491a
movb $0x0, 0x12(%rsp)
movw $0x3843, 0x10(%rsp)     # imm = 0x3843
jmp 0x14a84
leaq 0x18(%rax), %rsi
movl 0x64(%rax), %edx
movl 0x6c(%rax), %ecx
leaq 0x3c438(%rip), %rdi     # 0x50d3e
movl $0x0, 0x14(%rsp)
xorl %eax, %eax
callq 0x20f0
jmp 0x14a91
testb %dl, %dl
je 0x1493e
movzbl 0x19(%rax), %edi
cmpl $0x36, %edi
je 0x14a78
cmpl $0x35, %edi
jne 0x1493e
movb $0x0, 0x12(%rsp)
movw $0x374e, 0x10(%rsp)     # imm = 0x374E
jmp 0x149bb
testb %sil, %sil
je 0x14949
cmpb $0x36, 0x19(%rax)
je 0x1495c
cmpb $0x4e, %cl
jne 0x149a5
movzbl 0x19(%rax), %esi
cmpl $0x31, %esi
je 0x1495c
cmpl $0x36, %esi
jne 0x149a5
movb $0x0, 0x12(%rsp)
movw $0x3643, 0x10(%rsp)     # imm = 0x3643
jmp 0x14a84
cmpl $0x5a, %ecx
je 0x14d94
cmpl $0x20, %ecx
jne 0x14a22
cmpl $0x43, %edi
je 0x14a6a
cmpl $0x4f, %edi
je 0x145d8
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
cmpl $0x4e, %edi
je 0x145d8
jmp 0x14a93
testb %dl, %dl
je 0x149c5
cmpb $0x32, 0x19(%rax)
jne 0x149c5
movb $0x0, 0x12(%rsp)
movw $0x314e, 0x10(%rsp)     # imm = 0x314E
movb $0x4e, 0xf(%rsp)
jmp 0x14a89
cmpb $0x4e, %cl
jne 0x14d29
movzbl 0x19(%rax), %ecx
cmpl $0x33, %ecx
je 0x149e0
cmpl $0x32, %ecx
jne 0x14d29
movb $0x0, 0x12(%rsp)
movw $0x3243, 0x10(%rsp)     # imm = 0x3243
jmp 0x14a84
movb %r8b, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb %r8b, 0xf(%rsp)
jmp 0x14a93
cmpb $0x20, 0x1a(%rax)
je 0x147d7
jmp 0x14a89
cmpb $0x20, 0x1a(%rax)
jne 0x14a89
movl $0x203543, 0x10(%rsp)   # imm = 0x203543
jmp 0x14a84
cmpl $0x4f, %edi
jne 0x14a3f
cmpl $0x54, %ecx
je 0x145d8
cmpl $0x58, %ecx
jne 0x14a3f
cmpb $0x54, 0x1a(%rsi)
je 0x145d8
movl 0x6c(%rsi), %ecx
addq $0x18, %rsi
leaq 0x3c2f1(%rip), %rdi     # 0x50d3e
movl $0x0, 0x14(%rsp)
xorl %eax, %eax
callq 0x20f0
movw $0x2020, 0x10(%rsp)     # imm = 0x2020
movb $0x0, 0x12(%rsp)
jmp 0x14a91
movb $0x0, 0x12(%rsp)
movw $0x4143, 0x10(%rsp)     # imm = 0x4143
jmp 0x14a84
movb $0x0, 0x12(%rsp)
movw $0x3543, 0x10(%rsp)     # imm = 0x3543
movb $0x43, 0xf(%rsp)
movl $0x0, 0x14(%rsp)
movl %ebp, %eax
leaq -0xc0(%rbx), %r14
movq 0x28(%rsp), %rcx
decl %ecx
movq %rcx, 0x28(%rsp)
movl %eax, %eax
movq %rax, 0x48(%rsp)
cvtss2sd 0x5f7c3(%rip), %xmm0    # 0x74278
movsd %xmm0, 0x60(%rsp)
movl %r15d, %eax
sarl $0x1f, %eax
andl %r15d, %eax
movl %eax, 0x34(%rsp)
leaq -0xb8(%rbx), %rbp
movsd 0x3bdb9(%rip), %xmm0    # 0x50890
movsd %xmm0, 0x50(%rsp)
movsd 0x3bdb3(%rip), %xmm0    # 0x50898
movq $0x0, 0x38(%rsp)
movq $0x0, 0x20(%rsp)
movl %r15d, 0x44(%rsp)
testl %r15d, %r15d
jle 0x14c30
movq (%r14), %r13
movq (%rbx), %rsi
movq 0x28(%rsp), %rax
cmpl %eax, 0x64(%r13)
jl 0x14c35
cmpl $0x0, 0x48(%rsi)
je 0x14b2b
cmpl $0x0, 0x48(%r13)
je 0x14c1b
movsd %xmm0, 0x18(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x14b48
movb 0xf(%rsp), %al
movq 0x48(%rsp), %rcx
cmpb %al, 0x18(%r13,%rcx)
je 0x14b74
leaq 0x18(%r13), %r12
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x3
popq %rdx
callq 0x2070
testl %eax, %eax
je 0x14b74
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x2070
testl %eax, %eax
jne 0x14b7b
cmpb $0x48, 0x18(%r13)
jne 0x14bbe
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x14ba0
movsd (%rbp,%rax,8), %xmm1
subsd 0x8(%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
jmp 0x14b81
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x38(%rsp), %rax
cmovaq %r14, %rax
movq %rax, 0x38(%rsp)
minsd %xmm1, %xmm0
jmp 0x14c1b
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq $0x3, %rax
je 0x14be3
movsd (%rbp,%rax,8), %xmm1
subsd 0x8(%rbx,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
jmp 0x14bc4
movsd 0x60(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x14d24
movsd 0x50(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x20(%rsp), %rax
cmovaq %r14, %rax
movq %rax, 0x20(%rsp)
minsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x18(%rsp), %xmm0
movq $-0xc0, %rax
addq %rax, %r14
decl %r15d
addq %rax, %rbp
jmp 0x14afc
movq (%rbx), %rsi
jmp 0x14c3a
movl %r15d, 0x34(%rsp)
cmpq $0x0, 0x20(%rsp)
movq 0x38(%rsp), %r15
je 0x14c4e
movq 0x20(%rsp), %r15
jmp 0x14cba
movsd %xmm0, 0x18(%rsp)
addq $0x18, %rsi
leaq 0x3bffb(%rip), %rdi     # 0x50c5a
xorl %eax, %eax
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 0x3bffe(%rip), %rdi     # 0x50c82
xorl %eax, %eax
callq 0x20f0
movsbl 0xf(%rsp), %ecx
leaq 0x3c007(%rip), %rdi     # 0x50c9e
leaq 0x10(%rsp), %rsi
movq 0x48(%rsp), %rdx
xorl %eax, %eax
callq 0x20f0
movq (%rbx), %rsi
testq %r15, %r15
je 0x14da9
movsd 0x18(%rsp), %xmm0
leaq 0x18(%rsi), %rbx
movl 0x64(%rsi), %ebp
movsbl 0x68(%rsi), %r14d
movq %r15, 0x20(%rsp)
movq (%r15), %rax
leaq 0x18(%rax), %r12
movl 0x64(%rax), %r15d
movsbl 0x68(%rax), %r13d
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x14ceb
sqrtsd %xmm0, %xmm0
jmp 0x14cf0
callq 0x2290
movl %r13d, (%rsp)
leaq 0x3c01b(%rip), %rdi     # 0x50d16
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
movq %r12, %r8
movl %r15d, %r9d
movb $0x1, %al
callq 0x20f0
movq 0x20(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rax
jmp 0x14d15
testb %dl, %dl
je 0x14a89
cmpb $0x34, 0x19(%rax)
je 0x148c8
jmp 0x14a89
movb $0x44, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb $0x44, 0xf(%rsp)
jmp 0x14a93
movb $0x42, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb $0x42, 0xf(%rsp)
jmp 0x14a93
movb $0x47, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb $0x47, 0xf(%rsp)
jmp 0x14a93
movb $0x5a, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb $0x5a, 0xf(%rsp)
jmp 0x14a93
movb $0x45, 0x10(%rsp)
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movb $0x45, 0xf(%rsp)
jmp 0x14a93
addq $0x18, %rsi
leaq 0x3bf07(%rip), %rdi     # 0x50cbb
xorl %eax, %eax
callq 0x20f0
leaq 0x3bf1e(%rip), %rdi     # 0x50ce0
movl 0x44(%rsp), %esi
movl 0x34(%rsp), %edx
xorl %eax, %eax
callq 0x20f0
movq (%rbx), %rax
leaq 0x18(%rax), %rbx
movl 0x64(%rax), %ebp
movsbl 0x68(%rax), %r13d
movq (%r14), %rax
leaq 0x18(%rax), %r15
movl 0x64(%rax), %r12d
movsbl 0x68(%rax), %r14d
xorpd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x14e08
sqrtsd 0x18(%rsp), %xmm0
jmp 0x14e13
movsd 0x18(%rsp), %xmm0
callq 0x2290
movl %r14d, (%rsp)
leaq 0x3becf(%rip), %rdi     # 0x50ced
movq %rbx, %rsi
movl %ebp, %edx
movl %r13d, %ecx
movq %r15, %r8
movl %r12d, %r9d
movb $0x1, %al
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270