// File: /workspace/github_c_makefile_star2_O3/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 $0x2418, %rsp           # imm = 0x2418
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebp
movq 0x7cc9(%rip), %rax      # 0xe4e0
cmpq $0x60906090, %rax       # imm = 0x60906090
je 0x6844
leaq 0x33a8(%rip), %rsi      # 0x9bce
leaq 0x3379(%rip), %rdx      # 0x9ba6
movl $0x80020000, %edi       # imm = 0x80020000
movl $0x11a, %ecx            # imm = 0x11A
callq 0x31c0
testb %al, %al
je 0x69f8
movzwl %bp, %ebx
leaq 0x33e8(%rip), %rsi      # 0x9c36
leaq 0x3351(%rip), %rdx      # 0x9ba6
movl %ebx, %edi
movl $0x22c, %ecx            # imm = 0x22C
callq 0x5630
testb %al, %al
je 0x69f8
testq %r15, %r15
je 0x69c1
cmpb $0x0, (%r15)
je 0x69c1
leaq 0x33b3(%rip), %rsi      # 0x9c36
leaq 0x331c(%rip), %rdx      # 0x9ba6
movl $0x80010000, %edi       # imm = 0x80010000
movl $0x22f, %ecx            # imm = 0x22F
callq 0x31c0
leaq 0x7c48(%rip), %rdi      # 0xe4e8
callq 0x7790
testb %al, %al
je 0x69db
leaq 0x2b8(%rsp), %rdi
movl $0x2160, %edx           # imm = 0x2160
xorl %esi, %esi
callq 0x21b0
movq %rsp, %rdi
movq $-0x1, (%rdi)
callq 0x22b0
cmpq $-0x1, %rax
je 0x6902
movq (%rsp), %rax
subq 0x7e37(%rip), %rax      # 0xe718
cmpq $0x3d, %rax
jl 0x6902
leaq 0x7d2a(%rip), %rdi      # 0xe618
callq 0x6db7
testb %al, %al
je 0x6902
movq (%rsp), %rax
movq %rax, 0x7e16(%rip)      # 0xe718
leaq 0x20(%rsp), %r12
movq $0x0, (%r12)
movq %rsp, %rsi
movl $0x5, %edi
movq %r12, %rdx
callq 0x6dea
movq $0x5, 0x28(%rsp)
leaq 0x2f0(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq (%r12), %r9
leaq 0x3300(%rip), %r8       # 0x9c40
movl $0x5, %ecx
movl $0x1, %edx
xorl %eax, %eax
callq 0x2040
testl %eax, %eax
jne 0x695a
movq 0x28(%rsp), %rax
movq (%rsp), %r13
movq %fs:0x0, %rax
movq %rax, %r12
cmpq -0x10(%rax), %r13
jg 0x6983
cmpb $0x0, 0x7db7(%rip)      # 0xe734
jne 0x6a2d
leaq -0x10(%rax), %rax
movq %r13, (%rax)
leaq 0x10(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x28(%rsp), %rsi
callq 0x20b0
testq %rax, %rax
je 0x6a0e
leaq 0x7d89(%rip), %rdi      # 0xe734
leaq 0x3295(%rip), %rdx      # 0x9c47
movl $0x40, %esi
movq %rax, %rcx
callq 0x2320
jmp 0x6a2d
leaq 0x326e(%rip), %rsi      # 0x9c36
leaq 0x31d7(%rip), %rdx      # 0x9ba6
movl $0x800a0000, %edi       # imm = 0x800A0000
movl $0x22c, %ecx            # imm = 0x22C
jmp 0x69f3
leaq 0x3254(%rip), %rsi      # 0x9c36
leaq 0x31bd(%rip), %rdx      # 0x9ba6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x231, %ecx            # imm = 0x231
callq 0x31c0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x2418, %rsp           # imm = 0x2418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2080
movl (%rax), %edi
leaq 0x2fac(%rip), %rsi      # 0x99c8
leaq 0x2fb4(%rip), %rdx      # 0x99d7
movl $0x196, %ecx            # imm = 0x196
callq 0x32bc
movq %r12, 0x8(%rsp)
leaq -0x20(%r12), %r13
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0x6e79
ucomisd 0x3139(%rip), %xmm0     # 0x9b88
jbe 0x6ac2
movupd 0x10(%rsp), %xmm0
movupd %xmm0, (%r13)
callq 0x20c0
movl %eax, %r12d
movq 0x8(%rsp), %rax
leaq -0x30(%rax), %r13
movq %r13, %rdi
callq 0x6f36
testb %al, %al
jne 0x6ac2
cmpl 0x7cac(%rip), %r12d     # 0xe730
jne 0x6a8d
movb $0x0, (%r13)
jmp 0x6ac2
movq $0x10, 0x28(%rsp)
movq 0x28(%rsp), %rsi
leaq 0x311c(%rip), %r8       # 0x9bbe
movl $0x10, %ecx
movq %r13, %rdi
movl $0x1, %edx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x2040
testl %eax, %eax
jne 0x6ac2
movq 0x28(%rsp), %rax
leaq 0x7a47(%rip), %rsi      # 0xe510
leaq 0x28(%rsp), %rdi
movl $0x290, %edx            # imm = 0x290
callq 0x2280
leaq 0x7a09(%rip), %rdi      # 0xe4e8
callq 0x782e
leaq 0x130(%rsp), %rax
leaq 0x24c(%rsp), %rcx
movq %rcx, 0x2e8(%rsp)
movq %rax, 0x2f8(%rsp)
leaq 0x238(%rsp), %rax
movq %rax, 0x300(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x310(%rsp)
movl %ebx, %edi
callq 0x8230
testq %rax, %rax
je 0x6b58
movq %rax, %r13
movl $0x2b, %esi
movq %rax, %rdi
callq 0x21c0
leaq 0x2b8(%rsp), %rdi
movl $0x2b, %esi
movq %r13, %rdx
movq %rax, %rcx
callq 0x56fc
movl %ebx, %edi
callq 0x6f87
movq %rax, 0x308(%rsp)
movq 0x8(%rsp), %rax
cmpb $0x0, -0x30(%rax)
je 0x6ba4
leaq -0x30(%rax), %r12
leaq 0x318(%rsp), %r13
movl $0x10, %esi
movq %r12, %rdi
callq 0x21c0
movl $0x10, %esi
movq %r13, %rdi
movq %r12, %rdx
movq %rax, %rcx
callq 0x56fc
leaq 0x328(%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 0x6c72
xorl %r14d, %r14d
cmpw %bp, 0x2a2(%rsp)
jne 0x6c92
cmpb %al, 0x2a0(%rsp)
jne 0x6c92
movb 0x2a1(%rsp), %cl
cmpb 0x329(%rsp), %cl
jne 0x6c8f
movabsq $-0x340d631b7bdddcdb, %r14 # imm = 0xCBF29CE484222325
leaq 0x329(%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 0x6c23
cmpq %r14, 0x298(%rsp)
jne 0x6c92
movq 0x2a8(%rsp), %rax
movq 0x2b0(%rsp), %r9
incq %rax
movq %rax, 0x2a8(%rsp)
leaq -0x2(%r9), %rcx
cmpq %rcx, %rax
jae 0x6d38
movb 0x290(%rsp), %r15b
jmp 0x6cb5
leaq 0x2fbd(%rip), %rsi      # 0x9c36
leaq 0x2f26(%rip), %rdx      # 0x9ba6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x287, %ecx            # imm = 0x287
jmp 0x6dab
xorl %r14d, %r14d
movb $0x0, 0x290(%rsp)
movq $0x0, 0x2a8(%rsp)
movq $0x5, 0x2b0(%rsp)
xorl %r15d, %r15d
leaq 0x782c(%rip), %rdi      # 0xe4e8
callq 0x7790
testb %al, %al
je 0x6d93
movb 0x290(%rsp), %al
movb %al, 0x7aa2(%rip)       # 0xe778
movw %bp, 0x7aad(%rip)       # 0xe78a
movq %r14, 0x7a9c(%rip)      # 0xe780
movzwl 0x328(%rsp), %eax
movw %ax, 0x7a95(%rip)       # 0xe788
movb $0x1, %bpl
movupd 0x2a8(%rsp), %xmm0
movupd %xmm0, 0x7a89(%rip)     # 0xe790
leaq 0x77da(%rip), %rdi      # 0xe4e8
callq 0x782e
testb %r15b, %r15b
jne 0x69f8
leaq 0x28(%rsp), %rdi
leaq 0x2b8(%rsp), %rdx
movl %ebx, %esi
callq 0x7006
andb %al, %bpl
jmp 0x69fa
leaq (%r9,%r9), %rax
movq %rax, 0x2b0(%rsp)
movb $0x1, 0x290(%rsp)
leaq 0x2efd(%rip), %r8       # 0x9c50
movl $0x1000, %esi           # imm = 0x1000
movl $0x1000, %ecx           # imm = 0x1000
movq %r12, %rdi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2040
leaq 0x7775(%rip), %rdi      # 0xe4e8
callq 0x7790
testb %al, %al
je 0x6d93
movb 0x290(%rsp), %al
movb %al, 0x79ef(%rip)       # 0xe778
xorl %r15d, %r15d
xorl %ebp, %ebp
jmp 0x6cf6
leaq 0x2e9c(%rip), %rsi      # 0x9c36
leaq 0x2e05(%rip), %rdx      # 0x9ba6
movl $0x800f0000, %edi       # imm = 0x800F0000
movl $0x2b0, %ecx            # imm = 0x2B0
callq 0x31c0
movl %eax, %ebp
jmp 0x69fa