// File: /workspace/github_c_makefile_star2_O1/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
xorl %r13d, %r13d
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)
movw $0x0, 0x8(%rbx)
movq %rbx, %rdi
callq 0x9a31
movl %eax, %r14d
leaq 0xd076(%rip), %rsi      # 0x11712
leaq 0xd155(%rip), %rbx      # 0x117f8
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movq %rbx, %rdi
movl $0x80, %esi
movl $0x10400, %edx          # imm = 0x10400
callq 0xa045
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r14b, %al
movzbl %al, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b04
leaq 0xd12f(%rip), %rsi      # 0x11812
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xd13c(%rip), %rdi      # 0x11832
xorl %eax, %eax
callq 0x9a55
movl %eax, %r15d
leaq 0xd14f(%rip), %rsi      # 0x11856
leaq 0xd0e1(%rip), %r12      # 0x117ef
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xe9b8
andb %r15b, %al
andb %al, %r14b
movl $0x215, %edi            # imm = 0x215
callq 0x3f87
movzbl %r14b, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b04
leaq 0xd143(%rip), %rdi      # 0x1188d
xorl %eax, %eax
callq 0x9a55
movl %eax, %r15d
leaq 0xd170(%rip), %rsi      # 0x118cb
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xcb59(%rip), %rdi      # 0x112c7
callq 0xe9b8
andb %r15b, %al
andb %al, %r14b
movl $0x215, %edi            # imm = 0x215
callq 0x3f87
movzbl %r14b, %edi
xorl %esi, %esi
callq 0x3b04
leaq 0xd16b(%rip), %rdi      # 0x11900
xorl %eax, %eax
callq 0x9a55
movl %eax, %r15d
leaq 0xcfb6(%rip), %rsi      # 0x1175c
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movl %ebp, %edi
callq 0xa04a
movl %eax, %ebp
leaq 0xcfb4(%rip), %rsi      # 0x11779
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
leaq 0xee16(%rip), %rsi      # 0x135f1
movq %rbx, %rdi
callq 0x3490
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x491c
andb %r15b, %bpl
andb %r14b, %bpl
leaq 0x20(%rsp), %rbx
leaq 0x10(%rsp), %r12
leaq 0xd17b(%rip), %r14      # 0x11983
movl %ebp, %r13d
xorl %ebp, %ebp
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31f0
movq 0x8(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rsi
callq 0x3fc5
movq %rax, %r15
movl $0x1, %edi
leaq 0xd102(%rip), %rsi      # 0x1193f
movq %rbp, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3400
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
cmpq $0x1, %rbp
jne 0x4873
movl $0x10, %esi
movl $0x8, %ecx
movq %r12, %rdi
leaq 0xcf83(%rip), %rdx      # 0x117ef
callq 0xc950
jmp 0x489b
callq 0xe2c3
movl $0x10, %esi
movl $0x10, %ecx
movq %r12, %rdi
movl $0x1, %edx
leaq 0xd0c4(%rip), %r8       # 0x11955
movl %eax, %r9d
xorl %eax, %eax
callq 0x3040
testq %r15, %r15
setne %r15b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x35a0
testq %rax, %rax
setne %al
movq %r14, %rsi
leaq 0xd09b(%rip), %rcx      # 0x11958
cmovneq %rcx, %rsi
andb %al, %r13b
andb %r15b, %r13b
movl $0x1, %edi
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3400
incq %rbp
cmpq $0x3, %rbp
jne 0x480d
leaq 0x8(%rsp), %rdi
callq 0xc677
leaq 0xcee7(%rip), %rsi      # 0x117de
leaq 0xcefa(%rip), %rbx      # 0x117f8
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movzbl 0x16fe4(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x4053
callq 0x9a36
andb %r13b, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b04
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq