// File: /workspace/github_c_makefile_star2_O0/aremmell[P]libsir/src/sirinternal.c
// Function: sir_syslog_write
bool _sir_syslog_write(sir_level level, const sirbuf* buf, const sir_syslog_dest* ctx) {
#if !defined(SIR_NO_SYSTEM_LOGGERS)
    if (!_sir_bittest(ctx->_state.mask, SIRSL_IS_INIT)) {
        _sir_selflog("not initialized; ignoring");
        return _sir_seterror(_SIR_E_INVALID);
    }

    if (!_sir_bittest(ctx->_state.mask, SIRSL_IS_OPEN)) {
        _sir_selflog("log not open; ignoring");
        return _sir_seterror(_SIR_E_INVALID);
    }

# if defined(SIR_OS_LOG_ENABLED)
    if (SIRL_DEBUG == level)
        os_log_debug((os_log_t)ctx->_state.logger, SIR_OS_LOG_FORMAT, buf->message);
    else if (SIRL_INFO == level || SIRL_NOTICE == level)
        os_log_info((os_log_t)ctx->_state.logger, SIR_OS_LOG_FORMAT, buf->message);
    else if (SIRL_WARN == level || SIRL_ERROR == level)
        os_log_error((os_log_t)ctx->_state.logger, SIR_OS_LOG_FORMAT, buf->message);
    else if (SIRL_CRIT == level || SIRL_ALERT == level || SIRL_EMERG == level)
        os_log_fault((os_log_t)ctx->_state.logger, SIR_OS_LOG_FORMAT, buf->message);

    return true;
# elif defined(SIR_SYSLOG_ENABLED)
    int syslog_level;
    switch (level) {
        case SIRL_DEBUG:  syslog_level = LOG_DEBUG; break;
        case SIRL_INFO:   syslog_level = LOG_INFO; break;
        case SIRL_NOTICE: syslog_level = LOG_NOTICE; break;
        case SIRL_WARN:   syslog_level = LOG_WARNING; break;
        case SIRL_ERROR:  syslog_level = LOG_ERR; break;
        case SIRL_CRIT:   syslog_level = LOG_CRIT; break;
        case SIRL_ALERT:  syslog_level = LOG_ALERT; break;
        case SIRL_EMERG:  syslog_level = LOG_EMERG; break;
        // GCOVR_EXCL_START
        default: /* this should never happen. */
            SIR_ASSERT(false);
            syslog_level = LOG_DEBUG;
        // GCOVR_EXCL_STOP
    }

    syslog(syslog_level, "%s", buf->message);
    return true;
# elif defined(SIR_EVENTLOG_ENABLED)
    const EVENT_DESCRIPTOR* edesc = NULL;
    if (SIRL_DEBUG == level)
        edesc = &SIR_EVT_DEBUG;
    else if (SIRL_INFO == level || SIRL_NOTICE == level)
        edesc = &SIR_EVT_INFO;
    else if (SIRL_WARN == level)
        edesc = &SIR_EVT_WARNING;
    else if (SIRL_ERROR == level)
        edesc = &SIR_EVT_ERROR;
    else if (SIRL_CRIT == level || SIRL_ALERT == level || SIRL_EMERG == level)
        edesc = &SIR_EVT_CRITICAL;

    SIR_ASSERT(NULL != edesc);
    if (NULL == edesc)
        return _sir_seterror(_SIR_E_INTERNAL);

#  if defined(__HAVE_STDC_SECURE_OR_EXT1__)
    size_t msg_len = strnlen_s(buf->message, SIR_MAXMESSAGE) + 1;
#  else
    size_t msg_len = strnlen(buf->message, SIR_MAXMESSAGE) + 1;
#  endif
    int wlen = MultiByteToWideChar(CP_UTF8, 0UL, buf->message, (int)msg_len, NULL, 0);
    if (wlen <= 0)
        return _sir_handlewin32err(GetLastError());

    DWORD write = 1UL;
    wchar_t* wmsg = calloc(wlen, sizeof(wchar_t));
    if (NULL != wmsg) {
        int conv = MultiByteToWideChar(CP_UTF8, 0UL, buf->message, (int)msg_len, wmsg, wlen);
        if (conv > 0) {
            EVENT_DATA_DESCRIPTOR eddesc = {0};
            EventDataDescCreate(&eddesc, wmsg, (ULONG)(wlen * sizeof(wchar_t)));

            write = EventWrite((REGHANDLE)ctx->_state.logger, edesc, 1UL, &eddesc);
            if (ERROR_SUCCESS != write) {
                _sir_selflog("failed to write eventlog! error: %lu", write);
                (void)_sir_handlewin32err(write);
            }
        }
        _sir_safefree(&wmsg);
    }

    return ERROR_SUCCESS == write;
# else
    SIR_UNUSED(level);
    SIR_UNUSED(buf);
    SIR_UNUSED(ctx);
    return false;
# endif
#else
    SIR_UNUSED(level);
    SIR_UNUSED(buf);
    SIR_UNUSED(ctx);
    return false;
#endif
}

// Assembly:
subq $0x28, %rsp
movw %di, %ax
movw %ax, 0x24(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edi
movl $0x40, %esi
callq 0xbf30
testb $0x1, %al
jne 0xc532
leaq 0x4fff(%rip), %rdi      # 0x11502
movb $0x0, %al
callq 0x9730
movl $0x800c0000, %edi       # imm = 0x800C0000
leaq 0x5078(%rip), %rsi      # 0x1158e
leaq 0x4b79(%rip), %rdx      # 0x11096
movl $0x3c5, %ecx            # imm = 0x3C5
callq 0x3940
andb $0x1, %al
movb %al, 0x27(%rsp)
jmp 0xc65d
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edi
movl $0x1, %esi
callq 0xbf30
testb $0x1, %al
jne 0xc57e
leaq 0x5051(%rip), %rdi      # 0x115a0
movb $0x0, %al
callq 0x9730
movl $0x800c0000, %edi       # imm = 0x800C0000
leaq 0x502c(%rip), %rsi      # 0x1158e
leaq 0x4b2d(%rip), %rdx      # 0x11096
movl $0x3ca, %ecx            # imm = 0x3CA
callq 0x3940
andb $0x1, %al
movb %al, 0x27(%rsp)
jmp 0xc65d
movzwl 0x24(%rsp), %eax
movl %eax, 0x8(%rsp)
subl $0x1, %eax
je 0xc62b
jmp 0xc592
movl 0x8(%rsp), %eax
subl $0x2, %eax
je 0xc621
jmp 0xc5a1
movl 0x8(%rsp), %eax
subl $0x4, %eax
je 0xc617
jmp 0xc5ac
movl 0x8(%rsp), %eax
subl $0x8, %eax
je 0xc60d
jmp 0xc5b7
movl 0x8(%rsp), %eax
subl $0x10, %eax
je 0xc603
jmp 0xc5c2
movl 0x8(%rsp), %eax
subl $0x20, %eax
je 0xc5f9
jmp 0xc5cd
movl 0x8(%rsp), %eax
subl $0x40, %eax
je 0xc5ef
jmp 0xc5d8
movl 0x8(%rsp), %eax
subl $0x80, %eax
jne 0xc635
jmp 0xc5e5
movl $0x7, 0xc(%rsp)
jmp 0xc63d
movl $0x6, 0xc(%rsp)
jmp 0xc63d
movl $0x5, 0xc(%rsp)
jmp 0xc63d
movl $0x4, 0xc(%rsp)
jmp 0xc63d
movl $0x3, 0xc(%rsp)
jmp 0xc63d
movl $0x2, 0xc(%rsp)
jmp 0xc63d
movl $0x1, 0xc(%rsp)
jmp 0xc63d
movl $0x0, 0xc(%rsp)
jmp 0xc63d
movl $0x7, 0xc(%rsp)
movl 0xc(%rsp), %edi
movq 0x18(%rsp), %rdx
addq $0x70, %rdx
leaq 0x3f34(%rip), %rsi      # 0x10585
movb $0x0, %al
callq 0x2330
movb $0x1, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
addq $0x28, %rsp
retq
nopl (%rax,%rax)