// File: /workspace/github_c_makefile_star2_O1/aremmell[P]libsir/src/sirinternal.c
// Function: sir_logv
bool _sir_logv(sir_level level, PRINTF_FORMAT const char* format, va_list args) {
    if (!_sir_sanity() || !_sir_validlevel(level) || !_sir_validstr(format))
        return false;

    (void)_sir_seterror(_SIR_E_NOERROR);

    _SIR_LOCK_SECTION(sirconfig, _cfg, SIRMI_CONFIG, false);

    sirbuf buf = {0};

    /* from time to time, update the host name in the config, just in case. */
    time_t now_sec = -1;
    if (-1 != time(&now_sec) &&
        (now_sec - _cfg->state.last_hname_chk) > SIR_HNAME_CHK_INTERVAL) {
        _sir_selflog("updating hostname...");
        if (!_sir_gethostname(_cfg->state.hostname)) {
            _sir_selflog("error: failed to get hostname!");
        } else {
            _cfg->state.last_hname_chk = now_sec;
            _sir_selflog("hostname: '%s'", _cfg->state.hostname);
        }
    }

    /* format timestamp (h/m/s only if the integer time has changed). */
    long now_msec = 0L;
    bool gettime = _sir_clock_gettime(SIR_WALLCLOCK, &now_sec, &now_msec);
    SIR_ASSERT_UNUSED(gettime, gettime);

    /* milliseconds. */
    _sir_snprintf_trunc(buf.msec, SIR_MAXMSEC, SIR_MSECFORMAT, now_msec);

    /* hours/minutes/seconds. */
    if (now_sec > _sir_last_timestamp || !*_cfg->state.timestamp) {
        _sir_last_timestamp = now_sec;
        bool fmt = _sir_formattime(now_sec, _cfg->state.timestamp, SIR_TIMEFORMAT);
        SIR_ASSERT_UNUSED(fmt, fmt);
    }

    /* check elapsed time since updating thread identifier/name. */
    sir_time thrd_chk;
    double msec_since_thrd_chk = _sir_msec_since(&_sir_last_thrd_chk, &thrd_chk);

    /* update the thread identifier/name if enough time has elapsed. */
    if (msec_since_thrd_chk > SIR_THRD_CHK_INTERVAL) {
        _sir_last_thrd_chk = thrd_chk;

        pid_t tid         = _sir_gettid();
        bool resolved_tid = false;

        /* prefer thread names. */
        resolved_tid = _sir_getthreadname(_sir_tid);

        /* if tid is identical to pid... */
        if (!resolved_tid && tid == _cfg->state.pid) {
            /* don't use anything to identify the thread. */
            _sir_resetstr(_sir_tid);
            resolved_tid = true;
        }

        /* fall back on tid. */
        if (!resolved_tid)
            _sir_snprintf_trunc(_sir_tid, SIR_MAXPID, SIR_TIDFORMAT,
                PID_CAST tid);
    }

    sirconfig cfg;
    (void)memcpy(&cfg, _cfg, sizeof(sirconfig));
    _SIR_UNLOCK_SECTION(SIRMI_CONFIG);

    buf.timestamp = cfg.state.timestamp;
    buf.hostname  = cfg.state.hostname;
    buf.pid       = cfg.state.pidbuf;
    buf.name      = cfg.si.name;

#if !defined(SIR_NO_TEXT_STYLING)
    const char* style_str = _sir_gettextstyle(level);

    SIR_ASSERT(NULL != style_str);
    if (NULL != style_str)
        (void)_sir_strncpy(buf.style, SIR_MAXSTYLE, style_str,
            strnlen(style_str, SIR_MAXSTYLE));
#endif

    buf.level = _sir_formattedlevelstr(level);

    if (_sir_validstrnofail(_sir_tid))
        (void)_sir_strncpy(buf.tid, SIR_MAXPID, _sir_tid,
            strnlen(_sir_tid, SIR_MAXPID));

    (void)vsnprintf(buf.message, SIR_MAXMESSAGE, format, args);

    if (!_sir_validstrnofail(buf.message))
        return _sir_seterror(_SIR_E_INTERNAL);

    bool match             = false;
    bool exit_early        = false;
    bool update_last_props = true;
    uint64_t hash          = 0ULL;

    if (cfg.state.last.level == level &&
        cfg.state.last.prefix[0] == buf.message[0]  &&
        cfg.state.last.prefix[1] == buf.message[1]) {
        hash  = FNV64_1a(buf.message);
        match = cfg.state.last.hash == hash;
    }

    if (match) {
        cfg.state.last.counter++;

        if (cfg.state.last.counter >= cfg.state.last.threshold - 2) {
            size_t old_threshold = cfg.state.last.threshold;

            update_last_props = false;
            cfg.state.last.threshold *= SIR_SQUELCH_BACKOFF_FACTOR;
            cfg.state.last.squelch = true;

            _sir_selflog("hit squelch threshold of %zu; setting new threshold"
                         " to %zu (factor: %d)", old_threshold,
                         cfg.state.last.threshold, SIR_SQUELCH_BACKOFF_FACTOR);

            (void)snprintf(buf.message, SIR_MAXMESSAGE, SIR_SQUELCH_MSG_FORMAT, old_threshold);
        } else if (cfg.state.last.squelch) {
            exit_early = true;
        }
    } else {
        cfg.state.last.squelch   = false;
        cfg.state.last.counter   = 0;
        cfg.state.last.threshold = SIR_SQUELCH_THRESHOLD;
        /* _sir_selflog("message '%s' does not match last; resetting", buf.message); */
    }

    _cfg = _sir_locksection(SIRMI_CONFIG);
    if (!_cfg)
        return _sir_seterror(_SIR_E_INTERNAL);

    _cfg->state.last.squelch = cfg.state.last.squelch;

    if (update_last_props) {
        _cfg->state.last.level     = level;
        _cfg->state.last.hash      = hash;
        _cfg->state.last.prefix[0] = buf.message[0];
        _cfg->state.last.prefix[1] = buf.message[1];
    }

    _cfg->state.last.counter   = cfg.state.last.counter;
    _cfg->state.last.threshold = cfg.state.last.threshold;

    _SIR_UNLOCK_SECTION(SIRMI_CONFIG);

    if (exit_early)
        return false;

    bool dispatched = _sir_dispatch(&cfg.si, level, &buf);
    return update_last_props ? dispatched : false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2428, %rsp           # imm = 0x2428
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebp
movq 0x7b47(%rip), %rax      # 0xe4e0
cmpq $0x60906090, %rax       # imm = 0x60906090
je 0x69c6
leaq 0x3236(%rip), %rsi      # 0x9bde
leaq 0x3207(%rip), %rdx      # 0x9bb6
movl $0x80020000, %edi       # imm = 0x80020000
movl $0x11a, %ecx            # imm = 0x11A
callq 0x31c0
testb %al, %al
je 0x6bd5
movzwl %bp, %ebx
leaq 0x3276(%rip), %rsi      # 0x9c46
leaq 0x31df(%rip), %rdx      # 0x9bb6
movl %ebx, %edi
movl $0x22c, %ecx            # imm = 0x22C
callq 0x56f7
testb %al, %al
je 0x6bd5
testq %r15, %r15
je 0x6b9e
cmpb $0x0, (%r15)
je 0x6b9e
leaq 0x3241(%rip), %rsi      # 0x9c46
leaq 0x31aa(%rip), %rdx      # 0x9bb6
movl $0x80010000, %edi       # imm = 0x80010000
movl $0x22f, %ecx            # imm = 0x22F
callq 0x31c0
leaq 0x7ac6(%rip), %rdi      # 0xe4e8
callq 0x799c
movl %eax, %r13d
leaq 0x7adf(%rip), %rax      # 0xe510
xorl %ecx, %ecx
testb %r13b, %r13b
cmovneq %rax, %rcx
je 0x6bb8
movq %rcx, 0x18(%rsp)
leaq 0x2c8(%rsp), %rdi
movl $0x2160, %edx           # imm = 0x2160
xorl %esi, %esi
callq 0x21b0
movq %rsp, %rdi
movq $-0x1, (%rdi)
callq 0x22b0
cmpq $-0x1, %rax
je 0x6abd
xorl %r12d, %r12d
testb %r13b, %r13b
leaq 0x7a95(%rip), %rax      # 0xe510
cmovneq %rax, %r12
movq (%rsp), %rax
subq 0x208(%r12), %rax
cmpq $0x3d, %rax
jl 0x6abd
movl $0x108, %eax            # imm = 0x108
leaq 0x7a73(%rip), %rcx      # 0xe510
leaq (%rcx,%rax), %rdi
testb %r13b, %r13b
cmoveq %rax, %rdi
callq 0x6fd0
testb %al, %al
je 0x6abd
movq (%rsp), %rax
movq %rax, 0x208(%r12)
leaq 0x30(%rsp), %r12
movq $0x0, (%r12)
movq %rsp, %rsi
movl $0x5, %edi
movq %r12, %rdx
callq 0x7003
movq $0x5, 0x38(%rsp)
leaq 0x300(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq (%r12), %r9
leaq 0x3155(%rip), %r8       # 0x9c50
movl $0x5, %ecx
movl $0x1, %edx
xorl %eax, %eax
callq 0x2040
testl %eax, %eax
jne 0x6b15
movq 0x38(%rsp), %rax
movq (%rsp), %r12
movq %fs:0x0, %rax
movq %rax, 0x8(%rsp)
cmpq -0x10(%rax), %r12
jg 0x6b50
xorl %ecx, %ecx
testb %r13b, %r13b
leaq 0x79d1(%rip), %rdx      # 0xe510
cmovneq %rdx, %rcx
cmpb $0x0, 0x224(%rcx)
jne 0x6c0c
leaq -0x10(%rax), %rax
movq %r12, (%rax)
leaq 0x20(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x38(%rsp), %rsi
callq 0x20b0
testq %rax, %rax
je 0x6bed
movl $0x224, %ecx            # imm = 0x224
leaq 0x7993(%rip), %rdx      # 0xe510
leaq (%rdx,%rcx), %rdi
testb %r13b, %r13b
cmoveq %rcx, %rdi
leaq 0x30c8(%rip), %rdx      # 0x9c57
movl $0x40, %esi
movq %rax, %rcx
callq 0x2320
jmp 0x6c0c
leaq 0x30a1(%rip), %rsi      # 0x9c46
leaq 0x300a(%rip), %rdx      # 0x9bb6
movl $0x800a0000, %edi       # imm = 0x800A0000
movl $0x22c, %ecx            # imm = 0x22C
jmp 0x6bd0
leaq 0x3087(%rip), %rsi      # 0x9c46
leaq 0x2ff0(%rip), %rdx      # 0x9bb6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x231, %ecx            # imm = 0x231
callq 0x31c0
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x2428, %rsp           # imm = 0x2428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2080
movl (%rax), %edi
leaq 0x2dcd(%rip), %rsi      # 0x99c8
leaq 0x2dd5(%rip), %rdx      # 0x99d7
movl $0x196, %ecx            # imm = 0x196
callq 0x32bc
movq 0x8(%rsp), %rax
leaq -0x20(%rax), %r12
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x7092
ucomisd 0x2f6b(%rip), %xmm0     # 0x9b98
jbe 0x6cbf
movupd 0x20(%rsp), %xmm0
movupd %xmm0, (%r12)
callq 0x20c0
movl %eax, %r12d
movq 0x8(%rsp), %rax
leaq -0x30(%rax), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7140
testb %al, %al
jne 0x6cbf
xorl %ecx, %ecx
testb %r13b, %r13b
leaq 0x78a3(%rip), %rdx      # 0xe510
cmovneq %rdx, %rcx
cmpl 0x220(%rcx), %r12d
jne 0x6c84
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
jmp 0x6cbf
testb %al, %al
jne 0x6cbf
movq $0x10, 0x38(%rsp)
movq 0x38(%rsp), %rsi
leaq 0x2f31(%rip), %r8       # 0x9bce
movl $0x10, %ecx
movq 0x10(%rsp), %rdi
movl $0x1, %edx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x2040
testl %eax, %eax
jne 0x6cbf
movq 0x38(%rsp), %rax
leaq 0x38(%rsp), %rdi
movl $0x290, %edx            # imm = 0x290
movq 0x18(%rsp), %rsi
callq 0x2280
leaq 0x780e(%rip), %rdi      # 0xe4e8
callq 0x7a3a
leaq 0x140(%rsp), %rax
leaq 0x25c(%rsp), %rcx
movq %rcx, 0x2f8(%rsp)
movq %rax, 0x308(%rsp)
leaq 0x248(%rsp), %rax
movq %rax, 0x310(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, 0x320(%rsp)
movl %ebx, %edi
callq 0x8478
testq %rax, %rax
je 0x6d53
movq %rax, %r12
movl $0x2b, %esi
movq %rax, %rdi
callq 0x21c0
leaq 0x2c8(%rsp), %rdi
movl $0x2b, %esi
movq %r12, %rdx
movq %rax, %rcx
callq 0x57c8
movl %ebx, %edi
callq 0x7191
movq %rax, 0x318(%rsp)
movq 0x8(%rsp), %rax
cmpb $0x0, -0x30(%rax)
je 0x6d9f
leaq -0x30(%rax), %r12
leaq 0x328(%rsp), %r13
movl $0x10, %esi
movq %r12, %rdi
callq 0x21c0
movl $0x10, %esi
movq %r13, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x57c8
leaq 0x338(%rsp), %r12
movl $0x1000, %esi           # imm = 0x1000
movl $0x20f0, %ecx           # imm = 0x20F0
movq %r12, %rdi
movl $0x1, %edx
movq %r15, %r8
movq %r14, %r9
callq 0x2310
movb (%r12), %al
testb %al, %al
je 0x6e33
xorl %r14d, %r14d
movl $0x0, %ecx
cmpw %bp, 0x2b2(%rsp)
jne 0x6e55
cmpb %al, 0x2b0(%rsp)
jne 0x6e55
movb 0x2b1(%rsp), %cl
cmpb 0x339(%rsp), %cl
jne 0x6e50
movabsq $-0x340d631b7bdddcdb, %r14 # imm = 0xCBF29CE484222325
leaq 0x339(%rsp), %rcx
movabsq $0x100000001b3, %rdx    # imm = 0x100000001B3
movzbl %al, %eax
xorq %rax, %r14
imulq %rdx, %r14
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x6e13
cmpq %r14, 0x2a8(%rsp)
sete %cl
jmp 0x6e55
leaq 0x2e0c(%rip), %rsi      # 0x9c46
leaq 0x2d75(%rip), %rdx      # 0x9bb6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x287, %ecx            # imm = 0x287
jmp 0x6fc3
xorl %ecx, %ecx
xorl %r14d, %r14d
testb %cl, %cl
je 0x6e8a
movq 0x2b8(%rsp), %rax
movq 0x2c0(%rsp), %r9
incq %rax
movq %rax, 0x2b8(%rsp)
leaq -0x2(%r9), %rcx
cmpq %rcx, %rax
jae 0x6eb2
movb 0x2a0(%rsp), %r13b
movb $0x1, %r15b
jmp 0x6eec
movb $0x0, 0x2a0(%rsp)
movq $0x0, 0x2b8(%rsp)
movq $0x5, 0x2c0(%rsp)
movb $0x1, %r15b
xorl %r13d, %r13d
jmp 0x6eec
leaq (%r9,%r9), %rax
movq %rax, 0x2c0(%rsp)
movb $0x1, 0x2a0(%rsp)
leaq 0x2d93(%rip), %r8       # 0x9c60
xorl %r13d, %r13d
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r12, %rdi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2040
xorl %r15d, %r15d
leaq 0x75f5(%rip), %rdi      # 0xe4e8
callq 0x799c
testb %al, %al
je 0x6fab
movb 0x2a0(%rsp), %cl
movb %cl, 0x786b(%rip)       # 0xe778
testb %r15b, %r15b
je 0x6f49
xorl %ecx, %ecx
testb %al, %al
leaq 0x75f3(%rip), %rdx      # 0xe510
cmovneq %rdx, %rcx
movw %bp, 0x27a(%rcx)
movq %r14, 0x270(%rcx)
movb 0x338(%rsp), %dl
movb %dl, 0x278(%rcx)
movb 0x339(%rsp), %dl
movb %dl, 0x279(%rcx)
xorl %r14d, %r14d
testb %al, %al
leaq 0x75bb(%rip), %rcx      # 0xe510
cmoveq %r14, %rcx
movq 0x2b8(%rsp), %rax
movq %rax, 0x280(%rcx)
movq 0x2c0(%rsp), %rax
movq %rax, 0x288(%rcx)
leaq 0x756a(%rip), %rdi      # 0xe4e8
callq 0x7a3a
testb %r13b, %r13b
jne 0x6bd8
leaq 0x38(%rsp), %rdi
leaq 0x2c8(%rsp), %rdx
movl %ebx, %esi
callq 0x7210
andb %al, %r15b
movl %r15d, %r14d
jmp 0x6bd8
leaq 0x2c94(%rip), %rsi      # 0x9c46
leaq 0x2bfd(%rip), %rdx      # 0x9bb6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x2b0, %ecx            # imm = 0x2B0
callq 0x31c0
movl %eax, %r14d
jmp 0x6bd8