// File: /workspace/github_c_makefile_star2_O3/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 %r15d, %r15d
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 0x9a21
movl %eax, %r14d
leaq 0xd040(%rip), %rsi      # 0x11712
leaq 0xd11f(%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 0xa035
movl %eax, %ebp
testl %eax, %eax
setne %al
andb %r14b, %al
movzbl %al, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b6d
leaq 0xd0f9(%rip), %rsi      # 0x11812
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xd106(%rip), %rdi      # 0x11832
xorl %eax, %eax
callq 0x9a45
movl %eax, %r13d
leaq 0xd119(%rip), %rsi      # 0x11856
leaq 0xd0ab(%rip), %r12      # 0x117ef
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3400
movq %r12, %rdi
callq 0xe79d
andb %r13b, %al
andb %al, %r14b
movl $0x215, %edi            # imm = 0x215
callq 0x3fdd
movzbl %r14b, %r14d
movl %r14d, %edi
xorl %esi, %esi
callq 0x3b6d
leaq 0xd10d(%rip), %rdi      # 0x1188d
xorl %eax, %eax
callq 0x9a45
movl %eax, %r12d
leaq 0xd13a(%rip), %rsi      # 0x118cb
movl $0x1, %edi
xorl %eax, %eax
callq 0x3400
leaq 0xcb23(%rip), %rdi      # 0x112c7
callq 0xe79d
andb %r12b, %al
andb %al, %r14b
movl $0x215, %edi            # imm = 0x215
callq 0x3fdd
movzbl %r14b, %edi
xorl %esi, %esi
callq 0x3b6d
leaq 0xd135(%rip), %rdi      # 0x11900
xorl %eax, %eax
callq 0x9a45
movl %eax, %r13d
leaq 0xcf80(%rip), %rsi      # 0x1175c
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movl %ebp, %edi
callq 0xa03a
movl %eax, %r12d
leaq 0xcf7d(%rip), %rsi      # 0x11779
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
leaq 0xeddf(%rip), %rsi      # 0x135f1
movq %rbx, %rdi
callq 0x3490
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x4952
movq %rax, %rbx
andb %r13b, %r12b
andb %r14b, %r12b
leaq 0x20(%rsp), %r14
leaq 0x10(%rsp), %r13
movl %r12d, %r15d
xorl %r12d, %r12d
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
xorl %esi, %esi
callq 0x31f0
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rsi
callq 0x401b
movq %rax, %rbp
movl $0x1, %edi
leaq 0xd0d0(%rip), %rsi      # 0x1193f
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x3400
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
cmpq $0x1, %r12
jne 0x48a5
movl $0x10, %esi
movl $0x8, %ecx
movq %r13, %rdi
leaq 0xcf51(%rip), %rdx      # 0x117ef
callq 0xc874
jmp 0x48cd
callq 0xe0a9
movl $0x10, %esi
movl $0x10, %ecx
movq %r13, %rdi
movl $0x1, %edx
leaq 0xd092(%rip), %r8       # 0x11955
movl %eax, %r9d
xorl %eax, %eax
callq 0x3040
testq %rbp, %rbp
setne %bpl
movq %r14, %rdi
movq %r13, %rsi
callq 0x35a0
testq %rax, %rax
setne %al
leaq 0xd097(%rip), %rsi      # 0x11983
leaq 0xd065(%rip), %rcx      # 0x11958
cmovneq %rcx, %rsi
andb %bpl, %al
andb %al, %r15b
movl $0x1, %edi
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3400
incq %r12
cmpq $0x3, %r12
jne 0x4841
leaq 0x8(%rsp), %rdi
callq 0xc5b7
leaq 0xceb1(%rip), %rsi      # 0x117de
leaq 0xcec4(%rip), %rbx      # 0x117f8
movl $0x1, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3400
movzbl 0x16fae(%rip), %esi     # 0x1b8f8
movq %rbx, %rdi
callq 0x40a2
callq 0x9a26
andb %r15b, %al
movzbl %al, %edi
xorl %esi, %esi
callq 0x3b6d
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq