// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/nma.c
// Function: Set_reference
int Set_reference(// Output:
		  struct Reference *Ref,
		  // Input:
		  int ini_ref, char *SEL, atom *atoms,
		  int ini_atom, int natoms)
{
  // Set reference atoms
  Ref->atom_num=malloc(natoms*sizeof(int));
  int N_ref=
    Select_atoms(Ref->atom_num+ini_ref, atoms+ini_atom, natoms, SEL);
  Ref->N_ref=N_ref;
  Ref->N_Cart=3*N_ref;
  printf("%d atoms out of %d selected for kinetic energy (%s)\n",
	 N_ref, natoms, SEL);
  Ref->mass_atom=malloc(N_ref*sizeof(float));
  Ref->mass_coord=malloc(Ref->N_Cart*sizeof(float));
  Ref->mass_sqrt=malloc(Ref->N_Cart*sizeof(float));

  float *ma=Ref->mass_atom, *mc=Ref->mass_coord, *ms=Ref->mass_sqrt;
  int *a_num=Ref->atom_num;
  double mass_sum=0;
  for(int i=ini_ref; i<ini_ref+N_ref; i++){
    (*a_num)+=ini_atom;
    (*ma) = Mass(atoms+(*a_num));
    mass_sum+=(*ma);
    for(int j=0; j<3; j++){*mc = *ma; *ms=sqrt(*ma); mc++; ms++;}
    ma++; a_num++;
  }
  Ref->mass_sum=mass_sum;
  return(N_ref);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %ebx
movl %r8d, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r15
movslq %r9d, %r14
leaq (,%r14,4), %rdi
callq 0x21d0
movq %rax, 0x28(%r15)
movslq 0x10(%rsp), %rdx
testl %r14d, %r14d
movq %rdx, 0x28(%rsp)
movq %r12, 0x38(%rsp)
movq %rbp, 0x18(%rsp)
jle 0x25cbf
movslq %ebp, %rcx
leaq (%rax,%rcx,4), %r14
imulq $0x70, %rdx, %rbp
addq %r12, %rbp
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x18(%rbp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x27218
testl %eax, %eax
je 0x25cb1
movq 0x8(%rsp), %rax
cltq
movl %r12d, (%r14,%rax,4)
incl %eax
movq %rax, 0x8(%rsp)
addq $0x70, %rbp
incl %r12d
cmpl %r12d, %ebx
jne 0x25c8c
jmp 0x25cc8
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %r12
movl %r12d, (%r15)
leal (%r12,%r12,2), %eax
movl %eax, 0x4(%r15)
leaq 0x3309c(%rip), %rdi     # 0x58d7b
movl %r12d, %esi
movl %ebx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x20f0
movslq %r12d, %r14
leaq (,%r14,4), %rdi
callq 0x21d0
movq %rax, %r13
movq %rax, 0x10(%r15)
movslq 0x4(%r15), %rbx
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rbp
movq %rax, 0x18(%r15)
movq %rbx, %rdi
callq 0x21d0
movq %rax, 0x20(%r15)
testl %r14d, %r14d
jle 0x25dfe
movq %rax, %rbx
movq 0x18(%rsp), %rax
leal (%r12,%rax), %ecx
movl %ecx, 0x24(%rsp)
movq %r15, 0x30(%rsp)
movq 0x28(%r15), %r14
xorps %xmm0, %xmm0
movq 0x28(%rsp), %rcx
movsd %xmm0, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movslq (%r14), %rax
addq %rcx, %rax
movl %eax, (%r14)
imulq $0x70, %rax, %rdi
addq 0x38(%rsp), %rdi
callq 0x25e79
movss %xmm0, (%r13)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
movss (%r13), %xmm0
movss %xmm0, (%rbp,%r15,4)
ucomiss 0x2b26e(%rip), %xmm0    # 0x5100c
jb 0x25da6
sqrtss %xmm0, %xmm0
jmp 0x25dab
callq 0x21c0
movss %xmm0, (%rbx,%r15,4)
incq %r15
addq $-0x4, %r12
cmpl $0x3, %r15d
jne 0x25d8a
movsd 0x10(%rsp), %xmm0
addsd 0x40(%rsp), %xmm0
addq $0x4, %r13
addq $0x4, %r14
movq 0x18(%rsp), %rax
incl %eax
subq %r12, %rbx
subq %r12, %rbp
cmpl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
jl 0x25d52
cvtsd2ss %xmm0, %xmm0
movq 0x30(%rsp), %r15
movq 0x8(%rsp), %r12
jmp 0x25e01
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%r15)
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq