// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq %rdi, %rbx
callq 0xd7d8
movl %eax, %r15d
movzbl 0x1268b(%rip), %esi     # 0x1b908
movq %rbx, %rdi
callq 0x3fbf
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0x9a6b
testl %eax, %eax
je 0x9470
movl %eax, %r12d
leaq 0xaaa5(%rip), %rsi      # 0x13d4e
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movl %r15d, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3410
movl %r15d, %ebp
movq %rbp, (%rsp)
cmpq $0x190, %r14            # imm = 0x190
je 0x9447
testb $0x1, %r14b
jne 0x92f0
xorl %r15d, %r15d
leaq 0xaa9d(%rip), %rdi      # 0x13d7d
movq %r14, %rsi
xorl %eax, %eax
callq 0x94cd
pushq $0x6
popq %r13
jmp 0x9308
xorl %r13d, %r13d
leaq 0xaa83(%rip), %rdi      # 0x13d7d
movq %r14, %rsi
xorl %eax, %eax
callq 0x95a2
pushq $0x6
popq %r15
leal (%r14,%rbp), %eax
cmpl $0x1, %eax
movl %ebp, %edi
adcl %r14d, %edi
callq 0x948a
testb %al, %al
je 0x93c9
movl %r12d, %ebp
movl %r12d, %edi
callq 0x9a70
movzbl %al, %edi
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movq %rbx, %rdi
movl $0xff, %esi
movl $0x7f00, %edx           # imm = 0x7F00
callq 0x9a6b
xorl %edi, %edi
testl %eax, %eax
setne %dil
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movl $0x80, %edi
pushq $0x3
popq %rsi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x9afc
testb %al, %al
je 0x9391
pushq $0x40
popq %rdi
pushq $0x1
popq %rsi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x9afc
movl %eax, %r12d
movzbl %r12b, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movl $0x1600, %edi           # imm = 0x1600
callq 0x9b81
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
testb %al, %al
movl %ebp, %r12d
movq (%rsp), %rbp
jne 0x943f
jmp 0x9447
movl $0x80, %edi
pushq $0x4
popq %rsi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x9afc
testb %al, %al
je 0x93f2
pushq $0x40
popq %rdi
xorl %esi, %esi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x9afc
jmp 0x93f4
xorl %eax, %eax
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movl %r12d, %edi
movl $0x2400, %esi           # imm = 0x2400
callq 0x9abe
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movl $0x900, %edi            # imm = 0x900
callq 0x9b81
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
testb %al, %al
je 0x9447
incq %r14
jmp 0x92c3
movl %r12d, %edi
callq 0x9a70
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
movb %al, 0x1000(%rbx)
movzbl 0x124a2(%rip), %esi     # 0x1b908
movq %rbx, %rdi
callq 0x3fbf
jmp 0x9479
xorl %edi, %edi
xorl %esi, %esi
callq 0x3ac9
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq