// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/mutation.c
// Function: Match_atoms
void  Match_atoms(int *ref_atom, atom *atoms, int natoms,
		  int *atom_ref, int N_ref)
{
  /* For every atom i=1,natoms ref_atom[i] is the index of the reference
     atom that is closest to i */
  int i; for(i=0; i<natoms; i++)ref_atom[i]=-1;
  for(i=0; i<N_ref; i++)ref_atom[atom_ref[i]]=i;
  int Nr1=N_ref-1, ini_r=0, n=0;
  for(i=0; i<natoms; i++){
    if(ref_atom[i]>=0)continue;
    n++;
    atom *atom=atoms+i, *atom2;
    while((ini_r<Nr1)&&(atoms[atom_ref[ini_r]].res<atom->res))ini_r++;
    if(atoms[atom_ref[ini_r]].res != atom->res){
      printf("ERROR unmatch_atom in residue %c%d\n", atom->aa, atom->res);
      exit(8);
    }
    float d2_min=1000; int ir=ini_r, ir_min=-1;
    while(ir<N_ref){
      atom2=atoms+atom_ref[ir];
      if(atom2->res==atom->res){
	float d2=Distance_square(atom->r, atom2->r);
	if((d2<d2_min)||(ir_min<0)){d2_min=d2; ir_min=ir;}
      }
      ir++;
    }
    if(ir_min<0){
      printf("ERROR, reference atom %d in atom %d residue %c%d not valid\n",
	     ir_min, i, atom->aa, atom->res);
    }
    ref_atom[i]=ir_min;
  }
  if((N_ref+n)!=natoms){
    printf("ERROR, N_ref+%d=%d atoms matched over %d\n",
	   n, N_ref+n, natoms); exit(8);
  }
  if(0){
    for(i=0; i<natoms; i++){
      atom *atom=atoms+i;
      printf("%d %s(%c%d) ", i, atom->name, atom->aa, atom->res);
      int j=atom_ref[ref_atom[i]]; atom=atoms+j;
      printf(" ref: %d  %s(%c%d)\n", j, atom->name, atom->aa, atom->res);
    }
    exit(8);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x57654
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x57632
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x57684
movl -0x28(%rbp), %edx
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x28(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x5765b
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x57846
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x576c1
jmp 0x57838
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x30(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2c(%rbp), %ecx
movb %al, -0x59(%rbp)
jge 0x57711
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x64(%rcx), %eax
setl %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x5771a
jmp 0x57725
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x576dd
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x30(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x64(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x64(%rcx), %eax
je 0x5776f
movq -0x40(%rbp), %rax
movsbl 0x68(%rax), %esi
movq -0x40(%rbp), %rax
movl 0x64(%rax), %edx
leaq 0x2a33f(%rip), %rdi     # 0x81a9d
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movss 0x24c69(%rip), %xmm0    # 0x7c3e0
movss %xmm0, -0x4c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl -0x50(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x57800
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x50(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x64(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x64(%rcx), %eax
jne 0x577f5
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x1ae70
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm1
movss -0x4c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x577e3
cmpl $0x0, -0x54(%rbp)
jge 0x577f3
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x577f5
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x57789
cmpl $0x0, -0x54(%rbp)
jge 0x5782a
movl -0x54(%rbp), %esi
movl -0x28(%rbp), %edx
movq -0x40(%rbp), %rax
movsbl 0x68(%rax), %ecx
movq -0x40(%rbp), %rax
movl 0x64(%rax), %r8d
leaq 0x2a29e(%rip), %rdi     # 0x81ac1
movb $0x0, %al
callq 0x10d0
movl -0x54(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x576a2
movl -0x24(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x57875
movl -0x34(%rbp), %esi
movl -0x24(%rbp), %edx
addl -0x34(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq 0x2a299(%rip), %rdi     # 0x81afd
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)