// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/ssbond.c
// Function: SSBond
int SSBond(CHAIN **Chain, int NChain)
{

  register int Res1, Res2, Cn1, Cn2;
  int S1, S2, Bn, Cnt=0;
  
  for( Cn1=0; Cn1<NChain; Cn1++ )
    for( Res1=0; Res1<Chain[Cn1]->NRes; Res1++ ) {
      if( strcmp(Chain[Cn1]->Rsd[Res1]->ResType,"CYS") )
	continue;
      for( Cn2=Cn1; Cn2<NChain; Cn2++ )
	for( Res2 = ( (Cn2 == Cn1)? Res1+1 : 0) ; Res2<Chain[Cn2]->NRes; Res2++ ) {
	  if( strcmp(Chain[Cn2]->Rsd[Res2]->ResType,"CYS") )
	    continue;
	  
	  if( !ExistSSBond(Chain,NChain,Cn1,Cn2,
			   Chain[Cn1]->Rsd[Res1]->PDB_ResNumb,
			   Chain[Cn2]->Rsd[Res2]->PDB_ResNumb) && 
	     FindAtom(Chain[Cn1],Res1,"SG",&S1) && FindAtom(Chain[Cn2],Res2,"SG",&S2) &&
	     Dist(Chain[Cn1]->Rsd[Res1]->Coord[S1],
		  Chain[Cn2]->Rsd[Res2]->Coord[S2]) <= SSDIST ) {
	    Bn = Chain[0]->NBond;
	    Chain[0]->SSbond[Bn] =  (SSBOND *)ckalloc(sizeof(SSBOND));
	    strcpy(Chain[0]->SSbond[Bn]->PDB_ResNumb1,Chain[Cn1]->Rsd[Res1]->PDB_ResNumb);
	    strcpy(Chain[0]->SSbond[Bn]->PDB_ResNumb2,Chain[Cn2]->Rsd[Res2]->PDB_ResNumb);
	    Chain[0]->SSbond[Bn]->ChainId1 = Chain[Cn1]->Id;
	    Chain[0]->SSbond[Bn]->ChainId2 = Chain[Cn2]->Id;
	    Chain[0]->SSbond[Bn]->AsnSource = Stride;
	    Chain[0]->NBond++;
	    Cnt++;
	  }
	}
    }
  
  return(Cnt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
xorl %r13d, %r13d
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
movq %rax, 0x18(%rsp)
movl %esi, 0xc(%rsp)
movl %esi, %eax
movq %rax, 0x28(%rsp)
movl $0x0, 0x8(%rsp)
cmpq 0x18(%rsp), %r13
je 0x1473a
xorl %r12d, %r12d
movq (%r14,%r13,8), %rbx
movslq (%rbx), %r15
cmpq %r15, %r12
jge 0x14732
movq 0x68(%rbx), %rax
movq (%rax,%r12,8), %rdi
addq $0xa, %rdi
leaq 0x43a1(%rip), %rsi      # 0x18918
callq 0x2150
incq %r12
testl %eax, %eax
jne 0x1455b
movl %r12d, %eax
movq %rax, 0x20(%rsp)
leaq -0x1(%r12), %rax
movq %rax, 0x30(%rsp)
movq %r13, %r15
cmpq 0x28(%rsp), %r15
je 0x14554
cmpq %r13, %r15
movl $0x0, %ebp
cmoveq 0x20(%rsp), %rbp
movq (%r14,%r15,8), %rax
movslq (%rax), %rcx
cmpq %rcx, %rbp
jge 0x1472a
movq 0x68(%rax), %rax
movq (%rax,%rbp,8), %rbx
leaq 0xa(%rbx), %rdi
leaq 0x4348(%rip), %rsi      # 0x18918
callq 0x2150
testl %eax, %eax
jne 0x14607
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movq -0x8(%rax,%r12,8), %r8
addq $0x4, %r8
addq $0x4, %rbx
movq %r14, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
movl %r15d, %ecx
movq %rbx, %r9
callq 0x1474d
testl %eax, %eax
je 0x1460c
incq %rbp
jmp 0x145ad
movq (%r14,%r13,8), %rdi
movq 0x30(%rsp), %rsi
leaq 0x4950(%rip), %rbx      # 0x18f6c
movq %rbx, %rdx
leaq 0x14(%rsp), %rcx
callq 0x4777
testl %eax, %eax
je 0x14607
movq (%r14,%r15,8), %rdi
movl %ebp, %esi
movq %rbx, %rdx
leaq 0x10(%rsp), %rcx
callq 0x4777
testl %eax, %eax
je 0x14607
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0xc, %rcx, %rdi
addq -0x8(%rax,%r12,8), %rdi
movl $0x188, %edx            # imm = 0x188
addq %rdx, %rdi
movq (%r14,%r15,8), %rax
movq 0x68(%rax), %rax
movslq 0x10(%rsp), %rcx
imulq $0xc, %rcx, %rsi
addq (%rax,%rbp,8), %rsi
addq %rdx, %rsi
callq 0x3abc
movss 0x4479(%rip), %xmm1     # 0x18b00
ucomiss %xmm0, %xmm1
jb 0x14607
movq (%r14), %rax
movslq 0x2c(%rax), %rbx
pushq $0x14
popq %rdi
callq 0x50f4
movq (%r14), %rcx
movq 0xa0(%rcx), %rcx
movq %rax, (%rcx,%rbx,8)
movq (%r14), %rax
movq 0xa0(%rax), %rax
movq (%rax,%rbx,8), %rdi
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movq -0x8(%rax,%r12,8), %rsi
addq $0x4, %rsi
callq 0x2070
movq (%r14), %rax
movq 0xa0(%rax), %rax
movq (%rax,%rbx,8), %rdi
addq $0x6, %rdi
movq (%r14,%r15,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%rbp,8), %rsi
addq $0x4, %rsi
callq 0x2070
movq (%r14,%r13,8), %rax
movb 0x40(%rax), %al
movq (%r14), %rcx
movq 0xa0(%rcx), %rdx
movq (%rdx,%rbx,8), %rdx
movb %al, 0xe(%rdx)
movq (%r14,%r15,8), %rax
movb 0x40(%rax), %al
movb %al, 0xf(%rdx)
andl $0x0, 0x10(%rdx)
incl 0x2c(%rcx)
incl 0x8(%rsp)
jmp 0x14607
incq %r15
jmp 0x14598
incq %r13
jmp 0x14546
movl 0x8(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq