// File: hanhwi[P]SimPoint/analysiscode/Simpoint.cpp
// Function: Simpoint::findBestRun()
int Simpoint::findBestRun() {
    int bestRun = 0;
    if (options.kValues.size() > 1) {
        double min_bic = bicScores[0], max_bic = bicScores[0];
        for (unsigned int i = 1; i < options.kValues.size(); i++) {
            if (bicScores[i] > max_bic) { max_bic = bicScores[i]; }
            if (bicScores[i] < min_bic) { min_bic = bicScores[i]; }
        }

        double threshold = (max_bic - min_bic) * options.bicThreshold + min_bic;
        bestRun = -1;
        for (unsigned int i = 0; i < options.kValues.size(); i++) {
            if ((bicScores[i] >= threshold) &&
                ((bestRun == -1) || (options.kValues[i] < options.kValues[bestRun]))) {
                bestRun = i;
            }
        }
    }

    return bestRun;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq 0x50(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movl $0x0, 0x4c(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
callq 0x10df0
cmpq $0x1, %rax
jbe 0x164bc
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9ba0
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
addq $0x40, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x1, 0x34(%rsp)
movq 0x18(%rsp), %rdi
movl 0x34(%rsp), %eax
movq %rax, 0x10(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
callq 0x10df0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x163d0
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
movl 0x34(%rsp), %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x1637c
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
movl 0x34(%rsp), %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
movl 0x34(%rsp), %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm1
movsd 0x40(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x163be
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
movl 0x34(%rsp), %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x163c0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x16312
movq 0x18(%rsp), %rax
movsd 0x38(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd 0xd8(%rax), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x24(%rsp)
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %eax
movq %rax, 0x8(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
callq 0x10df0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x164ba
movq 0x18(%rsp), %rdi
addq $0x40, %rdi
movl 0x24(%rsp), %eax
movl %eax, %esi
callq 0x9ba0
movsd (%rax), %xmm0
ucomisd 0x28(%rsp), %xmm0
jb 0x164a8
cmpl $-0x1, 0x4c(%rsp)
je 0x164a0
movq 0x18(%rsp), %rdi
addq $0x58, %rdi
addq $0x38, %rdi
movl 0x24(%rsp), %eax
movl %eax, %esi
callq 0x10dd0
movq 0x18(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x4(%rsp)
addq $0x58, %rdi
addq $0x38, %rdi
movslq 0x4c(%rsp), %rsi
callq 0x10dd0
movq %rax, %rcx
movl 0x4(%rsp), %eax
cmpl (%rcx), %eax
jge 0x164a8
movl 0x24(%rsp), %eax
movl %eax, 0x4c(%rsp)
jmp 0x164aa
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1640d
jmp 0x164bc
movl 0x4c(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)