// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, %r14
movl %edi, %ebp
callq 0x3200
testl %eax, %eax
je 0x43e9
leaq 0x17665(%rip), %rax     # 0x1b8f8
movq %rax, (%rsp)
leaq 0x165c2(%rip), %rdx     # 0x1a860
leaq 0x1705b(%rip), %rbx     # 0x1b300
movl $0x7, %ecx
movl $0x25, %r9d
movl %ebp, %edi
movq %r14, %rsi
movq %rbx, %r8
callq 0x3c72
movl $0x1, %ebp
testb %al, %al
je 0x440b
movzbl 0x17629(%rip), %eax     # 0x1b8fa
movl %eax, %r13d
xorl $0x1, %r13d
movl $0x24, %r14d
testq %rax, %rax
je 0x42ea
movq 0x17616(%rip), %r14     # 0x1b900
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
movq %r14, %rdi
callq 0x36dc
xorl %r12d, %r12d
xorl %edi, %edi
movq %r15, %rsi
callq 0xdff1
movb 0x175e9(%rip), %al      # 0x1b8fa
shll $0x3, %r13d
leaq (%r13,%r13,2), %r13
xorl %r15d, %r15d
testb $0x1, %al
je 0x4329
cmpb $0x1, 0x10(%r13,%rbx)
jne 0x4362
incq %r12
movq (%r13,%rbx), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x373a
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 0x3756
movb 0x17598(%rip), %al      # 0x1b8fa
addq $0x18, %r13
cmpq $0x378, %r13            # imm = 0x378
jne 0x431d
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xdff1
movq %r14, %rdi
movq %r15, %rsi
callq 0x3789
cmpq %r14, %r15
je 0x43d0
movq %r14, %rdi
movq %r15, %rsi
callq 0x37f6
movl $0x11, %r12d
cmpb $0x0, (%r12,%rbx)
jne 0x43b0
movq -0x11(%r12,%rbx), %rdi
callq 0x3822
addq $0x18, %r12
cmpq $0x389, %r12            # imm = 0x389
jne 0x439f
leaq 0xcf02(%rip), %rsi      # 0x112c6
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
cmpb $0x1, 0x17522(%rip)     # 0x1b8f9
jne 0x43de
callq 0x3f95
xorl %ebp, %ebp
cmpq %r14, %r15
setne %bpl
jmp 0x440b
movq 0x16c08(%rip), %rax     # 0x1aff8
movq (%rax), %rdi
leaq 0xd11e(%rip), %rdx      # 0x11518
movl $0x1, %ebp
movl $0x1, %esi
xorl %eax, %eax
callq 0x3510
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq