// File: /workspace/github_c_makefile_star2_O0/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
subq $0x170, %rsp            # imm = 0x170
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x1bf00
movl 0x38(%rbp), %edi
movq 0x30(%rbp), %rsi
movq 0x40(%rbp), %rdx
callq 0x1ce20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl 0x38(%rbp), %esi
movq 0x30(%rbp), %rdx
callq 0x1bf00
movq -0x148(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %esi
movl -0x44(%rbp), %edx
leaq 0x2fe56(%rip), %rdi     # 0x80b7c
xorl %eax, %eax
movb %al, -0x139(%rbp)
callq 0x10d0
movb -0x139(%rbp), %al
movl 0x38(%rbp), %esi
leaq 0x2fe79(%rip), %rdi     # 0x80bbc
callq 0x10d0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x511c0
movl -0x24(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
movl %eax, -0x48(%rbp)
movl 0x38(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x138(%rbp)
movq %rdi, %rsp
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x49770
movl -0x4c(%rbp), %eax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x130(%rbp)
movq %rdi, %rsp
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rsi
movl 0x38(%rbp), %edx
callq 0x49770
movl -0x48(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x128(%rbp)
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x74(%rbp)
movl 0x38(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x50e0e
movl 0x38(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x150(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x50e63
movq -0x150(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movss 0x2523d(%rip), %xmm0    # 0x76090
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x50e38
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x150(%rbp), %rdx
movl -0x74(%rbp), %ecx
callq 0x70af0
movq -0x130(%rbp), %rdx
movq -0x148(%rbp), %rax
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x84(%rbp)
movl -0x44(%rbp), %esi
movl %esi, %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, -0x88(%rbp)
movl -0x88(%rbp), %ecx
leaq 0xf(,%rcx,4), %rdi
andq $-0x10, %rdi
movq %rsp, %rsi
subq %rdi, %rsi
movq %rsi, -0x160(%rbp)
movq %rsi, %rsp
movq %rcx, -0x90(%rbp)
movl -0x88(%rbp), %ecx
leaq 0xf(,%rcx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdi
subq %rsi, %rdi
movq %rdi, -0x158(%rbp)
movq %rdi, %rsp
movq %rcx, -0x98(%rbp)
movl -0x88(%rbp), %ecx
leaq 0xf(,%rcx,4), %r8
andq $-0x10, %r8
movq %rsp, %rsi
subq %r8, %rsi
movq %rsi, -0x168(%rbp)
movq %rsi, %rsp
movq %rcx, -0xa0(%rbp)
movl -0x44(%rbp), %esi
movq 0x8(%rax), %rcx
callq 0x4a1d0
movq -0x148(%rbp), %rax
movq -0x160(%rbp), %rdi
movq -0x138(%rbp), %rdx
movl -0x44(%rbp), %esi
movq (%rax), %rcx
callq 0x4a1d0
movq -0x148(%rbp), %rax
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq 0x10(%rax), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2fc4f(%rip), %rdi     # 0x80bde
movb $0x1, %al
callq 0x10d0
leaq -0x110(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x2fc4a(%rip), %rsi     # 0x80bf2
movb $0x0, %al
callq 0x1200
leaq -0x110(%rbp), %rdi
leaq 0x2b3b5(%rip), %rsi     # 0x7c372
callq 0x11b0
movq -0x138(%rbp), %rcx
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %r8
xorl %r9d, %r9d
xorps %xmm0, %xmm0
callq 0x49a60
movl $0x1, -0x11c(%rbp)
movl $0x1, -0x40(%rbp)
cmpl $0x3, -0x40(%rbp)
jg 0x51176
movl -0x40(%rbp), %esi
leaq 0x2fbef(%rip), %rdi     # 0x80c01
movb $0x0, %al
callq 0x10d0
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x1bf00
movq -0x8(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl -0x24(%rbp), %r8d
movl -0x40(%rbp), %r9d
movl -0x11c(%rbp), %eax
xorl %esi, %esi
movl %esi, %edi
xorl %esi, %esi
subq $0x10, %rsp
movl %eax, (%rsp)
callq 0x52a30
addq $0x10, %rsp
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0xc(%rbp), %ecx
xorl %eax, %eax
movl %eax, %edx
callq 0x1c4f0
movq -0x128(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x49770
movq -0x168(%rbp), %rdi
movq -0x128(%rbp), %rdx
movq -0x148(%rbp), %rax
movl -0x44(%rbp), %esi
movq (%rax), %rcx
callq 0x4a1d0
movq -0x160(%rbp), %rdi
movq -0x168(%rbp), %rsi
movq -0x150(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2fb58(%rip), %rdi     # 0x80c2f
movb $0x1, %al
callq 0x10d0
movq -0x158(%rbp), %rdi
movq -0x168(%rbp), %rsi
movq -0x150(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2fb2f(%rip), %rdi     # 0x80c49
movb $0x1, %al
callq 0x10d0
movq -0x138(%rbp), %rdi
movq -0x150(%rbp), %rdx
movq -0x128(%rbp), %rsi
movl -0x74(%rbp), %ecx
callq 0x70af0
movq -0x128(%rbp), %rcx
movq -0x118(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
movq -0x30(%rbp), %r8
movl -0x40(%rbp), %r9d
movss -0x84(%rbp), %xmm0
callq 0x49a60
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x50ffe
leaq -0x110(%rbp), %rsi
leaq 0x2636a(%rip), %rdi     # 0x774ee
movb $0x0, %al
callq 0x10d0
movq -0x118(%rbp), %rdi
callq 0x10a0
movq -0x38(%rbp), %rdi
callq 0x1040
movss -0x84(%rbp), %xmm0
movq -0x58(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)