// File: Chrom3D[P]Chrom3D/src/MCMC.cpp
// Function: MCMC::doMetropolisHastingsStep(double, unsigned int)
bool MCMC::doMetropolisHastingsStep(double T /*=1*/, uint maxAttempts /*=10000*/) {
  uint i=0;
  bool success = false;
  while(i < maxAttempts and !success) {
    try {
      Move proposedMove = model.proposeMove(); // Idea: if this fails (no move proposed), we could set the proposed Move to the same (identity) move.
      double before = model.getPartialLossScore(proposedMove.chr, proposedMove.start, proposedMove.stop); // score before move
      Move oldCoords = model.accept(proposedMove); //, true);
      double after = model.getPartialLossScore(proposedMove.chr, proposedMove.start, proposedMove.stop); // score after move
      if(after > before) {
	double pAccept = exp((before-after)/T);
	bool accept = util::unif_real(0,1, model.randEngine) < pAccept;
	if(not accept) {
	  Move tmp = model.accept(oldCoords); //, true); // roll back to previous coordinates.
	}
      }
      success = true;
    }
    catch(util::MoveException& e){
      i++;
    }
  }
  return success;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movsd %xmm0, 0x118(%rsp)
movl %esi, 0x114(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x110(%rsp)
movb $0x0, 0x10f(%rsp)
movl 0x110(%rsp), %ecx
xorl %eax, %eax
cmpl 0x114(%rsp), %ecx
movb %al, 0x1f(%rsp)
jae 0x389f2
movb 0x10f(%rsp), %al
xorb $-0x1, %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x389ff
jmp 0x38c14
movq 0x20(%rsp), %rax
movq (%rax), %rsi
leaq 0xd0(%rsp), %rdi
movl $0x1, %edx
callq 0x1dfa0
jmp 0x38a1b
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0xd0(%rsp), %rsi
movl 0xd8(%rsp), %edx
movl 0xdc(%rsp), %ecx
callq 0x1d9e0
movsd %xmm0, 0x10(%rsp)
jmp 0x38a46
movq 0x20(%rsp), %rax
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq (%rax), %rsi
leaq 0x80(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x1efa0
jmp 0x38a74
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0xd0(%rsp), %rsi
movl 0xd8(%rsp), %edx
movl 0xdc(%rsp), %ecx
callq 0x1d9e0
movsd %xmm0, 0x8(%rsp)
jmp 0x38a9f
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
ucomisd 0xb8(%rsp), %xmm0
jbe 0x38ba6
movsd 0xb8(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd 0x118(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x8890
movq 0x20(%rsp), %rax
movsd %xmm0, 0x70(%rsp)
movq (%rax), %rdi
addq $0x20, %rdi
xorps %xmm0, %xmm0
movsd 0x16506(%rip), %xmm1    # 0x4f008
callq 0x9940
movsd %xmm0, (%rsp)
jmp 0x38b0e
movsd (%rsp), %xmm1
movsd 0x70(%rsp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movb %al, 0x6f(%rsp)
testb $0x1, 0x6f(%rsp)
jne 0x38ba4
movq 0x20(%rsp), %rax
movq (%rax), %rsi
leaq 0x30(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x1efa0
jmp 0x38b49
leaq 0x30(%rsp), %rdi
callq 0x1a560
jmp 0x38ba4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0x38bd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0x38bca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x1a560
jmp 0x38bca
jmp 0x38ba6
movb $0x1, 0x10f(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x1a560
leaq 0xd0(%rsp), %rdi
callq 0x1a560
jmp 0x38c0f
leaq 0xd0(%rsp), %rdi
callq 0x1a560
movl 0xc4(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x38c25
movq 0xc8(%rsp), %rdi
callq 0x8210
movq %rax, 0x28(%rsp)
movl 0x110(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x110(%rsp)
callq 0x87b0
jmp 0x389cf
movb 0x10f(%rsp), %al
andb $0x1, %al
addq $0x128, %rsp            # imm = 0x128
retq
movq 0xc8(%rsp), %rdi
callq 0x8870
nopw %cs:(%rax,%rax)
nopl (%rax)