// File: UCBASiCS[P]SPRIGHT/src/experimentoutput.cpp
// Function: ExperimentOutput::checkMissedLocationsOrBinningFailure()
void ExperimentOutput::checkMissedLocationsOrBinningFailure()
{
    // indices of missed locations
    std::set<int> missedLocations;
    binningFailure = false;


    // if there are no false detections in the current iteration
    if (falseDetectionsIterationNb == 0)
    {
        // go over the true frequencies
        for (auto it = input->getNonZeroFrequencies().cbegin(); it != input->getNonZeroFrequencies().cend(); ++it)
        {
            // if the frequency is missing in the decoded frequencies
            if (backEnd->getDecodedFrequencies().count(it->first) == 0)
            {
                // add the missing location to the missed locations
                missedLocations.insert(it->first);
            }
        }

        // if there is a missing location check if it is due to binning failure
        if (!missedLocations.empty())
        {
            binningFailure = isBinningFailure(missedLocations);
        }
    }

    if (binningFailure)
    {
        binningFailuresNb++;
        missedLocationsIterationNb = 0;
        
        // if it is a binning failure, increment the counter for trapping set size
        // that is held with the unordered_map trappingSetSizeCounter
        auto it = trappingSetSizeCounter.find( missedLocations.size() );
        if( it != trappingSetSizeCounter.end() )  
        {
            it->second =  it->second + 1;
        }
        else
        {
            trappingSetSizeCounter[ missedLocations.size() ] = 1;
        }
    }
    else
    {
        missedLocationsIterationNb = missedLocations.size();
    }

    missedLocationsNbs.push_back(missedLocationsIterationNb);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5960
movq -0xc0(%rbp), %rax
movb $0x0, 0x40(%rax)
cmpl $0x0, 0x38(%rax)
jne 0x1646c
movq -0xc0(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x15310
movq %rax, -0xc8(%rbp)
jmp 0x16301
movq -0xc8(%rbp), %rdi
callq 0x5bb0
movq %rax, -0x40(%rbp)
movq -0xc0(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x15310
movq %rax, -0xd0(%rbp)
jmp 0x1632a
movq -0xd0(%rbp), %rdi
callq 0x5c10
movq %rax, -0x58(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x5be0
testb $0x1, %al
jne 0x16350
jmp 0x163f2
movq -0xc0(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x5750
movq %rax, -0xd8(%rbp)
jmp 0x16369
leaq -0x40(%rbp), %rdi
callq 0x5c70
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x5b30
movq %rax, -0xe0(%rbp)
jmp 0x1638a
movq -0xe0(%rbp), %rax
cmpq $0x0, %rax
jne 0x163e2
leaq -0x40(%rbp), %rdi
callq 0x5c70
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x11fe0
movb %dl, -0xe9(%rbp)
movq %rax, -0xe8(%rbp)
jmp 0x163bb
movb -0xe9(%rbp), %al
movq -0xe8(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movb %al, -0x60(%rbp)
jmp 0x163e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x165dc
jmp 0x163e4
leaq -0x40(%rbp), %rdi
callq 0x5ca0
jmp 0x16311
leaq -0x38(%rbp), %rdi
callq 0x173b0
testb $0x1, %al
jne 0x1646a
leaq -0x98(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x173d0
jmp 0x16411
movq -0xc0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x17000
movb %al, -0xea(%rbp)
jmp 0x1642c
movq -0xc0(%rbp), %rax
movb -0xea(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x40(%rax)
leaq -0x98(%rbp), %rdi
callq 0x5980
jmp 0x1646a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5980
jmp 0x165dc
jmp 0x1646c
movq -0xc0(%rbp), %rax
testb $0x1, 0x40(%rax)
je 0x1658f
movq -0xc0(%rbp), %rax
movl 0xd8(%rax), %ecx
incl %ecx
movl %ecx, 0xd8(%rax)
movl $0x0, 0x3c(%rax)
addq $0xa0, %rax
movq %rax, -0x100(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5cd0
movq -0x100(%rbp), %rdi
movl %eax, -0xa4(%rbp)
leaq -0xa4(%rbp), %rsi
callq 0x17400
movq %rax, -0xf8(%rbp)
jmp 0x164d1
movq -0xc0(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq %rax, -0xa0(%rbp)
addq $0xa0, %rdi
callq 0x17430
movq %rax, -0xb0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x172c0
testb $0x1, %al
jne 0x16512
jmp 0x16541
leaq -0xa0(%rbp), %rdi
callq 0x17460
movl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x17460
movl -0x104(%rbp), %ecx
movl %ecx, 0x4(%rax)
jmp 0x1658d
movq -0xc0(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x118(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5cd0
movq -0x118(%rbp), %rdi
movl %eax, -0xb4(%rbp)
leaq -0xb4(%rbp), %rsi
callq 0x17490
movq %rax, -0x110(%rbp)
jmp 0x16580
movq -0x110(%rbp), %rax
movl $0x1, (%rax)
jmp 0x165a5
leaq -0x38(%rbp), %rdi
callq 0x5cd0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0xc0(%rbp), %rax
movq %rax, %rdi
addq $0x70, %rdi
movl 0x3c(%rax), %eax
movl %eax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x17380
jmp 0x165ca
leaq -0x38(%rbp), %rdi
callq 0x5980
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x5980
movq -0x48(%rbp), %rdi
callq 0x4540
nop