// File: /workspace/github_cpp_makefile_star2_O3/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 0x3dae
movq 0xb78d(%rip), %rax      # 0xf1e0
movq 0xb77e(%rip), %r14      # 0xf1d8
cmpq %r14, %rax
je 0x3db3
cmpl $-0x1, -0x28(%rax)
je 0x3db8
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)
leaq 0x20(%rsp), %rbx
leaq 0x30(%rsp), %r12
movl $0x1, %ebp
leaq 0x58(%rsp), %r13
leaq (%rax,%rax,4), %r15
shlq $0x4, %r15
movl (%r14,%r15), %eax
movl %eax, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq 0x8(%r14,%r15), %rsi
movq 0x10(%r14,%r15), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x46a6
addq %r15, %r14
movl 0x28(%r14), %eax
movl %eax, 0x40(%rsp)
movq %r13, 0x48(%rsp)
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x46a6
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x3eea
incl (%rax)
cmpl $0x1, 0x40(%rsp)
jne 0x3b13
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x3eea
incl 0x4(%rax)
movq 0x48(%rsp), %rdi
cmpq %r13, %rdi
je 0x3b2a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31e0
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x3b41
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x31e0
movl %ebp, %eax
movq 0xb696(%rip), %rcx      # 0xf1e0
movq 0xb687(%rip), %r14      # 0xf1d8
subq %r14, %rcx
sarq $0x4, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
incl %ebp
cmpq %rax, %rcx
ja 0x3a9e
movq 0xb458(%rip), %rbx      # 0xefd0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x3260
movq (%rbx), %rcx
leaq 0x6823(%rip), %rdi      # 0xa3b2
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq (%rbx), %rcx
leaq 0x6837(%rip), %rdi      # 0xa3df
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq 0x80(%rsp), %r12
xorl %r15d, %r15d
movl $0x0, %ebx
movl $0x0, 0xc(%rsp)
movl $0x0, %r14d
leaq 0x70(%rsp), %rax
cmpq %rax, %r12
je 0x3cc3
xorl %r14d, %r14d
leaq 0x28(%rsp), %rbp
leaq 0x18(%rsp), %r13
movl $0x0, 0xc(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %rbp, 0x18(%rsp)
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x46a6
movl 0x40(%r12), %ecx
movl 0x44(%r12), %r8d
testl %r8d, %r8d
jne 0x3c2a
incl %ebx
jmp 0x3c38
cmpl %ecx, %r8d
jge 0x3c35
incl 0xc(%rsp)
jmp 0x3c38
incl %r14d
movq 0xb391(%rip), %rax      # 0xefd0
movq (%rax), %rdi
movq 0x18(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
mulsd 0x63b1(%rip), %xmm0     # 0xa008
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
leaq 0x67a3(%rip), %rsi      # 0xa40c
movb $0x1, %al
callq 0x32a0
leaq 0xb579(%rip), %rdi      # 0xf1f0
movq %r13, %rsi
callq 0x42e2
leaq 0xb572(%rip), %rcx      # 0xf1f8
cmpq %rcx, %rax
jne 0x3c90
callq 0x34ad
movq %r12, %rdi
callq 0x3220
movq %rax, %r12
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3cb2
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31e0
incl %r15d
leaq 0x70(%rsp), %rax
cmpq %rax, %r12
jne 0x3bfd
movq 0xb306(%rip), %r12      # 0xefd0
movq (%r12), %rcx
leaq 0x670a(%rip), %rdi      # 0xa3df
movl $0x2c, %esi
movl $0x1, %edx
callq 0x3360
movq (%r12), %rsi
movl $0xa, %edi
callq 0x3260
movq (%r12), %rdi
leaq 0x6760(%rip), %rsi      # 0xa45d
movl %r15d, %edx
xorl %eax, %eax
callq 0x32a0
movq (%r12), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x62ed(%rip), %xmm0     # 0xa008
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd %xmm1, 0x10(%rsp)
divsd %xmm1, %xmm0
leaq 0x6749(%rip), %rsi      # 0xa47d
movl %r14d, %edx
movb $0x1, %al
callq 0x32a0
movq (%r12), %rdi
movl 0xc(%rsp), %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd 0x62b3(%rip), %xmm0     # 0xa008
divsd 0x10(%rsp), %xmm0
leaq 0x6745(%rip), %rsi      # 0xa4a7
movb $0x1, %al
callq 0x32a0
movq (%r12), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x628c(%rip), %xmm0     # 0xa008
divsd 0x10(%rsp), %xmm0
leaq 0x6748(%rip), %rsi      # 0xa4d1
movl %ebx, %edx
movb $0x1, %al
callq 0x32a0
leaq 0x68(%rsp), %rdi
callq 0x3fea
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 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3e01
movq 0x28(%rsp), %rsi
jmp 0x3de5
jmp 0x3def
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x3e01
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x31e0
jmp 0x3e01
movq %rax, %rbx
jmp 0x3e01
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x3eb2
leaq 0x68(%rsp), %rdi
callq 0x3fea
movq %rbx, %rdi
callq 0x3330
nop