// File: /workspace/github_c_makefile_star2_O2/aremmell[P]libsir/src/sirinternal.c
// Function: sir_format
const char* _sir_format(bool styling, sir_options opts, sirbuf* buf) {
    if (_sir_validptr(buf)) {
        bool first = true;

        _sir_resetstr(buf->output);

        if (styling)
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->style, SIR_MAXSTYLE);

        if (!_sir_bittest(opts, SIRO_NOTIME)) {
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->timestamp, SIR_MAXTIME);
            first = false;

#if defined(SIR_MSEC_TIMER)
            if (!_sir_bittest(opts, SIRO_NOMSEC))
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->msec, SIR_MAXMSEC);
#endif
        }

        if (!_sir_bittest(opts, SIRO_NOHOST) && _sir_validstrnofail(buf->hostname)) {
            if (!first)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, " ", 1);
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->hostname, SIR_MAXHOST);
            first = false;
        }

        if (!_sir_bittest(opts, SIRO_NOLEVEL)) {
            if (!first)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, " ", 1);
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->level, SIR_MAXLEVEL);
            first = false;
        }

        bool name = false;
        if (!_sir_bittest(opts, SIRO_NONAME) && _sir_validstrnofail(buf->name)) {
            if (!first)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, " ", 1);
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->name, SIR_MAXNAME);
            first = false;
            name  = true;
        }

        bool wantpid = !_sir_bittest(opts, SIRO_NOPID) && _sir_validstrnofail(buf->pid);
        bool wanttid = !_sir_bittest(opts, SIRO_NOTID) && _sir_validstrnofail(buf->tid);

        if (wantpid || wanttid) {
            if (name)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_PIDPREFIX, 1);
            else if (!first)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, " ", 1);

            if (wantpid)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->pid, SIR_MAXPID);

            if (wanttid) {
                if (wantpid)
                    (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_PIDSEPARATOR, 1);
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->tid, SIR_MAXPID);
            }

            if (name)
                (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_PIDSUFFIX, 1);

            first = false;
        }

        if (!first)
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, ": ", 2);

        (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, buf->message, SIR_MAXMESSAGE);

        if (styling)
            (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_ESC_RST, SIR_MAXSTYLE);

#if defined(SIR_USE_EOL_CRLF)
        (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_EOL, 2);
#else
        (void)_sir_strncat(buf->output, SIR_MAXOUTPUT, SIR_EOL, 1);
#endif

        buf->output_len = strnlen(buf->output, SIR_MAXOUTPUT);

        return buf->output;
    }

    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %r15d
movl %edi, %ebp
leaq 0x2de4(%rip), %rdx      # 0x9c82
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x30d, %ecx            # imm = 0x30D
callq 0x5923
testb %al, %al
je 0x6fe1
leaq 0x1070(%rbx), %r14
movb $0x0, 0x1070(%rbx)
testb %bpl, %bpl
je 0x6edc
pushq $0x2b
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
movq %rbx, %rdx
callq 0x547a
movb $0x1, %al
btl $0x8, %r15d
jb 0x6f16
movq 0x30(%rbx), %rdx
pushq $0x40
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
btl $0x9, %r15d
jb 0x6f14
leaq 0x38(%rbx), %rdx
pushq $0x5
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
xorl %eax, %eax
btl $0xa, %r15d
jb 0x6f5e
movq 0x40(%rbx), %rdx
testq %rdx, %rdx
je 0x6f5e
cmpb $0x0, (%rdx)
je 0x6f5e
testb %al, %al
jne 0x6f4a
leaq 0x2d5b(%rip), %rdx      # 0x9c91
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
movq 0x40(%rbx), %rdx
movl $0x10e7, %esi           # imm = 0x10E7
movl $0x100, %ecx            # imm = 0x100
movq %r14, %rdi
callq 0x547a
xorl %eax, %eax
btl $0xb, %r15d
jb 0x6f96
testb %al, %al
jne 0x6f80
leaq 0x2d21(%rip), %rdx      # 0x9c91
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
movq 0x50(%rbx), %rdx
pushq $0x7
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
xorl %eax, %eax
btl $0xc, %r15d
jb 0x6fe9
movq 0x58(%rbx), %rdx
testq %rdx, %rdx
je 0x6fe9
cmpb $0x0, (%rdx)
je 0x6fe9
testb %al, %al
jne 0x6fca
leaq 0x2cdb(%rip), %rdx      # 0x9c91
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
movq 0x58(%rbx), %rdx
pushq $0x20
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
movb $0x1, %r12b
xorl %eax, %eax
jmp 0x6fec
xorl %r14d, %r14d
jmp 0x713d
xorl %r12d, %r12d
btl $0xd, %r15d
jb 0x7005
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
je 0x7005
cmpb $0x0, (%rcx)
setne %r13b
jmp 0x7008
xorl %r13d, %r13d
btl $0xe, %r15d
jb 0x7019
cmpb $0x0, 0x60(%rbx)
setne %r15b
jmp 0x701c
xorl %r15d, %r15d
movl %r13d, %ecx
orb %r15b, %cl
testb $0x1, %cl
je 0x7035
testb %r12b, %r12b
je 0x7042
leaq 0x2c5b(%rip), %rdx      # 0x9c8e
jmp 0x704d
testb %al, %al
je 0x70c9
jmp 0x70e0
testb %al, %al
jne 0x705d
leaq 0x2c44(%rip), %rdx      # 0x9c91
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
testb %r13b, %r13b
je 0x7094
movq 0x48(%rbx), %rdx
pushq $0x10
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
testb %r15b, %r15b
je 0x70ad
leaq 0x22d3(%rip), %rdx      # 0x9355
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
jmp 0x7099
testb %r15b, %r15b
je 0x70ad
leaq 0x60(%rbx), %rdx
pushq $0x10
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
testb %r12b, %r12b
je 0x70c9
leaq 0x27db(%rip), %rdx      # 0x9894
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
leaq 0x2bc0(%rip), %rdx      # 0x9c90
pushq $0x2
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
leaq 0x70(%rbx), %rdx
movl $0x10e7, %esi           # imm = 0x10E7
movl $0x1000, %ecx           # imm = 0x1000
movq %r14, %rdi
callq 0x547a
testb %bpl, %bpl
je 0x7112
leaq 0x2b91(%rip), %rdx      # 0x9c93
pushq $0x2b
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
leaq 0x2791(%rip), %rdx      # 0x98aa
pushq $0x1
popq %rcx
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x547a
movl $0x10e7, %esi           # imm = 0x10E7
movq %r14, %rdi
callq 0x21c0
movq %rax, 0x2158(%rbx)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq