// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/simulation.c
// Function: Switch_bonds
float Switch_bonds(struct bond *bonds, int naxes, char *prots,
		   struct ali_atoms ali_a,
		   atom *atoms1, int natoms1, struct residue *seq1,
		   atom *atoms2, int natoms2, struct residue *seq2)
{
  // Compute chimera conformations switching internal degrees of freedom
  Set_bonds_measure(bonds, natoms1, atoms1);

  struct bond *bonds2=Set_bonds_topology(natoms2, atoms2, seq2);
  Set_bonds_measure(bonds2, natoms2, atoms2);

  int i, k, N_ref=ali_a.N_ref;
  printf("Switching internal coordinates for %d (all) and %d (ref) atoms ",
	 natoms1, N_ref);
  printf("to match %d (all) atoms of str.2\n", natoms2);

  // Compute differences of internal coordinates
  Internal_differences(bonds, bonds2, natoms1, prots);

  // RMSD all atoms
  int ncart1=3*natoms1, ncart2=3*natoms2;
  float coord1[ncart1]; Put_coord(coord1, bonds, natoms1);
  float coord2[ncart2]; Put_coord(coord2, bonds2, natoms2);
  float coord_new[ncart1];
  int natom=natoms1; if(natoms2<natom)natom=natoms2;
  float mass[natom]; for(i=0; i<natom; i++)mass[i]=1;
  float RMSD=rmsd_mclachlan_f(coord1, coord2, mass, natom);

  // Reference coordinates
  int Ncart=3*N_ref;
  float coord_ref1[Ncart], coord_ref2[Ncart], coord_ref[Ncart];
  Write_ref_coord(coord_ref2, N_ref, coord2, ali_a.ali2);
  Write_ref_coord(coord_ref1, N_ref, coord1, ali_a.ali1);
  RMSD=rmsd_mclachlan_f(coord_ref1, coord_ref2, ali_a.mass, N_ref);
  printf("RMSD ini end: %.3f\n", RMSD);

  char name_pdb[100]; sprintf(name_pdb, "Chimera_%s.pdb", prots);
  FILE *file_pdb=fopen(name_pdb, "w");
  Print_PDB(file_pdb,atoms1,natoms1,coord1,seq1,0,0.00);

  int same=1;
  for(k=1; k<=3; k++){
    printf("Switching internal coordinates of type <= %d\n", k);
    Set_bonds_measure(bonds, natoms1, atoms1);
    Change_internal(NULL, 0, bonds, bonds2, natoms1, k, same);
    Build_up(bonds, natoms1, NULL, naxes);
    Put_coord(coord_new, bonds, natoms1);
    Write_ref_coord(coord_ref, N_ref, coord_new, ali_a.ali1);
    RMSD=rmsd_mclachlan_f(coord_ref1, coord_ref, mass, N_ref);
    printf("RMSD with struct 1: %.3f\n", RMSD);
    RMSD=rmsd_mclachlan_f(coord_ref2, coord_ref, mass, N_ref);
    printf("RMSD with struct 2: %.3f\n", RMSD);
    rmsd_mclachlan_f(coord1, coord_new, mass, natom);
    Print_PDB(file_pdb, atoms1, natoms1, coord_new, seq1, k, RMSD);
  }
  //Print_PDB(file_pdb, atoms2, natoms2, coord2, seq2, k, 0.00);
  printf("Writing %s\n", name_pdb);
  fclose(file_pdb);

  //Compare_build_up(bonds, natoms1, NULL, naxes, bonds2);
  free(bonds2);
  return(RMSD);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r9, -0x90(%rbp)
movl %r8d, %r12d
movq %rdx, %r15
movl %esi, -0x64(%rbp)
movq %rdi, %r13
movl 0x38(%rbp), %ebx
movq 0x30(%rbp), %r14
movl %r8d, %esi
movq %rcx, -0x88(%rbp)
movq %rcx, %rdx
callq 0x1512b
movl %ebx, %edi
movq %r14, %rsi
movq 0x40(%rbp), %rdx
callq 0x15a58
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movq 0x30(%rbp), %rdx
movq %r13, %rbx
callq 0x1512b
movl 0x28(%rbp), %edx
leaq 0x228d8(%rip), %rdi     # 0x5b7c7
movl %r12d, %esi
movq %rdx, -0x78(%rbp)
xorl %eax, %eax
callq 0x20f0
leaq 0x22903(%rip), %rdi     # 0x5b807
movl 0x38(%rbp), %esi
xorl %eax, %eax
callq 0x20f0
movq %r13, %rdi
movq %r14, -0x38(%rbp)
movq %r14, %rsi
movl %r12d, %edx
movq %r15, -0x40(%rbp)
movq %r15, %rcx
callq 0x393ab
leal (%r12,%r12,2), %eax
movl 0x38(%rbp), %ecx
movq %rcx, %r10
leal (%rcx,%rcx,2), %ecx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x30(%rbp)
movq %rdx, %rsp
movl %r12d, %r11d
movq %r12, -0x60(%rbp)
testl %r12d, %r12d
jle 0x38fa1
leaq 0x8(%rbx), %rdx
xorl %esi, %esi
movq -0x30(%rbp), %rdi
leaq (%rsi,%rsi,2), %r8
shlq $0x6, %r8
cmpl $0x0, 0x20(%rbx,%r8)
js 0x38fa1
xorl %r8d, %r8d
xorps %xmm0, %xmm0
cvtsd2ss (%rdx,%r8,2), %xmm0
movss %xmm0, (%rdi,%r8)
addq $0x4, %r8
cmpq $0xc, %r8
jne 0x38f76
incq %rsi
addq $0xc0, %rdx
addq %r8, %rdi
cmpq %r11, %rsi
jne 0x38f63
movl %ecx, %ecx
movq %rsp, %r14
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
testl %r10d, %r10d
jle 0x3900f
movl %r10d, %ecx
movq -0x38(%rbp), %rdx
addq $0x8, %rdx
xorl %esi, %esi
movq %r14, %rdi
movq -0x38(%rbp), %r9
leaq (%rsi,%rsi,2), %r8
shlq $0x6, %r8
cmpl $0x0, 0x20(%r9,%r8)
js 0x3900f
xorl %r8d, %r8d
xorps %xmm0, %xmm0
cvtsd2ss (%rdx,%r8,2), %xmm0
movss %xmm0, (%rdi,%r8)
addq $0x4, %r8
cmpq $0xc, %r8
jne 0x38fe4
incq %rsi
addq $0xc0, %rdx
addq %r8, %rdi
cmpq %rcx, %rsi
jne 0x38fd1
movq %r11, -0xb0(%rbp)
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq -0x60(%rbp), %rax
cmpl %eax, %r10d
cmovgel %eax, %r10d
leaq 0xf(,%r10,4), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %r10, -0x58(%rbp)
testl %r10d, %r10d
jle 0x3905d
movl -0x58(%rbp), %eax
xorl %ecx, %ecx
movl $0x3f800000, (%r12,%rcx,4) # imm = 0x3F800000
incq %rcx
cmpq %rcx, %rax
jne 0x3904d
leaq 0x10(%rbp), %r15
movq -0x30(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq -0x58(%rbp), %rcx
callq 0x4e010
movq %r15, %r9
movq -0x78(%rbp), %rcx
leal (%rcx,%rcx,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x50(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x48(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x98(%rbp)
movq %rdx, %rsp
testl %ecx, %ecx
jle 0x390f1
movq 0x8(%r9), %rax
xorl %r8d, %r8d
movq -0x48(%rbp), %rdx
movl (%rax,%r8,4), %esi
leal (%rsi,%rsi,2), %esi
movslq %esi, %rsi
leaq (%r14,%rsi,4), %rdi
xorl %esi, %esi
movss (%rdi,%rsi), %xmm0
movss %xmm0, (%rdx,%rsi)
addq $0x4, %rsi
cmpl $0xc, %esi
jne 0x390d3
incq %r8
addq %rsi, %rdx
cmpq %rcx, %r8
jne 0x390c3
movq %rbx, -0x80(%rbp)
movq (%r9), %r15
testl %ecx, %ecx
jle 0x39134
xorl %eax, %eax
movq -0x50(%rbp), %rdi
movl (%r15,%rax,4), %edx
leal (%rdx,%rdx,2), %edx
movslq %edx, %rdx
movq -0x30(%rbp), %rsi
leaq (%rsi,%rdx,4), %rsi
xorl %edx, %edx
movss (%rsi,%rdx), %xmm0
movss %xmm0, (%rdi,%rdx)
addq $0x4, %rdx
cmpl $0xc, %edx
jne 0x39116
incq %rax
addq %rdx, %rdi
cmpq %rcx, %rax
jne 0x39102
movq %r12, -0xa8(%rbp)
movq 0x10(%r9), %rdx
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4e010
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x226ce(%rip), %rdi     # 0x5b829
movb $0x1, %al
callq 0x20f0
leaq 0x226d4(%rip), %rsi     # 0x5b83d
leaq -0x120(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x1e0bb(%rip), %rsi     # 0x57240
movq %r14, %rdi
callq 0x2210
xorps %xmm0, %xmm0
movq %rax, -0x70(%rbp)
movq %rax, %rdi
movq -0x88(%rbp), %rbx
movq %rbx, %rsi
movq -0x60(%rbp), %r12
movl %r12d, %edx
movq -0x30(%rbp), %rcx
movq -0x90(%rbp), %r8
xorl %r9d, %r9d
callq 0x32c92
movq -0x80(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xa0(%rbp)
movl $0x1, %r14d
leaq 0x22675(%rip), %rdi     # 0x5b84c
movl %r14d, %esi
xorl %eax, %eax
callq 0x20f0
movq -0x80(%rbp), %rdi
movl %r12d, %esi
movq %rbx, %rdx
movq %rdi, %rbx
callq 0x1512b
subq $0x8, %rsp
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq -0x38(%rbp), %rcx
movl %r12d, %r8d
movl %r14d, %r9d
pushq $0x1
callq 0x3a1d3
addq $0x10, %rsp
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
movl -0x64(%rbp), %ecx
callq 0x154bb
testl %r12d, %r12d
movq -0x78(%rbp), %rcx
movq -0xb0(%rbp), %r8
jle 0x39278
movq -0xa0(%rbp), %rax
xorl %edi, %edi
movq %r13, %rdx
leaq (%rdi,%rdi,2), %rsi
shlq $0x6, %rsi
cmpl $0x0, 0x20(%rbx,%rsi)
js 0x39278
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsd2ss (%rax,%rsi,2), %xmm0
movss %xmm0, (%rdx,%rsi)
addq $0x4, %rsi
cmpq $0xc, %rsi
jne 0x39250
incq %rdi
addq $0xc0, %rax
addq %rsi, %rdx
cmpq %r8, %rdi
jne 0x3923f
movl %r14d, -0x68(%rbp)
testl %ecx, %ecx
jle 0x392be
xorl %eax, %eax
movq -0x98(%rbp), %rdi
movl (%r15,%rax,4), %edx
leal (%rdx,%rdx,2), %edx
movslq %edx, %rdx
leaq (,%rdx,4), %rsi
addq %r13, %rsi
xorl %edx, %edx
movss (%rsi,%rdx), %xmm0
movss %xmm0, (%rdi,%rdx)
addq $0x4, %rdx
cmpl $0xc, %edx
jne 0x392a0
incq %rax
addq %rdx, %rdi
cmpq %rcx, %rax
jne 0x39289
movq -0x50(%rbp), %rdi
movq -0x98(%rbp), %r14
movq %r14, %rsi
movq -0xa8(%rbp), %r12
movq %r12, %rdx
movq %rcx, %rbx
callq 0x4e010
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2258d(%rip), %rdi     # 0x5b87a
movb $0x1, %al
callq 0x20f0
movq -0x48(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movl %ebx, %ecx
callq 0x4e010
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x2257b(%rip), %rdi     # 0x5b894
movb $0x1, %al
callq 0x20f0
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq -0x58(%rbp), %rcx
callq 0x4e010
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %rbx
movq %rbx, %rsi
movq -0x60(%rbp), %r12
movl %r12d, %edx
movq %r13, %rcx
movq -0x90(%rbp), %r8
movl -0x68(%rbp), %r14d
movl %r14d, %r9d
movss -0x40(%rbp), %xmm0
callq 0x32c92
incl %r14d
cmpl $0x4, %r14d
jne 0x391d0
leaq 0x18964(%rip), %rdi     # 0x51cdb
leaq -0x120(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x70(%rbp), %rdi
callq 0x20c0
movq -0x38(%rbp), %rdi
callq 0x2050
movss -0x40(%rbp), %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq