// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %r8, 0x20(%rsp)
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movq %rsi, (%rsp)
movq %rdi, 0x8(%rsp)
movslq %ecx, %r12
leaq (,%r12,8), %r14
movq %r14, %rdi
callq 0x21d0
movq %rax, %rbx
movq %r14, %rdi
callq 0x21d0
movq %rax, %r14
leaq (,%r12,4), %rdi
callq 0x21d0
movq %rax, %r13
movq 0x8(%rsp), %rax
movq %r13, (%rax)
movq %rbx, 0x8(%rsp)
movq (%rsp), %rax
movq %rbx, (%rax)
movq %r14, (%rsp)
movq 0x10(%rsp), %rax
movq %r14, (%rax)
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %r9d
cmovgl %ebp, %r9d
cmpq %rax, %r9
je 0x1da02
andl $0x0, (%r13,%rax,4)
incq %rax
jmp 0x1d9f2
xorl %eax, %eax
movl 0x60(%rsp), %r8d
testl %r8d, %r8d
cmovlel %eax, %r8d
imulq $0xc8, %r8, %rcx
movq 0x20(%rsp), %rdi
cmpq %rax, %rcx
je 0x1da58
movslq (%r15,%rax), %rdx
imulq $0x70, %rdx, %rdx
movslq 0x64(%rdi,%rdx), %rdx
cmpl %ebp, %edx
jge 0x1da50
movslq 0x4(%r15,%rax), %rsi
imulq $0x70, %rsi, %rsi
movl 0x64(%rdi,%rsi), %esi
cmpl %ebp, %esi
jge 0x1da50
incl (%r13,%rdx,4)
movslq %esi, %rdx
incl (%r13,%rdx,4)
addq $0xc8, %rax
jmp 0x1da1c
movl %ebp, 0x1c(%rsp)
movq %r8, 0x10(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %r9, %rbp
cmpq %r12, %r9
je 0x1daaf
movslq (%r13,%r12,4), %rax
cmpl %ebx, %eax
cmovgl %eax, %ebx
leaq 0x4(,%rax,4), %r14
movq %r14, %rdi
callq 0x21d0
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
movq %r14, %rdi
callq 0x21d0
movq (%rsp), %rcx
movq %rax, (%rcx,%r12,8)
andl $0x0, (%r13,%r12,4)
incq %r12
movq %rbp, %r9
jmp 0x1da66
leaq 0x348f8(%rip), %rdi     # 0x523ae
xorl %r14d, %r14d
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
addq $0x4, %r15
movq 0x8(%rsp), %r9
movq (%rsp), %r10
movq 0x20(%rsp), %r11
movq 0x10(%rsp), %rbx
movl 0x1c(%rsp), %r12d
cmpq %r14, %rbx
je 0x1db55
movslq -0x4(%r15), %rax
imulq $0x70, %rax, %rax
movl 0x64(%r11,%rax), %eax
cmpl %r12d, %eax
jge 0x1db49
movslq (%r15), %rcx
imulq $0x70, %rcx, %rcx
movl 0x64(%r11,%rcx), %ecx
cmpl %r12d, %ecx
jge 0x1db49
movslq %eax, %rdx
movslq %ecx, %rsi
movq (%r9,%rdx,8), %rdi
movslq (%r13,%rdx,4), %r8
movl %ecx, (%rdi,%r8,4)
movq (%r10,%rdx,8), %rcx
movslq (%r13,%rdx,4), %rdi
movl %r14d, (%rcx,%rdi,4)
incl (%r13,%rdx,4)
movq (%r9,%rsi,8), %rcx
movslq (%r13,%rsi,4), %rdx
movl %eax, (%rcx,%rdx,4)
movq (%r10,%rsi,8), %rax
movslq (%r13,%rsi,4), %rcx
movl %r14d, (%rax,%rcx,4)
incl (%r13,%rsi,4)
incq %r14
addq $0xc8, %r15
jmp 0x1dade
xorl %eax, %eax
cmpq %rax, %rbp
je 0x1db7b
movq (%r9,%rax,8), %rcx
movslq (%r13,%rax,4), %rdx
orl $-0x1, (%rcx,%rdx,4)
movq (%r10,%rax,8), %rcx
movslq (%r13,%rax,4), %rdx
orl $-0x1, (%rcx,%rdx,4)
incq %rax
jmp 0x1db57
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop