// File: /workspace/github_c_makefile_star2_O2/aremmell[P]libsir/tests/tests.c
// Function: main
int main(int argc, char** argv) {
#if defined(__HAIKU__) && !defined(DEBUG)
    disable_debugger(1);
#endif

#include "tests_malloc.h"

#if !defined(__WIN__) && !defined(__HAIKU__) && !defined(__EMSCRIPTEN__)
    /* Disallow execution by root / sudo; some of the tests rely on lack of permissions. */
    if (geteuid() == 0) {
        (void)fprintf(stderr, "Sorry, but this program may not be executed by root." SIR_EOL);
        return EXIT_FAILURE;
    }
#else /* __WIN__ */
# if defined(_DEBUG) && defined(SIR_ASSERT_ENABLED)
    /* Prevents assert() from calling abort() before the user is able to:
     * a.) break into the code and debug (Retry button)
     * b.) ignore the assert() and continue. */
    _set_error_mode(_OUT_TO_MSGBOX);
# endif
#endif

    bool parsed = parse_cmd_line(argc, argv, cl_args, _sir_countof(cl_args),
        sir_tests, _sir_countof(sir_tests), &cl_cfg);
    if (!parsed)
        return EXIT_FAILURE;

    size_t first     = (cl_cfg.only ? 0 : 1);
    size_t tgt_tests = (cl_cfg.only ? cl_cfg.to_run : _sir_countof(sir_tests) - first);
    size_t passed    =  0;
    size_t ran       =  0;
    sir_time timer   = {0};

    print_intro(tgt_tests);
    sir_timer_start(&timer);

    for (size_t n = first; n < _sir_countof(sir_tests); n++) {
        if (cl_cfg.only && !sir_tests[n].run) {
            _sir_selflog("skipping '%s'; not marked to run", sir_tests[n].name);
            continue;
        }

        print_test_intro(ran + 1, tgt_tests, sir_tests[n].name);

        sir_tests[n].pass = sir_tests[n].fn();
        if (sir_tests[n].pass)
            passed++;

        ran++;

        print_test_outro(ran, tgt_tests, sir_tests[n].name, sir_tests[n].pass);
    }

    print_test_summary(tgt_tests, passed, sir_timer_elapsed(&timer));

    if (passed != tgt_tests) {
        print_failed_test_intro(tgt_tests, passed);

        for (size_t t = 0; t < _sir_countof(sir_tests); t++)
            if (!sir_tests[t].pass)
                print_failed_test(sir_tests[t].name);
        (void)printf(SIR_EOL);
    }

    if (cl_cfg.wait)
        wait_for_keypress();

    return passed == tgt_tests ? EXIT_SUCCESS : EXIT_FAILURE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movl %edi, %ebp
callq 0x3200
testl %eax, %eax
je 0x41e1
leaq 0x1776d(%rip), %rax     # 0x1b908
movq %rax, (%rsp)
leaq 0x166fa(%rip), %rdx     # 0x1a8a0
leaq 0x17163(%rip), %rbx     # 0x1b310
pushq $0x7
popq %rcx
pushq $0x25
popq %r9
movl %ebp, %edi
movq %r14, %rsi
movq %rbx, %r8
callq 0x3bd0
testb %al, %al
je 0x4203
movzbl 0x1773e(%rip), %eax     # 0x1b90a
movq %rax, %r12
xorq $0x1, %r12
testq %rax, %rax
je 0x420b
movq 0x17731(%rip), %r14     # 0x1b910
jmp 0x420f
movq 0x16e10(%rip), %rax     # 0x1aff8
movq (%rax), %rdi
leaq 0xc2e6(%rip), %rdx      # 0x104d8
pushq $0x1
popq %rbx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3520
jmp 0x42f8
pushq $0x1
popq %rbx
jmp 0x42f8
pushq $0x24
popq %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movq %r14, %rdi
callq 0x36ec
movq %r15, %rdi
callq 0x4309
imulq $0x18, %r12, %r13
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpq $0x378, %r13            # imm = 0x378
je 0x4288
cmpb $0x1, 0x176c5(%rip)     # 0x1b90a
jne 0x424f
cmpb $0x1, 0x10(%r13,%rbx)
jne 0x4282
incq %r12
movq (%r13,%rbx), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x3748
callq *0x8(%r13,%rbx)
movb %al, 0x11(%r13,%rbx)
movzbl %al, %ecx
addq %rcx, %r15
movq (%r13,%rbx), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x3762
addq $0x18, %r13
jmp 0x4235
leaq 0x10(%rsp), %rdi
callq 0x4313
movq %r14, %rdi
movq %r15, %rsi
callq 0x3793
cmpq %r14, %r15
je 0x42e2
movq %r14, %rdi
movq %r15, %rsi
callq 0x37fe
pushq $0x11
popq %r12
cmpq $0x389, %r12            # imm = 0x389
je 0x42d1
cmpb $0x0, (%r12,%rbx)
jne 0x42cb
movq -0x11(%r12,%rbx), %rdi
callq 0x3828
addq $0x18, %r12
jmp 0x42b1
leaq 0xbfee(%rip), %rsi      # 0x102c6
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x3410
cmpb $0x1, 0x17620(%rip)     # 0x1b909
jne 0x42f0
callq 0x3ec1
xorl %ebx, %ebx
cmpq %r14, %r15
setne %bl
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq