// File: /workspace/github_cpp_makefile_star2_O2/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, 0xa989(%rip)      # 0xe228
je 0x3b42
movq 0xa93c(%rip), %rax      # 0xe1e8
movq 0xa92d(%rip), %rsi      # 0xe1e0
cmpq %rsi, %rax
je 0x3b57
cmpl $-0x1, -0x28(%rax)
je 0x3b6c
leaq 0x20(%rsp), %rcx
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
xorl %r12d, %r12d
leaq 0x50(%rsp), %rbx
pushq $0x50
popq %r13
leaq 0x48(%rsp), %r14
leaq 0x18(%rsp), %r15
movl %r12d, %r12d
subq %rsi, %rax
cqto
idivq %r13
cmpq %r12, %rax
jbe 0x3952
imulq $0x50, %r12, %rax
addq %rax, %rsi
movq %r14, %rdi
callq 0x3c70
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3cc4
incl (%rax)
cmpl $0x1, 0x70(%rsp)
jne 0x3937
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3cc4
incl 0x4(%rax)
movq %r14, %rdi
callq 0x3c56
incl %r12d
movq 0xa89f(%rip), %rax      # 0xe1e8
movq 0xa890(%rip), %rsi      # 0xe1e0
jmp 0x38f6
movq 0xa67f(%rip), %rbp      # 0xdfd8
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0x3250
movq (%rbp), %rcx
leaq 0x5a42(%rip), %rdi      # 0x93b2
pushq $0x2c
popq %rbx
pushq $0x1
popq %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3370
movq (%rbp), %rcx
leaq 0x5a52(%rip), %rdi      # 0x93df
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3370
xorl %r14d, %r14d
movq 0x30(%rsp), %r13
leaq 0x48(%rsp), %r12
leaq 0xa84c(%rip), %r15      # 0xe1f8
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
leaq 0x20(%rsp), %rax
cmpq %rax, %r13
je 0x3a6c
leaq 0x20(%r13), %rsi
movq %r12, %rdi
callq 0x32a0
movl 0x40(%r13), %ecx
movl 0x44(%r13), %r8d
testl %r8d, %r8d
jne 0x39e9
incl %ebx
jmp 0x39f8
cmpl %ecx, %r8d
jge 0x39f4
incl 0xc(%rsp)
jmp 0x39f8
incl 0x8(%rsp)
movq (%rbp), %rdi
movq 0x48(%rsp), %rdx
cvtsi2sd %r8d, %xmm0
mulsd 0x55fa(%rip), %xmm0     # 0x9008
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
leaq 0x59ef(%rip), %rsi      # 0x940c
movb $0x1, %al
callq 0x32b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x40a2
leaq 0xa7ca(%rip), %rcx      # 0xe200
cmpq %rcx, %rax
jne 0x3a51
movq (%rbp), %rcx
leaq 0x59ea(%rip), %rdi      # 0x9430
pushq $0x2c
popq %rsi
pushq $0x1
popq %rdx
callq 0x3370
movq %r13, %rdi
callq 0x3210
movq %rax, %r13
movq %r12, %rdi
callq 0x30d0
incl %r14d
jmp 0x39be
movq (%rbp), %rcx
leaq 0x5968(%rip), %rdi      # 0x93df
pushq $0x2c
popq %rsi
pushq $0x1
popq %rdx
callq 0x3370
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0x3250
movq (%rbp), %rdi
leaq 0x59c4(%rip), %rsi      # 0x945d
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%rbp), %rdi
movl 0x8(%rsp), %edx
cvtsi2sd %edx, %xmm0
movsd 0x5551(%rip), %xmm1     # 0x9008
mulsd %xmm1, %xmm0
cvtsi2sd %r14d, %xmm1
movsd %xmm1, 0x10(%rsp)
divsd %xmm1, %xmm0
leaq 0x59ac(%rip), %rsi      # 0x947d
movb $0x1, %al
callq 0x32b0
movq (%rbp), %rdi
movl 0xc(%rsp), %edx
cvtsi2sd %edx, %xmm0
mulsd 0x551c(%rip), %xmm0     # 0x9008
divsd 0x10(%rsp), %xmm0
leaq 0x59ae(%rip), %rsi      # 0x94a7
movb $0x1, %al
callq 0x32b0
movq (%rbp), %rdi
cvtsi2sd %ebx, %xmm0
mulsd 0x54f8(%rip), %xmm0     # 0x9008
divsd 0x10(%rsp), %xmm0
leaq 0x59b4(%rip), %rsi      # 0x94d1
movl %ebx, %edx
movb $0x1, %al
callq 0x32b0
leaq 0x18(%rsp), %rdi
callq 0x3d9a
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa48f(%rip), %rax      # 0xdfd8
movq (%rax), %rcx
leaq 0x577b(%rip), %rdi      # 0x92ce
pushq $0x5b
jmp 0x3b7f
movq 0xa47a(%rip), %rax      # 0xdfd8
movq (%rax), %rcx
leaq 0x57c2(%rip), %rdi      # 0x932a
pushq $0x3c
jmp 0x3b7f
movq 0xa465(%rip), %rax      # 0xdfd8
movq (%rax), %rcx
leaq 0x57ea(%rip), %rdi      # 0x9367
pushq $0x4a
popq %rsi
pushq $0x1
popq %rdx
callq 0x3370
pushq $0x1
popq %rdi
callq 0x3230
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x30d0
jmp 0x3bb3
jmp 0x3ba1
movq %rax, %rbx
jmp 0x3bb3
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3c56
leaq 0x18(%rsp), %rdi
callq 0x3d9a
movq %rbx, %rdi
callq 0x3330
nop