// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $-0xc0, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x64(%rcx), %eax
jge 0x1d211
movl -0x2c(%rbp), %esi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %edx
leaq 0x5ec58(%rip), %rdi     # 0x7be62
movb $0x0, %al
callq 0x10d0
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl 0x61361(%rip), %eax     # 0x7e57f
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x1, %eax
je 0x1d23b
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $-0x1, %eax
jne 0x1d250
leaq -0x34(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x1e5a0
movl %eax, -0x30(%rbp)
jmp 0x1d29b
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x2, %eax
je 0x1d284
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $0x3, %eax
je 0x1d284
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $-0x2, %eax
je 0x1d284
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %eax
cmpl $-0x3, %eax
jne 0x1d299
leaq -0x34(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movsbl 0x13(%rax), %edx
callq 0x1e830
jmp 0x1d29b
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movsd 0x5e7c5(%rip), %xmm0    # 0x7ba78
movsd %xmm0, -0x50(%rbp)
movsd 0x5e7b0(%rip), %xmm0    # 0x7ba70
movsd %xmm0, -0x58(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0x1d4e1
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1d2ee
jmp 0x1d4e1
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x48(%rax)
je 0x1d30d
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x48(%rax)
jne 0x1d30d
jmp 0x1d4c5
cmpl $0x0, -0x30(%rbp)
jl 0x1d32b
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movsbl 0x18(%rax,%rcx), %eax
movsbl -0x34(%rbp), %ecx
cmpl %ecx, %eax
je 0x1d36b
movq -0x28(%rbp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
leaq -0x34(%rbp), %rsi
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
je 0x1d36b
movq -0x28(%rbp), %rax
movq (%rax), %rdi
addq $0x18, %rdi
leaq -0x34(%rbp), %rsi
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x1d427
movq -0x28(%rbp), %rax
movq (%rax), %rax
movsbl 0x18(%rax), %eax
cmpl $0x48, %eax
je 0x1d427
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x3, -0x74(%rbp)
jge 0x1d3dc
movq -0x28(%rbp), %rax
movslq -0x74(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x74(%rbp), %rcx
subsd 0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x70(%rbp), %xmm2
movsd -0x68(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1d38e
movsd -0x68(%rbp), %xmm1
movss 0x7ee4f(%rip), %xmm0    # 0x9c238
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1d400
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1d6f1
movsd -0x68(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1d422
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1d4c3
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movl $0x0, -0x8c(%rbp)
cmpl $0x3, -0x8c(%rbp)
jge 0x1d49f
movq -0x28(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x8c(%rbp), %rcx
subsd 0x8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
movsd -0x88(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1d439
movsd -0x80(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1d4c1
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x1d4c3
jmp 0x1d4c5
movq -0x28(%rbp), %rax
addq $-0xc0, %rax
movq %rax, -0x28(%rbp)
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1d2cb
cmpq $0x0, -0x48(%rbp)
je 0x1d4f2
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x1d557
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x18, %rsi
leaq 0x5e969(%rip), %rdi     # 0x7be6d
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %esi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x6c(%rax), %edx
movq -0x20(%rbp), %rax
movswl 0x18(%rax), %ecx
movq -0x20(%rbp), %rax
movsbl 0x13(%rax), %r8d
leaq 0x5e95e(%rip), %rdi     # 0x7be95
movb $0x0, %al
callq 0x10d0
leaq -0x34(%rbp), %rsi
movl -0x30(%rbp), %edx
movsbl -0x34(%rbp), %ecx
leaq 0x5e961(%rip), %rdi     # 0x7beb1
movb $0x0, %al
callq 0x10d0
cmpq $0x0, -0x40(%rbp)
jne 0x1d641
movq -0x10(%rbp), %rax
movq (%rax), %rsi
addq $0x18, %rsi
leaq 0x5e95a(%rip), %rdi     # 0x7bece
movb $0x0, %al
callq 0x10d0
movl -0x14(%rbp), %esi
movl -0x5c(%rbp), %edx
leaq 0x5e96b(%rip), %rdi     # 0x7bef3
movb $0x0, %al
callq 0x10d0
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x94(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %eax
movl %eax, -0x90(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x1220
movq -0xb0(%rbp), %rsi
movl -0xa8(%rbp), %edx
movl -0xa4(%rbp), %ecx
movq -0xa0(%rbp), %r8
movl -0x94(%rbp), %r9d
movl -0x90(%rbp), %eax
leaq 0x5e8d3(%rip), %rdi     # 0x7bf00
movl %eax, (%rsp)
movb $0x1, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, -0xc0(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0xb8(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movsbl 0x68(%rax), %eax
movl %eax, -0xb4(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x1220
movq -0xd0(%rbp), %rsi
movl -0xc8(%rbp), %edx
movl -0xc4(%rbp), %ecx
movq -0xc0(%rbp), %r8
movl -0xb8(%rbp), %r9d
movl -0xb4(%rbp), %eax
leaq 0x5e84a(%rip), %rdi     # 0x7bf29
movl %eax, (%rsp)
movb $0x1, %al
callq 0x10d0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nop