// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
testl %esi, %esi
jle 0x14c29
movq %rdi, %r14
movl %esi, 0xc(%rsp)
movl %esi, %eax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x8(%rsp)
movq (%r14,%r13,8), %rbx
movl (%rbx), %r15d
testl %r15d, %r15d
jle 0x14c19
xorl %ebp, %ebp
movq 0x68(%rbx), %rax
movq (%rax,%rbp,8), %rdi
addq $0xa, %rdi
leaq 0x4edc(%rip), %rsi      # 0x19918
callq 0x2150
leaq 0x1(%rbp), %rcx
movq %rcx, 0x20(%rsp)
testl %eax, %eax
jne 0x14c05
movq %r13, %r15
cmpq %r13, %r15
movl $0x0, %ecx
cmovel 0x20(%rsp), %ecx
movq (%r14,%r15,8), %rax
cmpl (%rax), %ecx
jge 0x14bf0
movl %ecx, %ebx
movq 0x68(%rax), %rax
movq (%rax,%rbx,8), %r12
leaq 0xa(%r12), %rdi
leaq 0x4e94(%rip), %rsi      # 0x19918
callq 0x2150
testl %eax, %eax
jne 0x14aba
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%rbp,8), %r8
addq $0x4, %r8
addq $0x4, %r12
movq %r14, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
movl %r15d, %ecx
movq %r12, %r9
callq 0x14c44
testl %eax, %eax
je 0x14aca
incq %rbx
movq (%r14,%r15,8), %rax
cmpl %ebx, (%rax)
jg 0x14a70
jmp 0x14bf0
movq (%r14,%r13,8), %rdi
movl %ebp, %esi
leaq 0x54c5(%rip), %r12      # 0x19f9c
movq %r12, %rdx
leaq 0x14(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
je 0x14aba
movq (%r14,%r15,8), %rdi
movl %ebx, %esi
movq %r12, %rdx
leaq 0x10(%rsp), %rcx
callq 0x4ea0
testl %eax, %eax
je 0x14aba
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movslq 0x14(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x2, %rdi
addq (%rax,%rbp,8), %rdi
movl $0x188, %edx            # imm = 0x188
addq %rdx, %rdi
movq (%r14,%r15,8), %rax
movq 0x68(%rax), %rax
movslq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rsi
shlq $0x2, %rsi
addq (%rax,%rbx,8), %rsi
addq %rdx, %rsi
callq 0x40c3
movss 0x4fb7(%rip), %xmm1     # 0x19b00
ucomiss %xmm0, %xmm1
jb 0x14aba
movq (%r14), %rax
movslq 0x2c(%rax), %r12
movl $0x14, %edi
callq 0x5880
movq (%r14), %rcx
movq 0xa0(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movq (%r14), %rax
movq 0xa0(%rax), %rax
movq (%rax,%r12,8), %rdi
movq (%r14,%r13,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%rbp,8), %rsi
addq $0x4, %rsi
callq 0x2070
movq (%r14), %rax
movq 0xa0(%rax), %rax
movq (%rax,%r12,8), %rdi
addq $0x6, %rdi
movq (%r14,%r15,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%rbx,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,%r12,8), %rdx
movb %al, 0xe(%rdx)
movq (%r14,%r15,8), %rax
movb 0x40(%rax), %al
movb %al, 0xf(%rdx)
movl $0x0, 0x10(%rdx)
incl 0x2c(%rcx)
incl 0x8(%rsp)
jmp 0x14aba
incq %r15
cmpq 0x18(%rsp), %r15
jne 0x14a55
movq (%r14,%r13,8), %rbx
movl (%rbx), %r15d
movslq %r15d, %rax
movq 0x20(%rsp), %rcx
movq %rcx, %rbp
cmpq %rax, %rcx
jl 0x14a29
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x14a17
jmp 0x14c31
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq