// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/nma.c
// Function: Principal_axis_frame
void Principal_axis_frame(atom *atoms, int N_atoms, int *atom_ref,
			  int N_atom_ref,struct axe *axes, int N_axes,
			  int ANISOU)
{
  double **inertia=Allocate_mat2_d(3,3);
  double **rotation=Allocate_mat2_d(3,3);
  double **corr=Allocate_mat2_d(3,3);
  double r_ave[3], ri[3];
  int i, j;

  /******************************************************************/
  /*              Transforming to principal axis frame              */
  /******************************************************************/
  // Compute center of mass and inertia tensor for reference atoms
  Inertia_tensor_old(atoms, atom_ref, N_atom_ref, r_ave, corr, inertia);

  // Transform all atoms and axes to principal axis frame of references
  Get_rotation(inertia, rotation);
  for(i=0; i<N_atoms; i++){
    double *r=atoms[i].r;
    for(j=0; j<3; j++)ri[j]=r[j];
    Subtract_vector_3_d(ri, ri, r_ave);
    Rotate_d(ri, rotation);
    for(j=0; j<3; j++)r[j]=ri[j];
  }
  for(i=0; i<N_axes; i++){
    Rotate_d(axes[i].rot, rotation);
    Subtract_vector_3_d(axes[i].offset, axes[i].offset, r_ave);
    Rotate_d(axes[i].offset, rotation);
  }

  // Transfrom anisotropic structure factors
  if(ANISOU){
    float rot[3][3];
    for(i=0; i<3; i++)for(j=0; j<3; j++)rot[i][j]=rotation[i][j];
    for(i=0; i<N_atoms; i++){
      Transform_matrix(atoms[i].anisou, (float **)rot);
    }
  }

  // Cleaning
  Empty_matrix_d(inertia, 3);
  Empty_matrix_d(corr, 3);
  Empty_matrix_d(rotation, 3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x694a0
movq %rax, -0x38(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x694a0
movq %rax, -0x40(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x694a0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
leaq -0x60(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x36bc0
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x36f80
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x369fb
movq -0x8(%rbp), %rax
movslq -0x84(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x88(%rbp)
cmpl $0x3, -0x88(%rbp)
jge 0x36983
movq -0x90(%rbp), %rax
movslq -0x88(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movslq -0x88(%rbp), %rax
movsd %xmm0, -0x80(%rbp,%rax,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x36949
leaq -0x80(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x14f40
leaq -0x80(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x14da0
movl $0x0, -0x88(%rbp)
cmpl $0x3, -0x88(%rbp)
jge 0x369e5
movslq -0x88(%rbp), %rax
movsd -0x80(%rbp,%rax,8), %xmm0
movq -0x90(%rbp), %rax
movslq -0x88(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x369ab
jmp 0x369e7
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x36917
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x36aa7
movq -0x28(%rbp), %rdi
movslq -0x84(%rbp), %rax
imulq $0x158, %rax, %rax      # imm = 0x158
addq %rax, %rdi
addq $0x48, %rdi
movq -0x40(%rbp), %rsi
callq 0x14da0
movq -0x28(%rbp), %rdi
movslq -0x84(%rbp), %rax
imulq $0x158, %rax, %rax      # imm = 0x158
addq %rax, %rdi
addq $0x30, %rdi
movq -0x28(%rbp), %rsi
movslq -0x84(%rbp), %rax
imulq $0x158, %rax, %rax      # imm = 0x158
addq %rax, %rsi
addq $0x30, %rsi
leaq -0x60(%rbp), %rdx
callq 0x14f40
movq -0x28(%rbp), %rdi
movslq -0x84(%rbp), %rax
imulq $0x158, %rax, %rax      # imm = 0x158
addq %rax, %rdi
addq $0x30, %rdi
movq -0x40(%rbp), %rsi
callq 0x14da0
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x36a05
cmpl $0x0, 0x10(%rbp)
je 0x36b85
movl $0x0, -0x84(%rbp)
cmpl $0x3, -0x84(%rbp)
jge 0x36b3b
movl $0x0, -0x88(%rbp)
cmpl $0x3, -0x88(%rbp)
jge 0x36b28
movq -0x40(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x88(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movslq -0x84(%rbp), %rcx
leaq -0xc0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x88(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x36ace
jmp 0x36b2a
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x36abb
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x36b83
movq -0x8(%rbp), %rdi
movslq -0x84(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
addq $0x20, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x15120
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x36b45
jmp 0x36b85
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x692a0
movq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x692a0
movq -0x40(%rbp), %rdi
movl $0x3, %esi
callq 0x692a0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)