// File: /workspace/github_c_makefile_star2_O3/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, -0x88(%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, -0x78(%rbp)
movq %rcx, %rdx
callq 0x14cf3
movl %ebx, %edi
movq %r14, %rsi
movq 0x40(%rbp), %rdx
callq 0x15645
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
movq 0x30(%rbp), %rdx
movq %r13, %rbx
callq 0x14cf3
movl 0x28(%rbp), %edx
leaq 0x229bc(%rip), %rdi     # 0x5b77f
movl %r12d, %esi
movq %rdx, -0x48(%rbp)
xorl %eax, %eax
callq 0x20f0
leaq 0x229e7(%rip), %rdi     # 0x5b7bf
movl 0x38(%rbp), %esi
xorl %eax, %eax
callq 0x20f0
movq %r13, %rdi
movq %r14, -0x50(%rbp)
movq %r14, %rsi
movl %r12d, %edx
movq %r15, -0x40(%rbp)
movq %r15, %rcx
movq %r12, %r15
callq 0x39389
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 %r15d, %r11d
testl %r15d, %r15d
jle 0x38e74
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 0x38e74
xorl %r8d, %r8d
xorps %xmm0, %xmm0
cvtsd2ss (%rdx,%r8,2), %xmm0
movss %xmm0, (%rdi,%r8)
addq $0x4, %r8
cmpq $0xc, %r8
jne 0x38e49
incq %rsi
addq $0xc0, %rdx
addq %r8, %rdi
cmpq %r11, %rsi
jne 0x38e36
movl %ecx, %ecx
movq %rsp, %r14
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
testl %r10d, %r10d
jle 0x38ee2
movl %r10d, %ecx
movq -0x50(%rbp), %rdx
addq $0x8, %rdx
xorl %esi, %esi
movq %r14, %rdi
movq -0x50(%rbp), %r9
leaq (%rsi,%rsi,2), %r8
shlq $0x6, %r8
cmpl $0x0, 0x20(%r9,%r8)
js 0x38ee2
xorl %r8d, %r8d
xorps %xmm0, %xmm0
cvtsd2ss (%rdx,%r8,2), %xmm0
movss %xmm0, (%rdi,%r8)
addq $0x4, %r8
cmpq $0xc, %r8
jne 0x38eb7
incq %rsi
addq $0xc0, %rdx
addq %r8, %rdi
cmpq %rcx, %rsi
jne 0x38ea4
movq %r14, -0x38(%rbp)
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
cmpl %r15d, %r10d
cmovgel %r15d, %r10d
leaq 0xf(,%r10,4), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %r10, -0x60(%rbp)
testl %r10d, %r10d
jle 0x39018
movq -0x60(%rbp), %rcx
leal 0x3(%rcx), %eax
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %eax
shlq $0x4, %rax
movdqa 0x180d5(%rip), %xmm1    # 0x51010
movdqa 0x180dd(%rip), %xmm2    # 0x51020
xorl %ecx, %ecx
movdqa 0x180e3(%rip), %xmm3    # 0x51030
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x1d223(%rip), %xmm5    # 0x56180
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0x38f99
movl $0x3f800000, (%r12,%rcx) # imm = 0x3F800000
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x38fb0
movl $0x3f800000, 0x4(%r12,%rcx) # imm = 0x3F800000
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %edx
testb $0x1, %dl
je 0x38ff0
movl $0x3f800000, 0x8(%r12,%rcx) # imm = 0x3F800000
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0x39003
movl $0x3f800000, 0xc(%r12,%rcx) # imm = 0x3F800000
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x38f5d
movq %r11, -0xb8(%rbp)
leaq 0x10(%rbp), %r14
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r12, %rdx
movq -0x60(%rbp), %rcx
callq 0x4dfa0
movq -0x48(%rbp), %rcx
leal (%rcx,%rcx,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x58(%rbp)
movq %rdx, %rsp
movq %rsp, %r9
subq %rax, %r9
movq %r9, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x90(%rbp)
movq %rdx, %rsp
testl %ecx, %ecx
movq %r15, -0x80(%rbp)
movq %rbx, -0x70(%rbp)
movq %r12, -0xb0(%rbp)
jle 0x39107
movq %r14, %r10
movq 0x8(%r14), %rax
xorl %r8d, %r8d
movq %r9, %rdx
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %r14
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 0x390ac
incq %r8
addq %rsi, %rdx
cmpq %rcx, %r8
jne 0x3909c
movq (%r10), %r15
xorl %eax, %eax
movq -0x58(%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 0x390e7
incq %rax
addq %rdx, %rdi
cmpq %rcx, %rax
jne 0x390d3
jmp 0x39111
movq (%r14), %r15
movq -0x48(%rbp), %rcx
movq %r14, %r10
movq 0x10(%r10), %rdx
movq -0x58(%rbp), %rdi
movq %r9, -0xa8(%rbp)
movq %r9, %rsi
callq 0x4dfa0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x226aa(%rip), %rdi     # 0x5b7e1
movb $0x1, %al
callq 0x20f0
leaq 0x226b0(%rip), %rsi     # 0x5b7f5
leaq -0x120(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x1e09f(%rip), %rsi     # 0x57200
movq %r14, %rdi
callq 0x2220
xorps %xmm0, %xmm0
movq %rax, -0x40(%rbp)
movq %rax, %rdi
movq -0x78(%rbp), %rbx
movq %rbx, %rsi
movq -0x80(%rbp), %r12
movl %r12d, %edx
movq -0x30(%rbp), %rcx
movq -0x88(%rbp), %r8
xorl %r9d, %r9d
callq 0x3285f
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x98(%rbp)
movl $0x1, %r14d
movq %r13, -0xa0(%rbp)
leaq 0x2264d(%rip), %rdi     # 0x5b804
movl %r14d, %esi
xorl %eax, %eax
callq 0x20f0
movq -0x70(%rbp), %rdi
movl %r12d, %esi
movq %rbx, %rdx
movq %rdi, %rbx
callq 0x14cf3
subq $0x8, %rsp
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq -0x50(%rbp), %rcx
movl %r12d, %r8d
movl %r14d, %r9d
pushq $0x1
callq 0x3a192
addq $0x10, %rsp
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
movl -0x64(%rbp), %ecx
callq 0x15083
testl %r12d, %r12d
movq -0xb8(%rbp), %rdi
jle 0x39254
movq -0x98(%rbp), %rax
xorl %ecx, %ecx
movq %r13, %rdx
leaq (%rcx,%rcx,2), %rsi
shlq $0x6, %rsi
cmpl $0x0, 0x20(%rbx,%rsi)
js 0x39254
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsd2ss (%rax,%rsi,2), %xmm0
movss %xmm0, (%rdx,%rsi)
addq $0x4, %rsi
cmpq $0xc, %rsi
jne 0x3922c
incq %rcx
addq $0xc0, %rax
addq %rsi, %rdx
cmpq %rdi, %rcx
jne 0x3921b
movq -0x48(%rbp), %rbx
testl %ebx, %ebx
jle 0x3929a
xorl %eax, %eax
movq -0x90(%rbp), %rcx
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, (%rcx,%rdx)
addq $0x4, %rdx
cmpl $0xc, %edx
jne 0x3927c
incq %rax
addq %rdx, %rcx
cmpq %rbx, %rax
jne 0x39265
movq -0x58(%rbp), %rdi
movq -0x90(%rbp), %r13
movq %r13, %rsi
movq -0xb0(%rbp), %r12
movq %r12, %rdx
movl %ebx, %ecx
callq 0x4dfa0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2256a(%rip), %rdi     # 0x5b832
movb $0x1, %al
callq 0x20f0
movq -0xa8(%rbp), %rdi
movq %r13, %rsi
movq -0xa0(%rbp), %r13
movq %r12, %rdx
movl %ebx, %ecx
callq 0x4dfa0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x2254e(%rip), %rdi     # 0x5b84c
movb $0x1, %al
callq 0x20f0
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq -0x60(%rbp), %rcx
callq 0x4dfa0
movq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rbx
movq %rbx, %rsi
movq -0x80(%rbp), %r12
movl %r12d, %edx
movq %r13, %rcx
movq -0x88(%rbp), %r8
movl %r14d, %r9d
movss -0x38(%rbp), %xmm0
callq 0x3285f
incl %r14d
cmpl $0x4, %r14d
jne 0x391b0
leaq 0x189fa(%rip), %rdi     # 0x51d4f
leaq -0x120(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x40(%rbp), %rdi
callq 0x20c0
movq -0x50(%rbp), %rdi
callq 0x2050
movss -0x38(%rbp), %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq