// File: /workspace/github_cpp_makefile_star2_O1/martinferianc[P]CPUSimulator-EIE2/src/shared/mips_test_framework.cpp
// Function: mips_test_end_suite
void mips_test_end_suite()
{
    if(!sg_started){
        fprintf(stderr, "Error:mips_test_finish_suite - Test suite has not been started with mips_test_begin_suite.\n");
        exit(1);
    }
    if(sg_tests.size()==0){
        fprintf(stderr, "Error:mips_test_finish_suite - No tests have been executed.\n");
        exit(1);
    }
    if(sg_tests.back().status==-1){
        fprintf(stderr, "Error:mips_test_finish_suite - The final test has not been completed yet.\n");
        exit(1);
    }
    
    // Now we will go through an collect some statistics about what happened
    
    // Build a map from instruction name to a pair of (tests,passed)
    typedef std::map<std::string, std::pair<int,int> > stats_t;
    stats_t statistics;
    
    for(unsigned i=0; i<sg_tests.size(); i++){
        test_info_t info=sg_tests[i];
        
        statistics[info.instruction].first++;   // count all tests
        if(info.status==1){
            statistics[info.instruction].second++;  // count the ones that passed
        }
    }
    
    fprintf(stderr, "\n");
    fprintf(stderr, "| Instruction |  tests | passed | success |\n");
    fprintf(stderr, "+-------------+--------+--------+---------+\n");
    
    // Work out what happened for each instruction
    int totalTested=0;
    int totalNotWorking=0;
    int totalPartiallyWorking=0;
    int totalFullyWorking=0;
    
    stats_t::const_iterator it=statistics.begin();
    while(it!=statistics.end()){
        std::string name=it->first;
        int total=it->second.first;
        int passed=it->second.second;
        
        totalTested++;
        if(passed==0){
            totalNotWorking++;
        }else if(passed<total){
            totalPartiallyWorking++;
        }else{
            totalFullyWorking++;
        }
            
        fprintf(stderr, "|%12s |   %4u |   %4u |  %5.1f%% |\n", name.c_str(), total, passed, 100.0*passed/(double)total);
        
        if(sg_knownInstructions.find(name)==sg_knownInstructions.end()){
            fprintf(stderr, "+ Warning: previous instruction not known +\n");
        }
        
        ++it;
    }
   
    fprintf(stderr, "+-------------+--------+--------+---------+\n"); 
    fprintf(stderr, "\n");
    fprintf(stderr, "Total instructions tested: %3u\n", totalTested);
    fprintf(stderr, "Fully working :            %3u (%5.1f%%)\n", totalFullyWorking, 100.0*totalFullyWorking/(double)totalTested);
    fprintf(stderr, "Partially working :        %3u (%5.1f%%)\n", totalPartiallyWorking, 100.0*totalPartiallyWorking/(double)totalTested);
    fprintf(stderr, "Not working at all :       %3u (%5.1f%%)\n", totalNotWorking, 100.0*totalNotWorking/(double)totalTested);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
cmpb $0x0, 0xb7da(%rip)      # 0xf220
je 0x3db9
movq 0xb78d(%rip), %rax      # 0xf1e0
cmpq 0xb77e(%rip), %rax      # 0xf1d8
je 0x3dbe
cmpl $-0x1, -0x28(%rax)
je 0x3dc3
leaq 0x70(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq 0xb74a(%rip), %r15      # 0xf1d8
cmpq %r15, 0xb74b(%rip)      # 0xf1e0
je 0x3b84
leaq 0x20(%rsp), %r14
leaq 0x30(%rsp), %r13
movl $0x1, %ebp
leaq 0x58(%rsp), %rbx
xorl %eax, %eax
leaq (%rax,%rax,4), %r12
shlq $0x4, %r12
movl (%r15,%r12), %eax
movl %eax, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq 0x8(%r15,%r12), %rsi
movq 0x10(%r15,%r12), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x46aa
addq %r12, %r15
movl 0x28(%r15), %eax
movl %eax, 0x40(%rsp)
movq %rbx, 0x48(%rsp)
movq 0x30(%r15), %rsi
movq 0x38(%r15), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x46aa
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x3ef4
incl (%rax)
cmpl $0x1, 0x40(%rsp)
jne 0x3b26
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x3ef4
incl 0x4(%rax)
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3b3d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31e0
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x3b54
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x31e0
movl %ebp, %eax
movq 0xb683(%rip), %rcx      # 0xf1e0
movq 0xb674(%rip), %r15      # 0xf1d8
subq %r15, %rcx
sarq $0x4, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
incl %ebp
cmpq %rax, %rcx
ja 0x3ab1
movq 0xb445(%rip), %rbx      # 0xefd0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x3260
movq (%rbx), %rcx
leaq 0x6810(%rip), %rdi      # 0xa3b2
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq (%rbx), %rcx
leaq 0x6824(%rip), %rdi      # 0xa3df
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq 0x80(%rsp), %r12
movl $0x0, %ebp
movl $0x0, 0xc(%rsp)
movl $0x0, %r15d
leaq 0x70(%rsp), %rax
cmpq %rax, %r12
movl $0x0, %ebx
je 0x3cd6
xorl %r15d, %r15d
leaq 0x28(%rsp), %r14
leaq 0x18(%rsp), %r13
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %r14, 0x18(%rsp)
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x46aa
movl 0x40(%r12), %ecx
movl 0x44(%r12), %r8d
testl %r8d, %r8d
jne 0x3c3e
incl %ebp
jmp 0x3c4c
cmpl %ecx, %r8d
jge 0x3c49
incl 0xc(%rsp)
jmp 0x3c4c
incl %r15d
movq 0xb37d(%rip), %rax      # 0xefd0
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd 0x639d(%rip), %xmm0     # 0xa008
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
leaq 0x678f(%rip), %rsi      # 0xa40c
movb $0x1, %al
callq 0x32a0
leaq 0xb565(%rip), %rdi      # 0xf1f0
movq %r13, %rsi
callq 0x42e6
leaq 0xb55e(%rip), %rcx      # 0xf1f8
cmpq %rcx, %rax
jne 0x3ca4
callq 0x34ad
movq %r12, %rdi
callq 0x3220
movq %rax, %r12
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x3cc6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31e0
incl %ebx
leaq 0x70(%rsp), %rax
cmpq %rax, %r12
jne 0x3c11
movq 0xb2f3(%rip), %r14      # 0xefd0
movq (%r14), %rcx
leaq 0x66f8(%rip), %rdi      # 0xa3df
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq (%r14), %rsi
movl $0xa, %edi
callq 0x3260
movq (%r14), %rdi
leaq 0x6750(%rip), %rsi      # 0xa45d
movl %ebx, %edx
xorl %eax, %eax
callq 0x32a0
movq (%r14), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x62df(%rip), %xmm0     # 0xa008
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd %xmm1, 0x10(%rsp)
divsd %xmm1, %xmm0
leaq 0x673c(%rip), %rsi      # 0xa47d
movl %r15d, %edx
movb $0x1, %al
callq 0x32a0
movq (%r14), %rdi
movl 0xc(%rsp), %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd 0x62a7(%rip), %xmm0     # 0xa008
divsd 0x10(%rsp), %xmm0
leaq 0x6739(%rip), %rsi      # 0xa4a7
movb $0x1, %al
callq 0x32a0
movq (%r14), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x6281(%rip), %xmm0     # 0xa008
divsd 0x10(%rsp), %xmm0
leaq 0x673d(%rip), %rsi      # 0xa4d1
movl %ebp, %edx
movb $0x1, %al
callq 0x32a0
leaq 0x68(%rsp), %rdi
callq 0x3ff4
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3488
callq 0x34f4
callq 0x34cf
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x3e0c
movq 0x30(%rsp), %rsi
jmp 0x3df0
jmp 0x3dfa
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x3e0c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31e0
jmp 0x3e0c
movq %rax, %rbx
jmp 0x3e0c
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3ebc
leaq 0x68(%rsp), %rdi
callq 0x3ff4
movq %rbx, %rdi
callq 0x3330