// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/site_dynamics.c
// Function: Binding_site_dynamics
void Binding_site_dynamics(struct Normal_Mode NM, struct Reference Ref,
			   struct residue *seq, atom *atoms,
			   char *nameout1, //int mode,
			   char *pdb, char *chain, int Nchain,
			   int Nres, char *SITES)
{
  int NMAX=1000; // Maximum number of sites
  int *site_res[NMAX], nres_site[NMAX];
  char *chain_res[NMAX], *description[NMAX], file_s[200];
  int PRINT_SITE=1;  // Print active site read in the PDB?
  printf("Reading binding sites\n");
  int N_sites=Read_sites(site_res, nres_site, chain_res, description, file_s,
			 NMAX, SITES, pdb, chain, Nchain, seq, Nres,PRINT_SITE);
  printf("%d binding sites read\n", N_sites);
  if(N_sites==0)return;

  // Extract c_alpha
  char SEL[4]="CA"; float mass=0;
  int Nref=Ref.N_ref, iref[Nref], iatom[Nref], atomres[Nref];
  int Na=Extract_atoms(iref, iatom, atomres, seq, &mass, atoms, Ref, SEL);
  if(Na!=Nres){
    printf("WARNING, %d residues but %d representative atoms", Nres, Na);
    printf(" found in Binding_site_dynamics\n");
  }

  char nameout[200]; int i, a, k;
  sprintf(nameout, "%s_sites_dynamics.dat", nameout1);
  FILE *file_out=fopen(nameout, "w");
  fprintf(file_out, "# read binding sites in file %s\n", file_s);
  float lambda[3], d2[3];
  float **v=Allocate_mat2_f(3, 3);
  fprintf(file_out, "# 1=<d>^2 2=<d>^2_x 3=<d>^2_y 4=<d>^2_z "); k=5;
  for(a=0; a<3; a++){
    fprintf(file_out,
	    " %d=projection_%d %d=v%d_x %d=v%d_y %d=v%d_z",
	    k,a,k+1,a,k+2,a,k+3,a); k+=4;
  }
  fprintf(file_out, "\n");
  for(i=0; i<N_sites; i++){
    Eigen_directions(d2, lambda, v,
		     site_res[i], nres_site[i], chain_res[i], NM,
		     atomres, iref);
    fprintf(file_out, "# site %s\n", description[i]);
    float sum=d2[0]+d2[1]+d2[2];
    fprintf(file_out, "%.3g  %.3f %.3f %.3f  ",
	    sum, d2[0]/sum, d2[1]/sum, d2[2]/sum);
    for(a=0; a<3; a++){
      fprintf(file_out, "%.3g  %.3f %.3f %.3f    ",
	      lambda[a], v[a][0], v[a][1], v[a][2]);
    }
    fprintf(file_out, "\n");
  }
  printf("Writing %s\n", nameout);

  Empty_matrix_f(v,3); //modyves: v was never freed
  for(i=0; i<N_sites; i++){
    free(site_res[i]);
    free(chain_res[i]);
    if(description[i])free(description[i]);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2c0, %rsp            # imm = 0x2C0
movq 0x118(%rbp), %rax
movl 0x110(%rbp), %eax
leaq 0xe0(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq %rdx, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movl %r9d, -0x4c(%rbp)
movl $0x3e8, -0x50(%rbp)     # imm = 0x3E8
movl -0x50(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x2a0(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
movl -0x50(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x298(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl -0x50(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x290(%rbp)
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movl -0x50(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x288(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl $0x1, -0x144(%rbp)
leaq 0x1b231(%rip), %rdi     # 0x82a5c
movb $0x0, %al
callq 0x10d0
movq -0x2a0(%rbp), %rdi
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rdx
movq -0x288(%rbp), %rcx
leaq -0x140(%rbp), %r8
movl -0x50(%rbp), %r9d
movq 0x118(%rbp), %r12
movq -0x40(%rbp), %r15
movq -0x48(%rbp), %r14
movl -0x4c(%rbp), %ebx
movq -0x28(%rbp), %r11
movl 0x110(%rbp), %r10d
movl -0x144(%rbp), %eax
subq $0x40, %rsp
movq %r12, (%rsp)
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl %ebx, 0x18(%rsp)
movq %r11, 0x20(%rsp)
movl %r10d, 0x28(%rsp)
movl %eax, 0x30(%rsp)
callq 0x67e40
addq $0x40, %rsp
movl %eax, -0x148(%rbp)
movl -0x148(%rbp), %esi
leaq 0x1b1b7(%rip), %rdi     # 0x82a73
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x148(%rbp)
jne 0x678db
movl $0x1, -0x14c(%rbp)
jmp 0x67e26
movq -0x2b0(%rbp), %rax
movl $0x4143, -0x150(%rbp)   # imm = 0x4143
movl $0x0, -0x154(%rbp)
movl (%rax), %ecx
movl %ecx, -0x158(%rbp)
movl -0x158(%rbp), %ecx
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rdi
subq %rdx, %rdi
movq %rdi, -0x2c0(%rbp)
movq %rdi, %rsp
movq %rcx, -0x160(%rbp)
movl -0x158(%rbp), %ecx
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rsi
subq %rdx, %rsi
movq %rsi, %rsp
movq %rcx, -0x168(%rbp)
movl -0x158(%rbp), %ecx
leaq 0xf(,%rcx,4), %r8
andq $-0x10, %r8
movq %rsp, %rdx
subq %r8, %rdx
movq %rdx, -0x2b8(%rbp)
movq %rdx, %rsp
movq %rcx, -0x170(%rbp)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r9
leaq -0x150(%rbp), %r8
subq $0x40, %rsp
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movq %r8, 0x30(%rax)
leaq -0x154(%rbp), %r8
callq 0x61db0
addq $0x40, %rsp
movl %eax, -0x174(%rbp)
movl -0x174(%rbp), %eax
cmpl 0x110(%rbp), %eax
je 0x679ee
movl 0x110(%rbp), %esi
movl -0x174(%rbp), %edx
leaq 0x1b6ac(%rip), %rdi     # 0x83085
movb $0x0, %al
callq 0x10d0
leaq 0x1b6cf(%rip), %rdi     # 0x830b6
movb $0x0, %al
callq 0x10d0
leaq -0x240(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1b6d7(%rip), %rsi     # 0x830d7
movb $0x0, %al
callq 0x1200
leaq -0x240(%rbp), %rdi
leaq 0x1495d(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rdi
leaq -0x140(%rbp), %rdx
leaq 0x1b09c(%rip), %rsi     # 0x82ad2
movb $0x0, %al
callq 0x1150
movl $0x3, %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0x278(%rbp)
movq -0x258(%rbp), %rdi
leaq 0x1b68f(%rip), %rsi     # 0x830ed
movb $0x0, %al
callq 0x1150
movl $0x5, -0x24c(%rbp)
movl $0x0, -0x248(%rbp)
cmpl $0x3, -0x248(%rbp)
jge 0x67b16
movq -0x258(%rbp), %rdi
movl -0x24c(%rbp), %edx
movl -0x248(%rbp), %ecx
movl -0x24c(%rbp), %r8d
addl $0x1, %r8d
movl -0x248(%rbp), %r9d
movl -0x24c(%rbp), %ebx
addl $0x2, %ebx
movl -0x248(%rbp), %r11d
movl -0x24c(%rbp), %r10d
addl $0x3, %r10d
movl -0x248(%rbp), %eax
leaq 0x1b643(%rip), %rsi     # 0x83116
subq $0x20, %rsp
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x1150
addq $0x20, %rsp
movl -0x24c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x24c(%rbp)
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x67a79
movq -0x258(%rbp), %rdi
leaq 0x16554(%rip), %rsi     # 0x7e078
movb $0x0, %al
callq 0x1150
movl $0x0, -0x244(%rbp)
movl -0x244(%rbp), %eax
cmpl -0x148(%rbp), %eax
jge 0x67d71
movq -0x2b8(%rbp), %r10
movq -0x2c0(%rbp), %r11
movq -0x2a8(%rbp), %rsi
movq -0x290(%rbp), %rax
movq -0x298(%rbp), %rcx
movq -0x2a0(%rbp), %rdi
leaq -0x270(%rbp), %rdx
movq %rdx, -0x2d0(%rbp)
leaq -0x264(%rbp), %rdx
movq %rdx, -0x2d8(%rbp)
movq -0x278(%rbp), %rdx
movslq -0x244(%rbp), %r8
movq (%rdi,%r8,8), %rdi
movq %rdi, -0x2c8(%rbp)
movslq -0x244(%rbp), %rdi
movl (%rcx,%rdi,4), %r8d
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %r9
subq $0xe0, %rsp
movq %rsp, %rax
movl $0x1a, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq -0x2d8(%rbp), %rsi
movq -0x2d0(%rbp), %rdi
movq -0x2c8(%rbp), %rcx
movq %r11, 0xd8(%rax)
movq %r10, 0xd0(%rax)
callq 0x68240
movq -0x288(%rbp), %rax
addq $0xe0, %rsp
movq -0x258(%rbp), %rdi
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x1b523(%rip), %rsi     # 0x83143
movb $0x0, %al
callq 0x1150
movss -0x270(%rbp), %xmm0
addss -0x26c(%rbp), %xmm0
addss -0x268(%rbp), %xmm0
movss %xmm0, -0x27c(%rbp)
movq -0x258(%rbp), %rdi
movss -0x27c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x270(%rbp), %xmm1
divss -0x27c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x26c(%rbp), %xmm2
divss -0x27c(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x268(%rbp), %xmm3
divss -0x27c(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x1b4b1(%rip), %rsi     # 0x8314e
movb $0x4, %al
callq 0x1150
movl $0x0, -0x248(%rbp)
cmpl $0x3, -0x248(%rbp)
jge 0x67d48
movq -0x258(%rbp), %rdi
movslq -0x248(%rbp), %rax
movss -0x264(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x278(%rbp), %rax
movslq -0x248(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq -0x278(%rbp), %rax
movslq -0x248(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss 0x4(%rax), %xmm2
cvtss2sd %xmm2, %xmm2
movq -0x278(%rbp), %rax
movslq -0x248(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movss 0x8(%rax), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x1b438(%rip), %rsi     # 0x83165
movb $0x4, %al
callq 0x1150
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x67cae
movq -0x258(%rbp), %rdi
leaq 0x16322(%rip), %rsi     # 0x7e078
movb $0x0, %al
callq 0x1150
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x67b35
leaq -0x240(%rbp), %rsi
leaq 0xf76f(%rip), %rdi      # 0x774ee
movb $0x0, %al
callq 0x10d0
movq -0x278(%rbp), %rdi
movl $0x3, %esi
callq 0x69240
movl $0x0, -0x244(%rbp)
movl -0x244(%rbp), %eax
cmpl -0x148(%rbp), %eax
jge 0x67e1c
movq -0x2a0(%rbp), %rax
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movq -0x290(%rbp), %rax
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movq -0x288(%rbp), %rax
movslq -0x244(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x67e09
movq -0x288(%rbp), %rax
movslq -0x244(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
jmp 0x67e0b
movl -0x244(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x244(%rbp)
jmp 0x67da1
movl $0x0, -0x14c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, %rsp
leaq -0x20(%rbp), %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)