// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkstorage.cc
// Function: get_multiple_best_RMSD_fits(MOLECULE, ATOM_NETWORK*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
vector<MOLECULE> get_multiple_best_RMSD_fits(MOLECULE mol, ATOM_NETWORK *cell, int vertex_ID, string net, string prefix, int mol_ID) {
  bool verbose = false; //for printing data to terminal
  //1) can we fit this MOLECULE to this VERTEX?
  int num_fit_sites_no_dummy = cell->vertices.at(vertex_ID).edges.size();
  int num_fit_sites_dummy = cell->vertices.at(vertex_ID).dummy_edges.size();
  int num_fit_sites = num_fit_sites_no_dummy + num_fit_sites_dummy;
  int num_mol_sites_no_dummy = mol.sites.size();
  int num_mol_sites_dummy = mol.dummy_sites.size();
  int num_mol_sites = num_mol_sites_no_dummy + num_mol_sites_dummy;
  if(num_fit_sites_dummy!=num_mol_sites_dummy || num_fit_sites_no_dummy!=num_mol_sites_no_dummy) { //we can only fit the molecule to the given vertex is the number of sites is the same in each
    printf("ERROR: cannot fit molecule with %d sites and %d dummy sites to a vertex with %d sites and %d dummy sites!\n", num_mol_sites_no_dummy, num_mol_sites_dummy, num_fit_sites_no_dummy, num_fit_sites_dummy);
    exit(EXIT_FAILURE);
  }

  //2) how many ways can we do it?
  vector<int> permute_base_no_dummy, permute_base_dummy;
  for(int i=0; i<num_fit_sites_no_dummy; i++) permute_base_no_dummy.push_back(i);
  for(int i=0; i<num_fit_sites_dummy; i++) permute_base_dummy.push_back(i+num_fit_sites_no_dummy);
  vector< vector<int> > permutations_no_dummy, permutations_dummy;

  permute(permute_base_no_dummy, 0, &permutations_no_dummy); //fills in a vector with all possible permutations by which we can try and orient our two objects, e.g. (0123), (0132), ...
  permute(permute_base_dummy, 0, &permutations_dummy);

  //2b) now collapse permutations for non-dummy and dummy together to get acceptable permutations
  vector< vector<int> > permutations;
  int num_perm_no_dummy = permutations_no_dummy.size();
  int num_perm_dummy = permutations_dummy.size();
  for(int i=0; i<num_perm_no_dummy; i++) {
    for(int j=0; j<num_perm_dummy; j++) {
      vector<int> new_perm = permutations_no_dummy.at(i);
      for(int k=0; k<num_fit_sites_dummy; k++) new_perm.push_back(permutations_dummy.at(j).at(k));
      permutations.push_back(new_perm);
    }
  }

  int num_perm = permutations.size();
  if(verbose) {
    printf("there are %d permutations of length %d:\n", num_perm, num_fit_sites);
    for(int i=0; i<num_perm; i++) {
      printf("\t");
      for(int j=0; j<permutations.at(i).size(); j++) {
        printf("%d ", permutations.at(i).at(j));
      }
      printf("\n");
    }
  }
  //3) which way gives us the lowest rmsd?
  double best_rmsd = -1; //dummy value
  int best_rmsd_ID = -1;
  vector<FIT> vector_of_fits;
  vector<MOLECULE> vector_of_centred_molecules;
  for(int p=0; p<num_perm; p++) { //try each permutation!
    vector<int> perm = permutations.at(p);
    double fixed[num_fit_sites][3], moving[num_fit_sites][3];
    XYZ fixed_CoM = origin, moving_CoM = origin;
    for(int i=0; i<num_fit_sites; i++) {
      XYZ fix(0,0,0);
      if(i<num_fit_sites_no_dummy)
        fix = cell->abc_to_xyz_returning_XYZ(cell->vertices.at(vertex_ID).edges.at(i)); //the edges are always in the same order
      else
        fix = cell->abc_to_xyz_returning_XYZ(cell->vertices.at(vertex_ID).dummy_edges.at(i-num_fit_sites_no_dummy));
      fixed[i][0] = fix.x;
      fixed[i][1] = fix.y;
      fixed[i][2] = fix.z;
      fixed_CoM = fixed_CoM+fix;
      XYZ move(0,0,0);
      if(perm.at(i)<num_fit_sites_no_dummy)
        move = mol.atoms_xyz.at(mol.sites.at(perm.at(i))); //permutation encodes in what order the sites should go to correspond to the edges
      else
//        move = mol.dummy_sites.at(perm.at(i)-num_fit_sites_no_dummy);
        move = mol.atoms_xyz.at(mol.dummy_sites.at(perm.at(i)-num_fit_sites_no_dummy));
      moving[i][0] = move.x;
      moving[i][1] = move.y;
      moving[i][2] = move.z;
      moving_CoM = moving_CoM+move;
    }

    if(verbose) {
      printf("PERMUTATION %d:\n\t", p);
      for(int i=0; i<num_fit_sites; i++) {
        printf("%d ", perm.at(i));
      }
      printf("\n");
      printf("\tfits the following positions:\n");
      for(int i=0; i<num_fit_sites; i++) {
        printf("\t\t%.3f %.3f %.3f to %.3f %.3f %.3f\n", moving[i][0], moving[i][1], moving[i][2], fixed[i][0], fixed[i][1], fixed[i][2]);
      }
    }
    //3a) evaluate this permutation
    double mov_com[3], mov_to_ref[3]; //leave these blank, they are filled in by the rmsd method
    double rotation_matrix[3][3];
    for(int i=0; i<3; i++) for(int j=0; j<3; j++) rotation_matrix[i][j] = 0; //dummy values - filled in by the rmsd method
    double rmsd = 0; //dummy value - filled in by the rmsd method
    calculate_rotation_rmsd(fixed, moving, num_fit_sites, mov_com, mov_to_ref, rotation_matrix, &rmsd); //calling rmsd code - writes the corresponding rotation matrix
    //3b) some permutations are not possible, and produce NAN
    bool valid = true;
    if(isnan(rmsd)) valid=false;
    for(int i=0; i<3 && valid; i++) for(int j=0; j<3 && valid; j++) if(isnan(rotation_matrix[i][j])) valid=false;
    if(valid) {
      FIT f;
      f.fit = rotate(mol, rotation_matrix);
      MOLECULE centred_aligned_mol = translate(f.fit, get_mol_site_CoM(&f.fit).scale(-1));
      f.fit.permutation = permutations.at(p);
      f.perm_ID = p;
      f.rmsd = rmsd;
//try and select alignments appropriately ...
      if(best_rmsd<0 || rmsd<best_rmsd) {
        best_rmsd = rmsd;
//        best_rmsd_ID = p;
        best_rmsd_ID = vector_of_fits.size();
      }
      vector_of_fits.push_back(f);
      vector_of_centred_molecules.push_back(centred_aligned_mol);
    } else if(verbose) printf("\tTHIS PERMUTATION COULD NOT PRODUCE A VALID ROTATION MATRIX\n");
  }

  //now return all molecules which are within a tolerance of the best RMSD
  int num_fits = vector_of_fits.size();
if(verbose) printf("DEBUG: num valid rotation matrices = %d; best_rmsd_ID = %d\n", num_fits, best_rmsd_ID);
  vector<MOLECULE> vec, vector_of_unique_centred_molecules;
  vector_of_unique_centred_molecules.push_back(vector_of_centred_molecules.at(best_rmsd_ID));
  FIT f0 = vector_of_fits.at(best_rmsd_ID);
  vec.push_back(f0.fit);
if(verbose) {
  string rotmol_name = prefix+"_molecule_ID_"+convertToString(mol_ID)+"_basic_vertex_ID_"+convertToString(vertex_ID)+"_permutation_"+convertToString(f0.perm_ID)+".xyz"; //write molecule to xyz file
  FILE *rotmol = fopen(rotmol_name.c_str(),"w");
  if(rotmol==NULL) {
    printf("ERROR: could not open output rotated molecule file with name %s\n", rotmol_name.c_str());
    exit(EXIT_FAILURE);
  }
  MOLECULE rotated = translate(f0.fit, get_mol_site_CoM(&f0.fit).scale(-1));
  write_molecule(rotmol, &rotated, net, vertex_ID, -1, true); //oriented to basic vertex basic_ID with symmetry "-1" (not applicable here) - this will be noted in the file - true indicates 'write out sites'
  fclose(rotmol);
  printf("\tmolecule %d oriented to basic vertex %d written to %s\n", mol_ID, vertex_ID, rotmol_name.c_str());
}
  for(int i=0; i<num_fits; i++) {
    if(i!=best_rmsd_ID) { //don't check the one we pushed already
      if(vector_of_fits.at(i).rmsd<best_rmsd*TOLERANCE_PROPORTION) { //acceptable RMSD?
        if(molecule_alignment_chemistry_is_unique(&vector_of_centred_molecules.at(i), &vector_of_unique_centred_molecules)) { //unique molecule?
          vector_of_unique_centred_molecules.push_back(vector_of_centred_molecules.at(i));
          FIT f = vector_of_fits.at(i);
          vec.push_back(f.fit);
if(verbose) {
  string rotmol_name = prefix+"_molecule_ID_"+convertToString(mol_ID)+"_basic_vertex_ID_"+convertToString(vertex_ID)+"_permutation_"+convertToString(f.perm_ID)+".xyz"; //write molecule to xyz file
  FILE *rotmol = fopen(rotmol_name.c_str(),"w");
  if(rotmol==NULL) {
    printf("ERROR: could not open output rotated molecule file with name %s\n", rotmol_name.c_str());
    exit(EXIT_FAILURE);
  }
  MOLECULE rotated = translate(f.fit, get_mol_site_CoM(&f.fit).scale(-1));
  write_molecule(rotmol, &rotated, net, vertex_ID, -1, true); //oriented to basic vertex basic_ID with symmetry "-1" (not applicable here) - this will be noted in the file - true indicates 'write out sites'
  fclose(rotmol);
  printf("\tmolecule %d oriented to basic vertex %d written to %s\n", mol_ID, vertex_ID, rotmol_name.c_str());
}
        }
      }
    }
  }
if(verbose) printf("DEBUG: of %d permutations, %d unique alignments were generated\n", num_perm, (int)(vec.size()));
  return vec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x578, %rsp            # imm = 0x578
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
movq %rdx, -0xa8(%rbp)
leaq 0x3c0(%rdx), %rbx
movslq %ecx, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4b63c
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
pushq $0x18
popq %r13
movq %rcx, %rax
cqto
idivq %r13
movq %rax, %r12
movq %rbx, -0xb8(%rbp)
movq %rbx, %rdi
movq %r15, -0xb0(%rbp)
movq %r15, %rsi
callq 0x4b63c
movq 0x40(%rax), %rcx
subq 0x38(%rax), %rcx
movq %rcx, %rax
cqto
idivq %r13
movq %rax, %rbx
movq 0x50(%r14), %rsi
movq 0x68(%r14), %rdx
subq 0x48(%r14), %rsi
movq %r14, -0x70(%rbp)
subq 0x60(%r14), %rdx
shrq $0x2, %rsi
shrq $0x2, %rdx
movq %r12, -0x30(%rbp)
cmpl %esi, %r12d
jne 0x45427
cmpl %edx, %ebx
jne 0x45427
movq -0x30(%rbp), %rax
addl %ebx, %eax
movl %eax, -0x44(%rbp)
movq -0x70(%rbp), %rax
leaq 0x48(%rax), %rcx
movq %rcx, -0x180(%rbp)
addq $0x60, %rax
movq %rax, -0x178(%rbp)
leaq -0x240(%rbp), %r14
andq $0x0, 0x10(%r14)
xorpd %xmm0, %xmm0
andq $0x0, -0x140(%rbp)
movapd %xmm0, (%r14)
movapd %xmm0, -0x150(%rbp)
xorl %eax, %eax
leaq -0x330(%rbp), %r15
movl %eax, -0x330(%rbp)
cmpl -0x30(%rbp), %eax
jge 0x44b50
movq %r14, %rdi
movq %r15, %rsi
callq 0x9434
movl -0x330(%rbp), %eax
incl %eax
jmp 0x44b30
xorl %r15d, %r15d
testl %ebx, %ebx
cmovgl %ebx, %r15d
leaq -0x150(%rbp), %rbx
leaq -0x330(%rbp), %r14
movq -0x30(%rbp), %rax
movl %eax, %r12d
movl %r15d, %r13d
subl $0x1, %r13d
jb 0x44b8e
movl %r12d, -0x330(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10324
incl %r12d
jmp 0x44b71
xorpd %xmm0, %xmm0
movapd %xmm0, -0x110(%rbp)
andq $0x0, -0x100(%rbp)
movapd %xmm0, -0x130(%rbp)
andq $0x0, -0x120(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0xa6ce
leaq -0x270(%rbp), %rdi
leaq -0x110(%rbp), %rdx
xorl %esi, %esi
callq 0x76206
leaq -0x270(%rbp), %rdi
callq 0xb290
leaq -0x258(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xa6ce
leaq -0x258(%rbp), %rdi
xorl %ebx, %ebx
leaq -0x130(%rbp), %rdx
xorl %esi, %esi
callq 0x76206
leaq -0x258(%rbp), %rdi
callq 0xb290
xorpd %xmm0, %xmm0
leaq -0xf0(%rbp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x110(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %rsi
leaq -0x130(%rbp), %r13
movq 0x8(%r13), %rax
subq (%r13), %rax
cqto
idivq %rcx
testl %eax, %eax
cmovlel %ebx, %eax
movq %rax, -0x50(%rbp)
testl %esi, %esi
cmovlel %ebx, %esi
movq %rsi, -0x68(%rbp)
movl %r15d, %r12d
leaq -0x330(%rbp), %r14
xorl %esi, %esi
cmpq -0x68(%rbp), %rsi
je 0x44cf7
xorl %r15d, %r15d
movq %rsi, -0x78(%rbp)
cmpq -0x50(%rbp), %r15
je 0x44cf2
leaq -0x110(%rbp), %rdi
callq 0x4bbec
movq %r14, %rdi
movq %rax, %rsi
callq 0xa6ce
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x44cd2
movq %r13, %rdi
movq %r15, %rsi
callq 0x4bbec
movq %rax, %rdi
movq %rbx, %rsi
callq 0xac00
movq %r14, %rdi
movq %rax, %rsi
callq 0x9434
incq %rbx
jmp 0x44ca7
leaq -0xf0(%rbp), %rdi
movq %r14, %rsi
callq 0xad52
movq %r14, %rdi
callq 0xb290
incq %r15
movq -0x78(%rbp), %rsi
jmp 0x44c88
incq %rsi
jmp 0x44c7b
leaq -0xf0(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq -0xa0(%rbp), %rcx
andq $0x0, 0x10(%rcx)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rcx)
leaq -0xd0(%rbp), %rcx
movapd %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
movl -0x44(%rbp), %ecx
movl %ecx, %edx
movslq -0x30(%rbp), %rsi
xorl %r12d, %r12d
testl %ecx, %ecx
movl $0x0, %edi
cmovgl %ecx, %edi
movq %rdi, -0x78(%rbp)
testl %eax, %eax
cmovlel %r12d, %eax
movq %rax, -0x160(%rbp)
movq %rsi, -0x68(%rbp)
negq %rsi
movq %rsi, -0x170(%rbp)
pushq $-0x1
popq %rcx
movq %rcx, -0x58(%rbp)
movsd 0xbb573(%rip), %xmm0    # 0x1002e8
imulq $0x18, %rdx, %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rax, -0x158(%rbp)
movsd %xmm0, -0x40(%rbp)
xorl %esi, %esi
cmpq -0x160(%rbp), %rsi
je 0x45251
leaq -0xf0(%rbp), %rdi
movq %rsi, -0x60(%rbp)
callq 0x4bbec
leaq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0xa6ce
movq %rsp, -0x168(%rbp)
movq %rsp, %rcx
movq -0x158(%rbp), %rax
subq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq 0x10b902(%rip), %rax    # 0x1506e8
movq %rax, -0x1c0(%rbp)
movupd 0x10b8e3(%rip), %xmm0   # 0x1506d8
movapd %xmm0, -0x1d0(%rbp)
movq %rax, -0x1a0(%rbp)
movapd %xmm0, -0x1b0(%rbp)
pushq $0x10
popq %r13
xorl %r14d, %r14d
cmpq %r14, -0x78(%rbp)
je 0x45013
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq -0x330(%rbp), %rdi
callq 0x6402e
cmpq -0x68(%rbp), %r14
jge 0x44e75
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x4b63c
addq $0x20, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x4b6d6
leaq -0x400(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
callq 0x3f1b2
jmp 0x44eb5
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x4b63c
addq $0x38, %rax
movq -0x170(%rbp), %rcx
leaq (%rcx,%r14), %rsi
movq %rax, %rdi
callq 0x4b6d6
leaq -0x400(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
callq 0x3f1b2
movq -0x3f0(%rbp), %rax
movq %rax, -0x320(%rbp)
movups -0x400(%rbp), %xmm0
movaps %xmm0, -0x330(%rbp)
movaps -0x330(%rbp), %xmm0
movq -0x50(%rbp), %rax
movups %xmm0, -0x10(%rax,%r13)
movsd -0x320(%rbp), %xmm0
movsd %xmm0, (%rax,%r13)
leaq -0x400(%rbp), %r15
movq %r15, %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x330(%rbp), %rdx
callq 0x642d2
movq -0x3f0(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movupd -0x400(%rbp), %xmm0
movapd %xmm0, -0x1d0(%rbp)
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %r15, %rdi
callq 0x6402e
leaq -0x198(%rbp), %rdi
movq %r14, %rsi
callq 0xac00
movq -0x30(%rbp), %rcx
cmpl %ecx, (%rax)
jge 0x44f70
leaq -0x198(%rbp), %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %eax
movq -0x180(%rbp), %rdi
jmp 0x44f8b
leaq -0x198(%rbp), %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %eax
subl -0x30(%rbp), %eax
movq -0x178(%rbp), %rdi
movslq %eax, %rsi
callq 0xac00
movslq (%rax), %rsi
movq -0x70(%rbp), %rdi
callq 0x4b6d6
movups (%rax), %xmm0
movaps %xmm0, -0x400(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x3f0(%rbp)
movaps -0x400(%rbp), %xmm0
movups %xmm0, -0x10(%rbx,%r13)
movsd -0x3f0(%rbp), %xmm0
movsd %xmm0, (%rbx,%r13)
leaq -0x220(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x400(%rbp), %rdx
callq 0x642d2
movq -0x210(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movupd -0x220(%rbp), %xmm0
movapd %xmm0, -0x1b0(%rbp)
incq %r14
addq $0x18, %r13
jmp 0x44e13
leaq -0x220(%rbp), %rax
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0x4503d
xorl %edx, %edx
cmpq $0x3, %rdx
je 0x45034
andq $0x0, (%rax,%rdx,8)
incq %rdx
jmp 0x45024
incq %rcx
addq $0x18, %rax
jmp 0x4501c
andq $0x0, -0x80(%rbp)
subq $0x8, %rsp
movq -0x50(%rbp), %rdi
movq %rbx, %rsi
movl -0x44(%rbp), %edx
leaq -0x450(%rbp), %rcx
leaq -0x430(%rbp), %r8
leaq -0x220(%rbp), %rbx
movq %rbx, %r9
leaq -0x80(%rbp), %rax
pushq %rax
callq 0x795c4
popq %rax
popq %rcx
movsd -0x80(%rbp), %xmm0
ucomisd %xmm0, %xmm0
setnp %al
movq %rbx, %rcx
xorl %edx, %edx
leaq -0x330(%rbp), %r14
leaq -0x5a0(%rbp), %r15
cmpq $0x2, %rdx
ja 0x450c7
testb $0x1, %al
je 0x450c7
xorl %esi, %esi
cmpq $0x2, %rsi
ja 0x450be
testb $0x1, %al
je 0x450be
movsd (%rcx,%rsi,8), %xmm0
ucomisd %xmm0, %xmm0
movzbl %al, %eax
cmovpl %r12d, %eax
incq %rsi
jmp 0x4509f
incq %rdx
addq $0x18, %rcx
jmp 0x45093
testb $0x1, %al
je 0x45232
movq %r14, %rdi
callq 0x4c0da
movq %r15, %rdi
movq -0x70(%rbp), %rsi
callq 0x4ba0a
leaq -0x400(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x75e02
movq %r14, %rdi
movq %r13, %rsi
callq 0x4bae8
movq %r13, %rdi
callq 0x4bb60
movq %r15, %rdi
callq 0x4bb60
leaq -0x4f8(%rbp), %rdi
movq %r14, %rsi
callq 0x4ba0a
leaq -0x418(%rbp), %rdi
movq %r14, %rsi
callq 0x75f61
leaq -0x348(%rbp), %rdi
leaq -0x418(%rbp), %rsi
movsd 0xbb1a1(%rip), %xmm0    # 0x1002e8
callq 0x640ba
subq $0x20, %rsp
movq -0x338(%rbp), %rax
movq %rax, 0x10(%rsp)
movupd -0x348(%rbp), %xmm0
movupd %xmm0, (%rsp)
leaq -0x400(%rbp), %rdi
leaq -0x4f8(%rbp), %rsi
callq 0x76138
addq $0x20, %rsp
leaq -0x4f8(%rbp), %rdi
callq 0x4bb60
leaq -0xf0(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x4bbec
leaq -0x2b8(%rbp), %rdi
movq %rax, %rsi
callq 0xc178
movq -0x60(%rbp), %rax
movl %eax, -0x280(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x288(%rbp)
movsd -0x40(%rbp), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm1, %xmm2
ja 0x451d7
ucomisd %xmm0, %xmm1
jbe 0x451f7
movq -0x98(%rbp), %rax
subq -0xa0(%rbp), %rax
cqto
movl $0xb8, %ecx
idivq %rcx
movq %rax, -0x58(%rbp)
movapd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
callq 0x4bc0a
leaq -0xd0(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x4bc3a
leaq -0x400(%rbp), %rdi
callq 0x4bb60
movq %r14, %rdi
callq 0x4bb60
movq -0x168(%rbp), %rsp
leaq -0x198(%rbp), %rdi
callq 0xb290
movq -0x60(%rbp), %rsi
incq %rsi
jmp 0x44d8f
movq -0x98(%rbp), %rax
subq -0xa0(%rbp), %rax
movl $0xb8, %ecx
cqto
idivq %rcx
movq %rax, %rbx
movq -0x38(%rbp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
andq $0x0, -0x210(%rbp)
movupd %xmm0, (%rax)
movapd %xmm0, -0x220(%rbp)
movslq -0x58(%rbp), %r14
leaq -0xd0(%rbp), %rdi
movq %r14, %rsi
callq 0x4b9e8
leaq -0x220(%rbp), %rdi
movq %rax, %rsi
callq 0x4bc3a
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
callq 0x4bc6a
leaq -0x330(%rbp), %rdi
movq %rax, %rsi
callq 0x4bc8c
leaq -0x330(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x4bc3a
movsd -0x40(%rbp), %xmm0
mulsd 0xbc40e(%rip), %xmm0    # 0x1016f8
movsd %xmm0, -0x40(%rbp)
movl -0x58(%rbp), %r13d
xorl %r14d, %r14d
testl %ebx, %ebx
cmovlel %r14d, %ebx
leaq -0xa0(%rbp), %r15
leaq -0x400(%rbp), %r12
cmpq %r14, %rbx
je 0x453a8
cmpq %r14, %r13
je 0x453a0
movq %r15, %rdi
movq %r14, %rsi
callq 0x4bc6a
movsd -0x40(%rbp), %xmm0
ucomisd 0xa8(%rax), %xmm0
jbe 0x453a0
leaq -0xd0(%rbp), %rdi
movq %r14, %rsi
callq 0x4b9e8
movq %rax, %rdi
leaq -0x220(%rbp), %rsi
callq 0x780c7
testb %al, %al
je 0x453a0
leaq -0xd0(%rbp), %rdi
movq %r14, %rsi
callq 0x4b9e8
leaq -0x220(%rbp), %rdi
movq %rax, %rsi
callq 0x4bc3a
movq %r15, %rdi
movq %r14, %rsi
callq 0x4bc6a
movq %r12, %rdi
movq %rax, %rsi
callq 0x4bc8c
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x4bc3a
movq %r12, %rdi
callq 0x4bb60
incq %r14
jmp 0x4530a
leaq -0x330(%rbp), %rdi
callq 0x4bb60
leaq -0x220(%rbp), %rdi
callq 0x4bcbe
leaq -0xd0(%rbp), %rdi
callq 0x4bcbe
leaq -0xa0(%rbp), %rdi
callq 0x4bce0
leaq -0xf0(%rbp), %rdi
callq 0xad7e
leaq -0x130(%rbp), %rdi
callq 0xad7e
leaq -0x110(%rbp), %rdi
callq 0xad7e
leaq -0x150(%rbp), %rdi
callq 0xb290
leaq -0x240(%rbp), %rdi
callq 0xb290
movq -0x38(%rbp), %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbd003(%rip), %rdi     # 0x102431
movq -0x30(%rbp), %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x4050
pushq $0x1
popq %rdi
callq 0x524c
jmp 0x454a9
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
jmp 0x4545c
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
callq 0xb290
jmp 0x45552
jmp 0x45468
movq %rax, %rbx
jmp 0x454b8
movq %rax, %rbx
jmp 0x45552
movq %rax, %rbx
leaq -0x400(%rbp), %rdi
callq 0x4bb60
jmp 0x454ac
jmp 0x454a9
jmp 0x4548a
movq %rax, %rbx
jmp 0x454ea
jmp 0x4550e
movq %rax, %rbx
leaq -0x5a0(%rbp), %rdi
jmp 0x454e5
jmp 0x4550e
jmp 0x454a1
movq %rax, %rbx
jmp 0x4556a
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
callq 0x4bb60
leaq -0x220(%rbp), %rdi
callq 0x4bcbe
movq -0x38(%rbp), %rdi
callq 0x4bcbe
jmp 0x4551d
movq %rax, %rbx
leaq -0x4f8(%rbp), %rdi
jmp 0x454e5
movq %rax, %rbx
leaq -0x400(%rbp), %rdi
callq 0x4bb60
leaq -0x330(%rbp), %rdi
callq 0x4bb60
jmp 0x45511
movq %rax, %rbx
jmp 0x4551d
jmp 0x4550e
jmp 0x4550e
jmp 0x4550e
jmp 0x45537
jmp 0x4550e
jmp 0x4550e
movq %rax, %rbx
jmp 0x45546
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0xb290
leaq -0xd0(%rbp), %rdi
callq 0x4bcbe
leaq -0xa0(%rbp), %rdi
callq 0x4bce0
jmp 0x45546
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
callq 0xb290
leaq -0xf0(%rbp), %rdi
callq 0xad7e
leaq -0x130(%rbp), %rdi
callq 0xad7e
leaq -0x110(%rbp), %rdi
callq 0xad7e
leaq -0x150(%rbp), %rdi
callq 0xb290
leaq -0x240(%rbp), %rdi
callq 0xb290
movq %rbx, %rdi
callq 0x4780