// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/contacts.c
// Function: Get_contact_list
void Get_contact_list(int **nc1, int ***clist1, int ***cnum1, int Nres,
		      atom *atoms, struct interaction *Int_list, int N_int)
{
  int **clist=(int **)malloc(Nres*sizeof(int *));
  int **cnum=(int **)malloc(Nres*sizeof(int *));
  int *nc=(int *)malloc(Nres*sizeof(int));
  *nc1=nc; *clist1=clist; *cnum1=cnum;
  int ia, ja, n;

  for(ia=0; ia<Nres; ia++)nc[ia]=0;
  for(n=0; n<N_int; n++){
    ia=(atoms+Int_list[n].i1)->res;
    ja=(atoms+Int_list[n].i2)->res;
    if((ia>=Nres)||(ja>=Nres))continue;
    nc[ia]++; nc[ja]++;
  }

  int Ncmax=0;
  for(ia=0; ia<Nres; ia++){
    if(nc[ia]>Ncmax)Ncmax=nc[ia];
    clist[ia]=malloc((nc[ia]+1)*sizeof(int));
    cnum[ia]=malloc((nc[ia]+1)*sizeof(int));
    nc[ia]=0;
  }
  printf("Max number contact per residue: %d\n", Ncmax);

  for(n=0; n<N_int; n++){
    ia=(atoms+Int_list[n].i1)->res;
    ja=(atoms+Int_list[n].i2)->res;
    if((ia>=Nres)||(ja>=Nres))continue;
    clist[ia][nc[ia]]=ja; cnum[ia][nc[ia]]=n; nc[ia]++;
    clist[ja][nc[ja]]=ia; cnum[ja][nc[ja]]=n; nc[ja]++;
  }    
  for(ia=0; ia<Nres; ia++){
    clist[ia][nc[ia]]=-1;
    cnum[ia][nc[ia]]=-1;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r12
movq %r8, 0x18(%rsp)
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movq %rsi, (%rsp)
movq %rdi, 0x8(%rsp)
movslq %ecx, %r13
leaq (,%r13,8), %r14
movq %r14, %rdi
callq 0x21d0
movq %rax, %rbx
movq %r14, %rdi
callq 0x21d0
movq %rax, %r14
leaq (,%r13,4), %rdi
callq 0x21d0
movq %rax, %r15
movq 0x8(%rsp), %rax
movq %r15, (%rax)
movq %rbx, 0x8(%rsp)
movq (%rsp), %rax
movq %rbx, (%rax)
movq %r14, (%rsp)
movq 0x10(%rsp), %rax
movq %r14, (%rax)
movl %ebp, %r14d
testl %r13d, %r13d
jle 0x1fcb9
leaq (,%r14,4), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2110
movl 0x60(%rsp), %eax
movl %eax, %r8d
testl %eax, %eax
movq 0x18(%rsp), %rdi
jle 0x1fd0b
imulq $0xc8, %r8, %rax
xorl %ecx, %ecx
movslq (%r12,%rcx), %rdx
imulq $0x70, %rdx, %rdx
movslq 0x64(%rdi,%rdx), %rdx
cmpl %ebp, %edx
jge 0x1fcff
movslq 0x4(%r12,%rcx), %rsi
imulq $0x70, %rsi, %rsi
movl 0x64(%rdi,%rsi), %esi
cmpl %ebp, %esi
jge 0x1fcff
incl (%r15,%rdx,4)
movslq %esi, %rdx
incl (%r15,%rdx,4)
addq $0xc8, %rcx
cmpq %rcx, %rax
jne 0x1fcd2
movq %r8, 0x20(%rsp)
movl %ebp, 0x10(%rsp)
testl %ebp, %ebp
jle 0x1fd67
xorl %r13d, %r13d
xorl %ebx, %ebx
movslq (%r15,%r13,4), %rax
cmpl %ebx, %eax
cmovgl %eax, %ebx
movq %r14, %rbp
leaq 0x4(,%rax,4), %r14
movq %r14, %rdi
callq 0x21d0
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r14, %rdi
movq %rbp, %r14
callq 0x21d0
movq (%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movl $0x0, (%r15,%r13,4)
incq %r13
cmpq %r13, %rbp
jne 0x1fd1d
jmp 0x1fd69
xorl %ebx, %ebx
leaq 0x3871e(%rip), %rdi     # 0x5848e
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
cmpl $0x0, 0x60(%rsp)
movq 0x8(%rsp), %r10
movq (%rsp), %r11
movq 0x18(%rsp), %rbx
movl 0x10(%rsp), %ebp
movq 0x20(%rsp), %r13
jle 0x1fe09
addq $0x4, %r12
xorl %eax, %eax
movslq -0x4(%r12), %rcx
imulq $0x70, %rcx, %rcx
movl 0x64(%rbx,%rcx), %ecx
cmpl %ebp, %ecx
jge 0x1fdfa
movslq (%r12), %rdx
imulq $0x70, %rdx, %rdx
movl 0x64(%rbx,%rdx), %edx
cmpl %ebp, %edx
jge 0x1fdfa
movslq %ecx, %rsi
movslq %edx, %rdi
movq (%r10,%rsi,8), %r8
movslq (%r15,%rsi,4), %r9
movl %edx, (%r8,%r9,4)
movq (%r11,%rsi,8), %rdx
movslq (%r15,%rsi,4), %r8
movl %eax, (%rdx,%r8,4)
incl (%r15,%rsi,4)
movq (%r10,%rdi,8), %rdx
movslq (%r15,%rdi,4), %rsi
movl %ecx, (%rdx,%rsi,4)
movq (%r11,%rdi,8), %rcx
movslq (%r15,%rdi,4), %rdx
movl %eax, (%rcx,%rdx,4)
incl (%r15,%rdi,4)
incq %rax
addq $0xc8, %r12
cmpq %rax, %r13
jne 0x1fd9d
testl %ebp, %ebp
jle 0x1fe32
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%r10,%rax,8), %rdx
movslq (%r15,%rax,4), %rsi
movl %ecx, (%rdx,%rsi,4)
movq (%r11,%rax,8), %rdx
movslq (%r15,%rax,4), %rsi
movl %ecx, (%rdx,%rsi,4)
incq %rax
cmpq %rax, %r14
jne 0x1fe14
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)