// File: /workspace/github_c_makefile_star2_O1/aremmell[P]libsir/tests/tests.c
// Function: threadrace_thread
unsigned __stdcall threadrace_thread(void* arg) {
#endif
    pid_t threadid       = _sir_gettid();
    thread_args* my_args = (thread_args*)arg;

    rmfile(my_args->log_file, cl_cfg.leave_logs);
    sirfileid id = sir_addfile(my_args->log_file, SIRL_ALL, SIRO_MSGONLY);

    if (0U == id) {
        bool unused = print_test_error(false, false);
        SIR_UNUSED(unused);
#if !defined(__WIN__)
        return NULL;
#else /* __WIN__ */
        return 0;
#endif
    }

    TEST_MSG("hi, i'm thread (id: " SIR_TIDFORMAT "), logging to: '%s'...",
            PID_CAST threadid, my_args->log_file);

#if !defined(DUMA)
# if !defined(__EMSCRIPTEN__)
#  define NUM_ITERATIONS 400
# else
#  define NUM_ITERATIONS 200
# endif
#else
# define NUM_ITERATIONS 100
#endif

    for (size_t n = 0; n < NUM_ITERATIONS; n++) {
        /* choose a random level, and colors. */
        sir_textcolor fg = SIRTC_DEFAULT;
        sir_textcolor bg = SIRTC_DEFAULT;

        if (n % 2 == 0) {
            fg = SIRTC_CYAN;
            bg = SIRTC_BLACK;
            (void)sir_debug("log message #%zu", n);
        } else {
            fg = SIRTC_BLACK;
            bg = SIRTC_CYAN;
            (void)sir_info("log message #%zu", n);
        }

        /* sometimes remove and re-add the log file, and set some options/styles.
         * other times, just set different options/styles. */
        uint32_t rnd = (uint32_t)(n + threadid);
        if (getrand_bool(rnd > 1U ? rnd : 1U)) {
            my_args->pass = print_test_error(sir_remfile(id), false);
            my_args->pass = print_test_error(0 != sir_addfile(my_args->log_file,
                SIRL_ALL, SIRO_MSGONLY), false);

            bool test = sir_settextstyle(SIRL_DEBUG, SIRTA_EMPH, fg, bg) &&
                        sir_settextstyle(SIRL_INFO, SIRTA_BOLD, fg, bg);
            my_args->pass = print_test_error(test, false);

            test = sir_stdoutopts(SIRO_NONAME | SIRO_NOHOST | SIRO_NOMSEC);
            my_args->pass = print_test_error(test, false);
        } else {
            bool test = sir_settextstyle(SIRL_DEBUG, SIRTA_ULINE, fg, bg) &&
                        sir_settextstyle(SIRL_INFO, SIRTA_NORMAL, fg, bg);
            my_args->pass = print_test_error(test, false);

            test = sir_fileopts(id, SIRO_NOPID | SIRO_NOHOST);
            my_args->pass = print_test_error(test, false);

            test = sir_stdoutopts(SIRO_NOTIME | SIRO_NOLEVEL);
            my_args->pass = print_test_error(test, false);
        }

        if (!my_args->pass)
            break;
    }

    my_args->pass = print_test_error(sir_remfile(id), false);

    rmfile(my_args->log_file, cl_cfg.leave_logs);

#if !defined(__WIN__)
    return NULL;
#else /* __WIN__ */
    return 0U;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
callq 0xe2c3
movl %eax, %ebp
movzbl 0x120bf(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x4053
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa045
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x9a11
leaq 0xb528(%rip), %rsi      # 0x14d8e
xorl %r14d, %r14d
movl $0x1, %edi
movl %ebp, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3400
movl %ebp, %eax
movq %rax, 0x10(%rsp)
testb $0x1, %r14b
jne 0x98a3
xorl %r12d, %r12d
leaq 0xb52c(%rip), %rdi      # 0x14dbd
movq %r14, %rsi
xorl %eax, %eax
callq 0x9a55
movl $0x6, %r13d
jmp 0x98bd
xorl %r13d, %r13d
leaq 0xb510(%rip), %rdi      # 0x14dbd
movq %r14, %rsi
xorl %eax, %eax
callq 0x9b13
movl $0x6, %r12d
movq 0x10(%rsp), %rcx
leal (%rcx,%r14), %eax
cmpl $0x1, %eax
movl %ecx, %edi
adcl %r14d, %edi
callq 0x403f
testb $0x1, %al
jne 0x9952
movl 0xc(%rsp), %edi
callq 0xa04a
movzbl %al, %edi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa045
xorl %edi, %edi
testl %eax, %eax
setne %dil
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
movl $0x80, %edi
movl $0x3, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0dc
movl $0x1600, %ebp           # imm = 0x1600
testb %al, %al
je 0x99a7
movl $0x40, %edi
movl $0x1, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0dc
movl %eax, %r15d
jmp 0x99a7
movl $0x80, %edi
movl $0x4, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0dc
testb %al, %al
je 0x997f
movl $0x40, %edi
xorl %esi, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0dc
jmp 0x9981
xorl %eax, %eax
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
movl 0xc(%rsp), %edi
movl $0x2400, %esi           # imm = 0x2400
callq 0xa09b
movl %eax, %r15d
movl $0x900, %ebp            # imm = 0x900
movzbl %r15b, %edi
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
movl %ebp, %edi
callq 0xa164
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
testb %al, %al
je 0x99e7
leaq 0x1(%r14), %rax
cmpq $0x18f, %r14            # imm = 0x18F
movq %rax, %r14
jne 0x9881
movl 0xc(%rsp), %edi
callq 0xa04a
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
movb %al, 0x1000(%rbx)
movzbl 0x11ef1(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x4053
jmp 0x9a1a
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b04
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop