// File: /workspace/github_c_makefile_star2_O3/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 0xe0a9
movl %eax, %r15d
movzbl 0x12100(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x40a2
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa035
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x9a02
leaq 0xb569(%rip), %rsi      # 0x14d8e
xorl %r14d, %r14d
movl $0x1, %edi
movl %r15d, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3400
movl %r15d, %ebp
leaq 0xb579(%rip), %r15      # 0x14dbd
movq %rbp, 0x10(%rsp)
testb $0x1, %r14b
jne 0x9867
xorl %r12d, %r12d
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x9a45
movl $0x6, %r13d
jmp 0x987d
xorl %r13d, %r13d
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x9b03
movl $0x6, %r12d
leal (%r14,%rbp), %eax
cmpl $0x1, %eax
movl %ebp, %edi
adcl %r14d, %edi
callq 0x408e
testb $0x1, %al
jne 0x994d
movq %r15, %rbp
movl 0xc(%rsp), %edi
callq 0xa03a
movzbl %al, %edi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0xa035
xorl %edi, %edi
testl %eax, %eax
setne %dil
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movl $0x80, %edi
movl $0x3, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0cc
testb %al, %al
je 0x990d
movl $0x40, %edi
movl $0x1, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0cc
movl %eax, %r15d
movzbl %r15b, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movl $0x1600, %edi           # imm = 0x1600
callq 0xa154
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
testb %al, %al
movq %rbp, %r15
movq 0x10(%rsp), %rbp
jne 0x99c8
jmp 0x99d8
movl $0x80, %edi
movl $0x4, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0cc
testb %al, %al
je 0x997a
movl $0x40, %edi
xorl %esi, %esi
movl %r13d, %edx
movl %r12d, %ecx
callq 0xa0cc
jmp 0x997c
xorl %eax, %eax
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movl 0xc(%rsp), %edi
movl $0x2400, %esi           # imm = 0x2400
callq 0xa08b
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movl $0x900, %edi            # imm = 0x900
callq 0xa154
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
testb %al, %al
je 0x99d8
incq %r14
cmpq $0x190, %r14            # imm = 0x190
jne 0x9849
movl 0xc(%rsp), %edi
callq 0xa03a
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
movb %al, 0x1000(%rbx)
movzbl 0x11f00(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x40a2
jmp 0x9a0b
xorl %edi, %edi
xorl %esi, %esi
callq 0x3b6d
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq