// File: /workspace/github_c_makefile_star2_O0/josch[P]stride/contact_order.c
// Function: ContactOrder
void ContactOrder(CHAIN **Chain, int NChain, COMMAND *Cmd )
{

  register int Res1, Res2, At1, At2;
  int Cn, From, To, NumberOfContacts;
  char PDB_Start[RES_FIELD], PDB_End[RES_FIELD];
  double CO;
  
  for( Cn=0; Cn<NChain; Cn++ ) {
    
    if( !Chain[Cn]->Valid )
      continue;
    NumberOfContacts = 0;
    CO = 0.0;
    if( !strcmp(Cmd->FirstResidue,"") ) {
      From = 0;
      strcpy(PDB_Start,Chain[Cn]->Rsd[0]->PDB_ResNumb);
    }
    else { 
      if( !PdbN2SeqN(Chain[Cn],Cmd->FirstResidue,&From) ) {
	fprintf(stderr,"Residue %s does not exist in %s chain %c\n",
		Cmd->FirstResidue,Chain[Cn]->PdbIdent,SpaceToDash(Chain[Cn]->Id));
	exit(1);
      }
      strcpy(PDB_Start,Cmd->FirstResidue);
    }
    if( !strcmp(Cmd->LastResidue,"") ) {
      To = Chain[Cn]->NRes;
      strcpy(PDB_End,Chain[Cn]->Rsd[Chain[Cn]->NRes-1]->PDB_ResNumb);
    }
    else {
      if( !PdbN2SeqN(Chain[Cn],Cmd->LastResidue,&To) ) {
	fprintf(stderr,"Residue %s does not exist in %s chain %c\n",
		Cmd->LastResidue,Chain[Cn]->PdbIdent,SpaceToDash(Chain[Cn]->Id));
	exit(1);
      }
      strcpy(PDB_End,Cmd->LastResidue);
    }
    for( Res1=From; Res1<To-1; Res1++ ) {
      for( At1=0; At1<Chain[Cn]->Rsd[Res1]->NAtom; At1++ ) {
	if( !strcmp(Chain[Cn]->Rsd[Res1]->AtomType[At1],"H") )
	  continue;
	for( Res2 = Res1+1; Res2<To; Res2++ ) {
	  for( At2=0; At2<Chain[Cn]->Rsd[Res2]->NAtom; At2++ ) {
	    if( !strcmp(Chain[Cn]->Rsd[Res2]->AtomType[At2],"H") )
	      continue;
	    if( Dist(Chain[Cn]->Rsd[Res1]->Coord[At1],
		     Chain[Cn]->Rsd[Res2]->Coord[At2]) < CO_DIST) {
	      CO += abs(Res1-Res2);
	      NumberOfContacts++;
	    }
	  }
	}
      }
    }
    CO = 100.0*CO/NumberOfContacts;
    CO /= (To-From+1);
    
    printf("%s %c %d ( %s ) %d ( %s ) %5.1f\n",
	   Chain[Cn]->PdbIdent,SpaceToDash(Chain[Cn]->Id),From,PDB_Start,To-1,PDB_End,CO);
  }
  exit(0);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movq %rdx, 0x80(%rsp)
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jge 0x2a0d6
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x58(%rax)
jne 0x29b93
jmp 0x2a0c6
movl $0x0, 0x60(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x80(%rsp), %rdi
addq $0x1ce6, %rdi           # imm = 0x1CE6
leaq 0x21aa(%rip), %rsi      # 0x2bd64
callq 0x2130
cmpl $0x0, %eax
jne 0x29bf7
movl $0x0, 0x68(%rsp)
leaq 0x5a(%rsp), %rdi
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movq (%rax), %rsi
addq $0x4, %rsi
callq 0x2060
jmp 0x29cc6
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x80(%rsp), %rsi
addq $0x1ce6, %rsi           # imm = 0x1CE6
leaq 0x68(%rsp), %rdx
callq 0x60b0
cmpl $0x0, %eax
jne 0x29cad
movq 0x63c7(%rip), %rax      # 0x2fff8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x80(%rsp), %rax
addq $0x1ce6, %rax           # imm = 0x1CE6
movq %rax, 0x38(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
addq $0xb0, %rax
movq %rax, 0x40(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edi
callq 0x6550
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movsbl %al, %r8d
leaq 0x3276(%rip), %rsi      # 0x2cf12
movb $0x0, %al
callq 0x2140
movl $0x1, %edi
callq 0x2210
leaq 0x5a(%rsp), %rdi
movq 0x80(%rsp), %rsi
addq $0x1ce6, %rsi           # imm = 0x1CE6
callq 0x2060
movq 0x80(%rsp), %rdi
addq $0x1cec, %rdi           # imm = 0x1CEC
leaq 0x2088(%rip), %rsi      # 0x2bd64
callq 0x2130
cmpl $0x0, %eax
jne 0x29d42
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movl %eax, 0x64(%rsp)
leaq 0x54(%rsp), %rdi
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movq 0x90(%rsp), %rcx
movslq 0x6c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
addq $0x4, %rsi
callq 0x2060
jmp 0x29e11
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
movq 0x80(%rsp), %rsi
addq $0x1cec, %rsi           # imm = 0x1CEC
leaq 0x64(%rsp), %rdx
callq 0x60b0
cmpl $0x0, %eax
jne 0x29df8
movq 0x627c(%rip), %rax      # 0x2fff8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rax
addq $0x1cec, %rax           # imm = 0x1CEC
movq %rax, 0x20(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
addq $0xb0, %rax
movq %rax, 0x28(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edi
callq 0x6550
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movsbl %al, %r8d
leaq 0x312b(%rip), %rsi      # 0x2cf12
movb $0x0, %al
callq 0x2140
movl $0x1, %edi
callq 0x2210
leaq 0x54(%rsp), %rdi
movq 0x80(%rsp), %rsi
addq $0x1cec, %rsi           # imm = 0x1CEC
callq 0x2060
movl 0x68(%rsp), %eax
movl %eax, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl 0x64(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2a01c
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
movq 0x90(%rsp), %rcx
movslq 0x6c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x68(%rcx), %rcx
movslq 0x7c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl (%rcx), %eax
jge 0x2a00a
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x7c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x10, %rdi
movslq 0x74(%rsp), %rax
imulq $0x5, %rax, %rax
addq %rax, %rdi
leaq 0x2b35(%rip), %rsi      # 0x2c9c8
callq 0x2130
cmpl $0x0, %eax
jne 0x29ea2
jmp 0x29ffa
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
cmpl 0x64(%rsp), %eax
jge 0x29ff8
movl $0x0, 0x70(%rsp)
movl 0x70(%rsp), %eax
movq 0x90(%rsp), %rcx
movslq 0x6c(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x68(%rcx), %rcx
movslq 0x78(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl (%rcx), %eax
jge 0x29fe6
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x78(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x10, %rdi
movslq 0x70(%rsp), %rax
imulq $0x5, %rax, %rax
addq %rax, %rdi
leaq 0x2aa6(%rip), %rsi      # 0x2c9c8
callq 0x2130
cmpl $0x0, %eax
jne 0x29f31
jmp 0x29fd6
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x7c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x188, %rdi            # imm = 0x188
movslq 0x74(%rsp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rdi
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x68(%rax), %rax
movslq 0x78(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x188, %rsi            # imm = 0x188
movslq 0x70(%rsp), %rax
imulq $0xc, %rax, %rax
addq %rax, %rsi
callq 0x4a30
cvtss2sd %xmm0, %xmm1
movsd 0x1aec(%rip), %xmm0     # 0x2ba90
ucomisd %xmm1, %xmm0
jbe 0x29fd4
movl 0x7c(%rsp), %eax
subl 0x78(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cvtsi2sd %eax, %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x29fd6
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x29ec3
jmp 0x29fe8
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0x29ead
jmp 0x29ffa
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x29e34
jmp 0x2a00c
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x29e19
movsd 0x2b64(%rip), %xmm0     # 0x2cb88
mulsd 0x48(%rsp), %xmm0
cvtsi2sdl 0x60(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x64(%rsp), %eax
subl 0x68(%rsp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x48(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
addq $0xb0, %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rax
movslq 0x6c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x40(%rax), %edi
callq 0x6550
movq 0x10(%rsp), %rsi
movsbl %al, %edx
movl 0x68(%rsp), %ecx
leaq 0x5a(%rsp), %r8
movl 0x64(%rsp), %r9d
subl $0x1, %r9d
leaq 0x54(%rsp), %rax
movsd 0x48(%rsp), %xmm0
leaq 0x2e81(%rip), %rdi      # 0x2cf3c
movq %rax, (%rsp)
movb $0x1, %al
callq 0x20d0
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x29b66
xorl %edi, %edi
callq 0x2210
nopl (%rax)