// File: AndreRenaud[P]simple_options/./acutest.h
// Function: acutest_run_
static void
acutest_run_(const struct acutest_test_* test, int index, int master_index)
{
    int failed = 1;
    acutest_timer_type_ start, end;

    acutest_current_test_ = test;
    acutest_test_already_logged_ = 0;
    acutest_timer_get_time_(&start);

    if(!acutest_no_exec_) {

#if defined(ACUTEST_UNIX_)

        pid_t pid;
        int exit_code;

        /* Make sure the child starts with empty I/O buffers. */
        fflush(stdout);
        fflush(stderr);

        pid = fork();
        if(pid == (pid_t)-1) {
            acutest_error_("Cannot fork. %s [%d]", strerror(errno), errno);
            failed = 1;
        } else if(pid == 0) {
            /* Child: Do the test. */
            acutest_worker_ = 1;
            failed = (acutest_do_run_(test, index) != 0);
            acutest_exit_(failed ? 1 : 0);
        } else {
            /* Parent: Wait until child terminates and analyze its exit code. */
            waitpid(pid, &exit_code, 0);
            if(WIFEXITED(exit_code)) {
                switch(WEXITSTATUS(exit_code)) {
                    case 0:   failed = 0; break;   /* test has passed. */
                    case 1:   /* noop */ break;    /* "normal" failure. */
                    default:  acutest_error_("Unexpected exit code [%d]", WEXITSTATUS(exit_code));
                }
            } else if(WIFSIGNALED(exit_code)) {
                char tmp[32];
                const char* signame;
                switch(WTERMSIG(exit_code)) {
                    case SIGINT:  signame = "SIGINT"; break;
                    case SIGHUP:  signame = "SIGHUP"; break;
                    case SIGQUIT: signame = "SIGQUIT"; break;
                    case SIGABRT: signame = "SIGABRT"; break;
                    case SIGKILL: signame = "SIGKILL"; break;
                    case SIGSEGV: signame = "SIGSEGV"; break;
                    case SIGILL:  signame = "SIGILL"; break;
                    case SIGTERM: signame = "SIGTERM"; break;
                    default:      sprintf(tmp, "signal %d", WTERMSIG(exit_code)); signame = tmp; break;
                }
                acutest_error_("Test interrupted by %s.", signame);
            } else {
                acutest_error_("Test ended in an unexpected way [%d].", exit_code);
            }
        }

#elif defined(ACUTEST_WIN_)

        char buffer[512] = {0};
        STARTUPINFOA startupInfo;
        PROCESS_INFORMATION processInfo;
        DWORD exitCode;

        /* windows.has no fork(). So we propagate all info into the child
         * through a command line arguments. */
        _snprintf(buffer, sizeof(buffer)-1,
                 "%s --worker=%d %s --no-exec --no-summary %s --verbose=%d --color=%s -- \"%s\"",
                 acutest_argv0_, index, acutest_timer_ ? "--time" : "",
                 acutest_tap_ ? "--tap" : "", acutest_verbose_level_,
                 acutest_colorize_ ? "always" : "never",
                 test->name);
        memset(&startupInfo, 0, sizeof(startupInfo));
        startupInfo.cb = sizeof(STARTUPINFO);
        if(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) {
            WaitForSingleObject(processInfo.hProcess, INFINITE);
            GetExitCodeProcess(processInfo.hProcess, &exitCode);
            CloseHandle(processInfo.hThread);
            CloseHandle(processInfo.hProcess);
            failed = (exitCode != 0);
            if(exitCode > 1) {
                switch(exitCode) {
                    case 3:             acutest_error_("Aborted."); break;
                    case 0xC0000005:    acutest_error_("Access violation."); break;
                    default:            acutest_error_("Test ended in an unexpected way [%lu].", exitCode); break;
                }
            }
        } else {
            acutest_error_("Cannot create unit test subprocess [%ld].", GetLastError());
            failed = 1;
        }

#else

        /* A platform where we don't know how to run child process. */
        failed = (acutest_do_run_(test, index) != 0);

#endif

    } else {
        /* Child processes suppressed through --no-exec. */
        failed = (acutest_do_run_(test, index) != 0);
    }
    acutest_timer_get_time_(&end);

    acutest_current_test_ = NULL;

    acutest_stat_run_units_++;
    if(failed)
        acutest_stat_failed_units_++;

    acutest_set_success_(master_index, !failed);
    acutest_set_duration_(master_index, acutest_timer_diff_(start, end));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, 0x6441(%rip)      # 0xb178
movl $0x0, 0x642f(%rip)      # 0xb170
leaq -0x28(%rbp), %rdi
callq 0x65e0
cmpl $0x0, 0x640b(%rip)      # 0xb15c
jne 0x4f47
movq 0x627a(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x21c0
movq 0x628b(%rip), %rax      # 0xaff8
movq (%rax), %rdi
callq 0x21c0
callq 0x2260
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x3c(%rbp)
jne 0x4db8
callq 0x2060
movl (%rax), %edi
callq 0x2250
movq %rax, -0x70(%rbp)
callq 0x2060
movq -0x70(%rbp), %rsi
movl (%rax), %edx
leaq 0x2f3b(%rip), %rdi      # 0x7ce0
movb $0x0, %al
callq 0x6610
movl $0x1, -0x14(%rbp)
jmp 0x4f45
cmpl $0x0, -0x3c(%rbp)
jne 0x4df7
movl $0x1, 0x6510(%rip)      # 0xb2d8
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x6710
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %ecx
xorl %edi, %edi
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
callq 0x40b0
movl -0x3c(%rbp), %edi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0x21f0
movl -0x40(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x4e54
movzwl -0x40(%rbp), %eax
shrl $0x8, %eax
movl %eax, -0x74(%rbp)
testl %eax, %eax
je 0x4e2a
jmp 0x4e20
movl -0x74(%rbp), %eax
subl $0x1, %eax
je 0x4e33
jmp 0x4e35
movl $0x0, -0x14(%rbp)
jmp 0x4e4f
jmp 0x4e4f
movl -0x40(%rbp), %esi
andl $0xff00, %esi           # imm = 0xFF00
sarl $0x8, %esi
leaq 0x2ead(%rip), %rdi      # 0x7cf5
movb $0x0, %al
callq 0x6610
jmp 0x4f41
movl -0x40(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x4f2e
movl -0x40(%rbp), %eax
andl $0x7f, %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x80(%rbp)
subl $0xe, %eax
ja 0x4efa
movq -0x80(%rbp), %rax
leaq 0x224b(%rip), %rcx      # 0x70d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2e76(%rip), %rax      # 0x7d0f
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e70(%rip), %rax      # 0x7d16
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e6a(%rip), %rax      # 0x7d1d
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e65(%rip), %rax      # 0x7d25
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e60(%rip), %rax      # 0x7d2d
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e5b(%rip), %rax      # 0x7d35
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e56(%rip), %rax      # 0x7d3d
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq 0x2e50(%rip), %rax      # 0x7d44
movq %rax, -0x68(%rbp)
jmp 0x4f1a
leaq -0x60(%rbp), %rdi
movl -0x40(%rbp), %edx
andl $0x7f, %edx
leaq 0x2e41(%rip), %rsi      # 0x7d4c
movb $0x0, %al
callq 0x2230
leaq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rsi
leaq 0x2e31(%rip), %rdi      # 0x7d56
movb $0x0, %al
callq 0x6610
jmp 0x4f3f
movl -0x40(%rbp), %esi
leaq 0x2e36(%rip), %rdi      # 0x7d6e
movb $0x0, %al
callq 0x6610
jmp 0x4f41
jmp 0x4f43
jmp 0x4f45
jmp 0x4f61
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x6710
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x65e0
movq $0x0, 0x6203(%rip) # 0xb178
movl 0x6369(%rip), %eax      # 0xb2e4
addl $0x1, %eax
movl %eax, 0x6360(%rip)      # 0xb2e4
cmpl $0x0, -0x14(%rbp)
je 0x4f99
movl 0x6358(%rip), %eax      # 0xb2e8
addl $0x1, %eax
movl %eax, 0x634f(%rip)      # 0xb2e8
movl -0x10(%rbp), %edi
cmpl $0x0, -0x14(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x6950
movl -0x10(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x5fd0
movl -0x84(%rbp), %edi
callq 0x6990
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)