// File: /workspace/github_c_makefile_star2_O2/aremmell[P]libsir/tests/tests.c
// Function: sirtest_threadidsanity
bool sirtest_threadidsanity(void)
{
#if defined(SIR_NO_THREAD_NAMES)
    TEST_MSG_0(SIR_DGRAY("test skipped for this system configuration"));
    return true;
#endif
    INIT(si, SIRL_ALL, 0, 0, 0);
    bool pass = si_init;

    static const char* thread_name = "mythread";
    static const char* logfilename = MAKE_LOG_NAME("thread-id-name.log");

    TEST_MSG("adding log file '%s' to libsir...", logfilename);
    sirfileid id = sir_addfile(logfilename, SIRL_DEBUG, SIRO_NOHDR | SIRO_NOHOST);
    _sir_eqland(pass, 0U != id);

    (void)print_test_error(pass, false);

    TEST_MSG_0("logging a message normally...");
    _sir_eqland(pass, sir_debug("this is a test of the libsir system"));

    TEST_MSG("setting the thread name to '%s' and logging again...", thread_name);

    _sir_eqland(pass, _sir_setthreadname(thread_name));
    sir_sleep_msec((uint32_t)SIR_THRD_CHK_INTERVAL + 200U);

    (void)print_test_error(pass, false);

    _sir_eqland(pass, sir_debug("this is a test of the libsir system after setting thread name"));

    TEST_MSG_0("setting the thread name to '' and logging again...");

    _sir_eqland(pass, _sir_setthreadname(""));
    sir_sleep_msec((uint32_t)SIR_THRD_CHK_INTERVAL + 200U);

    (void)print_test_error(pass, false);

    _sir_eqland(pass, sir_debug("this is a test of the libsir system after clearing thread name"));

     /* remove the log file from libsir, then open it and read it line by line. */
    TEST_MSG("removing %s from libsir...", logfilename);
    _sir_eqland(pass, sir_remfile(id));

    TEST_MSG("opening %s for reading...", logfilename);

    FILE* f = fopen(logfilename, "r");
    if (!f) {
        pass = false;
    } else {
        /* look for, in order, TID, thread name, TID. */
        for (size_t n = 0; n < 3; n++) {
            char buf[256] = {0};
            _sir_eqland(pass, 0 != sir_readline(f, buf, 256));
            TEST_MSG("read line %zu: '%s'", n, buf);

            char search[SIR_MAXPID] = {0};
            switch (n) {
                case 0:
                case 2:
                    (void)snprintf(search, SIR_MAXPID, SIR_TIDFORMAT, _sir_gettid());
                break;
                case 1:
                    (void)_sir_strncpy(search, SIR_MAXPID, thread_name, strlen(thread_name));
                break;
                default: break; // GCOVR_EXCL_LINE
            }

            bool found = NULL != strstr(buf, search);
            _sir_eqland(pass, found);

            if (found)
                TEST_MSG(SIR_GREEN("line %zu: found '%s'"), n, search);
            else
                TEST_MSG(SIR_RED("line %zu: did not find '%s'"), n, search);
        }

        _sir_safefclose(&f);
        TEST_MSG("deleting %s...", logfilename);
        rmfile(logfilename, cl_cfg.leave_logs);
    }

    _sir_eqland(pass, sir_cleanup());
    return PRINT_RESULT_RETURN(pass);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
leaq 0x120(%rsp), %rbx
movl $0x108, %edx            # imm = 0x108
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100000, %eax         # imm = 0x100000
movl %eax, 0x4(%rbx)
movw $0xff, (%rbx)
movl %eax, 0xc(%rbx)
movq %rbx, %rdi
callq 0x94a9
movl %eax, %r15d
leaq 0xc101(%rip), %rsi      # 0x106d2
leaq 0xc1e0(%rip), %rbx      # 0x107b8
pushq $0x1
popq %rbp
movl %ebp, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
movq %rbx, %rdi
movl $0x80, %esi
movl $0x10400, %edx          # imm = 0x10400
callq 0x9a6b
movl %eax, %r14d
testl %eax, %eax
setne %al
andb %r15b, %al
movzbl %al, %r15d
movl %r15d, %edi
xorl %esi, %esi
callq 0x3ac9
leaq 0xc1b9(%rip), %rsi      # 0x107d2
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xc1c9(%rip), %rdi      # 0x107f2
xorl %eax, %eax
callq 0x94cd
movl %eax, %r12d
leaq 0xc1dc(%rip), %rsi      # 0x10816
leaq 0xc16e(%rip), %r13      # 0x107af
movl %ebp, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3410
movq %r13, %rdi
callq 0xde59
andb %r12b, %al
andb %al, %r15b
movl $0x215, %edi            # imm = 0x215
callq 0x3f05
movzbl %r15b, %r15d
movl %r15d, %edi
xorl %esi, %esi
callq 0x3ac9
leaq 0xc1d3(%rip), %rdi      # 0x1084d
xorl %eax, %eax
callq 0x94cd
movl %eax, %r12d
leaq 0xc200(%rip), %rsi      # 0x1088b
movl %ebp, %edi
xorl %eax, %eax
callq 0x3410
leaq 0xbc2c(%rip), %rdi      # 0x102c7
callq 0xde59
andb %r12b, %al
andb %al, %r15b
movl $0x215, %edi            # imm = 0x215
callq 0x3f05
movzbl %r15b, %edi
xorl %esi, %esi
callq 0x3ac9
leaq 0xc1fe(%rip), %rdi      # 0x108c0
xorl %eax, %eax
callq 0x94cd
movl %eax, %r12d
leaq 0xc049(%rip), %rsi      # 0x1071c
movl %ebp, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
movl %r14d, %edi
callq 0x9a70
movl %eax, %r14d
leaq 0xc048(%rip), %rsi      # 0x10739
movl %ebp, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3410
leaq 0xdead(%rip), %rsi      # 0x125b1
movq %rbx, %rdi
xorl %ebx, %ebx
callq 0x34a0
movq %rax, 0x8(%rsp)
movq %rax, (%rsp)
testq %rax, %rax
je 0x483e
andb %r12b, %r14b
andb %r15b, %r14b
movl %r14d, %eax
leaq 0x20(%rsp), %r14
pushq $0x1
popq %rbp
leaq 0x10(%rsp), %r13
xorl %r15d, %r15d
movl %eax, %ebx
cmpq $0x3, %r15
je 0x480a
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100, %edx            # imm = 0x100
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x3f36
movq %rax, %r12
movl %ebp, %edi
leaq 0xc18e(%rip), %rsi      # 0x108ff
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x3410
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
cmpq $0x1, %r15
jne 0x47a3
movq %r13, %rdi
pushq $0x10
popq %rsi
leaq 0xc016(%rip), %rdx      # 0x107af
pushq $0x8
popq %rcx
callq 0xc015
jmp 0x47c4
callq 0xd7d8
movq %r13, %rdi
pushq $0x10
popq %rcx
movq %rcx, %rsi
movl %ebp, %edx
leaq 0xc15b(%rip), %r8       # 0x10915
movl %eax, %r9d
xorl %eax, %eax
callq 0x3040
testq %r12, %r12
setne %r12b
movq %r14, %rdi
movq %r13, %rsi
callq 0x35b0
testq %rax, %rax
setne %al
leaq 0xc160(%rip), %rsi      # 0x10943
leaq 0xc12e(%rip), %rcx      # 0x10918
cmovneq %rcx, %rsi
andb %r12b, %al
andb %al, %bl
movl %ebp, %edi
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3410
incq %r15
jmp 0x473b
leaq 0x8(%rsp), %rdi
callq 0xbd03
leaq 0xbf83(%rip), %rsi      # 0x1079e
leaq 0xbf96(%rip), %r14      # 0x107b8
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3410
movzbl 0x170d2(%rip), %esi     # 0x1b908
movq %r14, %rdi
callq 0x3fbf
callq 0x94ae
andb %bl, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3ac9
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq