// File: /workspace/github_c_makefile_star2_O1/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
testl %esi, %esi
jle 0x14dca
movq %rdi, %r13
movl %esi, 0x24(%rsp)
movl %esi, %eax
movq %rax, 0x30(%rsp)
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movq (%r13,%r14,8), %rax
cmpl $0x0, (%rax)
jle 0x14dba
xorl %ebx, %ebx
movq %r14, 0x18(%rsp)
movq 0x68(%rax), %rax
movq (%rax,%rbx,8), %rdi
addq $0xa, %rdi
leaq 0x4d61(%rip), %rsi      # 0x19908
callq 0x2150
testl %eax, %eax
movq %rbx, 0x10(%rsp)
jne 0x14da1
leal 0x1(%rbx), %eax
movl %eax, 0x20(%rsp)
movq %r14, %r15
cmpq %r14, %r15
movl $0x0, %ecx
cmovel 0x20(%rsp), %ecx
movq (%r13,%r15,8), %rax
cmpl (%rax), %ecx
jge 0x14d8e
movl %ecx, %ebx
movq 0x68(%rax), %rax
movq (%rax,%rbx,8), %r12
leaq 0xa(%r12), %rdi
leaq 0x4d15(%rip), %rsi      # 0x19908
callq 0x2150
testl %eax, %eax
jne 0x14c3a
movq 0x18(%rsp), %r14
movq (%r13,%r14,8), %rax
movq 0x68(%rax), %rax
movq %r15, %rcx
movq 0x10(%rsp), %r15
movq (%rax,%r15,8), %r8
addq $0x4, %r8
addq $0x4, %r12
movq %r13, %rdi
movl 0x24(%rsp), %esi
movl %r14d, %edx
movq %rcx, %rbp
movq %r12, %r9
callq 0x14de5
testl %eax, %eax
je 0x14c4b
movq %rbp, %r15
incq %rbx
movq (%r13,%r15,8), %rax
cmpl %ebx, (%rax)
jg 0x14bdf
jmp 0x14d8e
movq (%r13,%r14,8), %rdi
movl %r15d, %esi
leaq 0x533a(%rip), %r14      # 0x19f94
movq %r14, %rdx
leaq 0x2c(%rsp), %rcx
callq 0x4f78
testl %eax, %eax
je 0x14c37
movq %rbp, %r15
movq (%r13,%rbp,8), %rdi
movl %ebx, %esi
movq %r14, %rdx
leaq 0x28(%rsp), %rcx
callq 0x4f78
testl %eax, %eax
je 0x14c3a
movq 0x18(%rsp), %rbp
movq (%r13,%rbp,8), %rax
movq 0x68(%rax), %rax
movslq 0x2c(%rsp), %rcx
leaq (%rcx,%rcx,2), %rdi
shlq $0x2, %rdi
movq %r15, %r14
movq %r13, %r15
movq 0x10(%rsp), %r13
addq (%rax,%r13,8), %rdi
movl $0x188, %edx            # imm = 0x188
addq %rdx, %rdi
movq (%r15,%r14,8), %rax
movq 0x68(%rax), %rax
movslq 0x28(%rsp), %rcx
leaq (%rcx,%rcx,2), %rsi
shlq $0x2, %rsi
addq (%rax,%rbx,8), %rsi
addq %rdx, %rsi
callq 0x40d5
movss 0x4e0f(%rip), %xmm1     # 0x19af0
ucomiss %xmm0, %xmm1
jb 0x14d83
movq (%r15), %rax
movslq 0x2c(%rax), %r12
movl $0x14, %edi
callq 0x595c
movq (%r15), %rcx
movq 0xa0(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
movq (%r15), %rax
movq 0xa0(%rax), %rax
movq (%rax,%r12,8), %rdi
movq (%r15,%rbp,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%r13,8), %rsi
addq $0x4, %rsi
callq 0x2070
movq (%r15), %rax
movq 0xa0(%rax), %rax
movq (%rax,%r12,8), %rdi
addq $0x6, %rdi
movq (%r15,%r14,8), %rax
movq 0x68(%rax), %rax
movq (%rax,%rbx,8), %rsi
addq $0x4, %rsi
callq 0x2070
movq (%r15,%rbp,8), %rax
movb 0x40(%rax), %al
movq (%r15), %rcx
movq 0xa0(%rcx), %rdx
movq (%rdx,%r12,8), %rdx
movb %al, 0xe(%rdx)
movq (%r15,%r14,8), %rax
movb 0x40(%rax), %al
movb %al, 0xf(%rdx)
movl $0x0, 0x10(%rdx)
incl 0x2c(%rcx)
incl 0xc(%rsp)
movq %r15, %r13
movq %r14, %r15
jmp 0x14c3a
incq %r15
cmpq 0x30(%rsp), %r15
movq 0x18(%rsp), %r14
jne 0x14bc3
movq 0x10(%rsp), %rbx
incq %rbx
movq (%r13,%r14,8), %rax
movslq (%rax), %rcx
cmpq %rcx, %rbx
jl 0x14b94
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x14b7f
jmp 0x14dd2
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq