// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/pp.c
// Function: janet_buffer_format
void janet_buffer_format(
    JanetBuffer *b,
    const char *strfrmt,
    int32_t argstart,
    int32_t argc,
    Janet *argv) {
    size_t sfl = strlen(strfrmt);
    const char *strfrmt_end = strfrmt + sfl;
    int32_t arg = argstart;
    int32_t startlen = b->count;
    while (strfrmt < strfrmt_end) {
        if (*strfrmt != '%')
            janet_buffer_push_u8(b, (uint8_t) * strfrmt++);
        else if (*++strfrmt == '%')
            janet_buffer_push_u8(b, (uint8_t) * strfrmt++); /* %% */
        else { /* format item */
            char form[MAX_FORMAT], item[MAX_ITEM];
            char width[3], precision[3];
            int nb = 0; /* number of bytes in added item */
            if (++arg >= argc)
                janet_panic("not enough values for format");
            strfrmt = scanformat(strfrmt, form, width, precision);
            switch (*strfrmt++) {
                case 'c': {
                    nb = snprintf(item, MAX_ITEM, form, (int)
                                  janet_getinteger(argv, arg));
                    break;
                }
                case 'D':
                case 'I':
                case 'd':
                case 'i': {
                    int64_t n = janet_getinteger64(argv, arg);
                    nb = snprintf(item, MAX_ITEM, form, n);
                    break;
                }
                case 'x':
                case 'X':
                case 'o':
                case 'u': {
                    uint64_t n = janet_getuinteger64(argv, arg);
                    nb = snprintf(item, MAX_ITEM, form, n);
                    break;
                }
                case 'a':
                case 'A':
                case 'e':
                case 'E':
                case 'f':
                case 'g':
                case 'G': {
                    double d = janet_getnumber(argv, arg);
                    nb = snprintf(item, MAX_ITEM, form, d);
                    break;
                }
                case 's': {
                    JanetByteView bytes = janet_getbytes(argv, arg);
                    const uint8_t *s = bytes.bytes;
                    int32_t l = bytes.len;
                    if (form[2] == '\0')
                        janet_buffer_push_bytes(b, s, l);
                    else {
                        if (l != (int32_t) strnlen((const char *) s, l))
                            janet_panic("string contains zeros");
                        if (!strchr(form, '.') && l >= 100) {
                            janet_panic("no precision and string is too long to be formatted");
                        } else {
                            nb = snprintf(item, MAX_ITEM, form, s);
                        }
                    }
                    break;
                }
                case 'V': {
                    janet_to_string_b(b, argv[arg]);
                    break;
                }
                case 'v': {
                    janet_description_b(b, argv[arg]);
                    break;
                }
                case 't':
                    janet_buffer_push_cstring(b, typestr(argv[arg]));
                    break;
                case 'M':
                case 'm':
                case 'N':
                case 'n':
                case 'Q':
                case 'q':
                case 'P':
                case 'p': { /* janet pretty , precision = depth */
                    int depth = atoi(precision);
                    if (depth < 1) depth = JANET_RECURSION_GUARD;
                    char d = strfrmt[-1];
                    int has_color = (d == 'P') || (d == 'Q') || (d == 'M') || (d == 'N');
                    int has_oneline = (d == 'Q') || (d == 'q') || (d == 'N') || (d == 'n');
                    int has_notrunc = (d == 'M') || (d == 'm') || (d == 'N') || (d == 'n');
                    int flags = 0;
                    flags |= has_color ? JANET_PRETTY_COLOR : 0;
                    flags |= has_oneline ? JANET_PRETTY_ONELINE : 0;
                    flags |= has_notrunc ? JANET_PRETTY_NOTRUNC : 0;
                    janet_pretty_(b, depth, flags, argv[arg], startlen);
                    break;
                }
                case 'j': {
                    int depth = atoi(precision);
                    if (depth < 1)
                        depth = JANET_RECURSION_GUARD;
                    janet_jdn_(b, depth, argv[arg], startlen);
                    break;
                }
                default: {
                    /* also treat cases 'nLlh' */
                    janet_panicf("invalid conversion '%s' to 'format'",
                                 form);
                }
            }
            if (nb >= MAX_ITEM)
                janet_panic("format buffer overflow");
            if (nb > 0)
                janet_buffer_push_bytes(b, (uint8_t *) item, nb);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r8, -0x30(%rbp)
movl %ecx, -0x3c(%rbp)
movl %edx, %r15d
movq %rsi, %rbx
movq %rdi, %r12
movq %rsi, %rdi
callq 0x12310
testq %rax, %rax
jle 0x3fada
movq %rax, %r13
addq %rbx, %r13
movl 0x10(%r12), %eax
movl %eax, -0x38(%rbp)
movb (%rbx), %al
leaq 0x1(%rbx), %r14
cmpb $0x25, %al
jne 0x3f814
cmpb $0x25, (%r14)
jne 0x3f824
addq $0x2, %rbx
movq %r12, %rdi
movl $0x25, %esi
callq 0x17947
movq %rbx, %r14
jmp 0x3f981
movzbl %al, %esi
movq %r12, %rdi
callq 0x17947
jmp 0x3f981
incl %r15d
cmpl -0x3c(%rbp), %r15d
jge 0x3faec
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
leaq -0x3f(%rbp), %rdx
leaq -0x33(%rbp), %rcx
callq 0x3f489
movq %rax, %r14
movzbl (%rax), %ebx
leal -0x41(%rbx), %eax
cmpl $0x37, %eax
ja 0x3fb04
leaq 0x28b8a(%rip), %rcx     # 0x683e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x33(%rbp), %rdi
callq 0x12a20
testl %eax, %eax
movl $0x400, %ecx            # imm = 0x400
cmovlel %ecx, %eax
leal -0x4d(%rbx), %esi
cmpl $0x4, %esi
ja 0x3f891
movl $0x1, %ecx
movl $0x19, %edx
btl %esi, %edx
jb 0x3f899
xorl %ecx, %ecx
cmpl $0x4e, %ebx
sete %cl
leal -0x4e(%rbx), %edi
cmpl $0x23, %edi
ja 0x3f8b6
movl $0x2, %edx
movabsq $0x800000009, %r8       # imm = 0x800000009
btq %rdi, %r8
jb 0x3f8c0
xorl %edx, %edx
cmpl $0x6e, %ebx
sete %dl
addl %edx, %edx
cmpl $0x20, %esi
ja 0x3f8da
movl $0x4, %edi
movabsq $0x100000003, %r8       # imm = 0x100000003
btq %rsi, %r8
jb 0x3f8e6
xorl %edi, %edi
cmpl $0x6e, %ebx
sete %dil
shll $0x2, %edi
orl %ecx, %edx
orl %edi, %edx
movslq %r15d, %rcx
movq -0x30(%rbp), %rsi
movq (%rsi,%rcx,8), %rcx
movq %r12, %rdi
movl %eax, %esi
movl -0x38(%rbp), %r8d
callq 0x3ee13
jmp 0x3f97e
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19346
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movb $0x1, %al
callq 0x12390
jmp 0x3f95e
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19b5d
jmp 0x3f944
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19b4c
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x12390
cmpl $0x100, %eax            # imm = 0x100
jge 0x3faf8
testl %eax, %eax
jle 0x3f97e
movq %r12, %rdi
leaq -0x170(%rbp), %rsi
movl %eax, %edx
callq 0x178c5
incq %r14
movq %r14, %rbx
cmpq %r13, %r14
jb 0x3f7eb
jmp 0x3fada
movslq %r15d, %rax
movq -0x30(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x3e828
jmp 0x3f97e
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19909
movl %edx, %ebx
cmpb $0x0, -0x5e(%rbp)
je 0x3facd
movslq %ebx, %rsi
movq %rax, -0x68(%rbp)
movq %rax, %rdi
callq 0x12420
cmpl %eax, %ebx
jne 0x3fb16
leaq -0x60(%rbp), %rdi
movl $0x2e, %esi
callq 0x12370
testq %rax, %rax
jne 0x3f9f2
cmpl $0x64, %ebx
jge 0x3fb22
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
jmp 0x3f957
movslq %r15d, %rax
movq -0x30(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x3eb9c
jmp 0x3f97e
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19a57
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x12390
jmp 0x3f95e
movslq %r15d, %rax
movq -0x30(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, %xmm0
movq %rdi, %rax
shrq $0x2f, %rax
andl $0xf, %eax
ucomisd %xmm0, %xmm0
movl $0x0, %ecx
cmovnpl %ecx, %eax
cmpl $0xe, %eax
jne 0x3fab3
callq 0x4ebc4
movq -0x10(%rax), %rax
jmp 0x3fabd
leaq -0x33(%rbp), %rdi
callq 0x12a20
testl %eax, %eax
movl $0x400, %ecx            # imm = 0x400
cmovlel %ecx, %eax
movslq %r15d, %rcx
movq -0x30(%rbp), %rdx
movq (%rdx,%rcx,8), %rdx
movq %r12, %rdi
movl %eax, %esi
movl -0x38(%rbp), %ecx
callq 0x3eeb1
jmp 0x3f97e
shll $0x3, %eax
addq 0x454e3(%rip), %rax     # 0x84fa0
movq (%rax), %rsi
movq %r12, %rdi
callq 0x17878
jmp 0x3f97e
movq %r12, %rdi
movq %rax, %rsi
movl %ebx, %edx
jmp 0x3f979
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28b3b(%rip), %rdi     # 0x6862e
callq 0x191a3
leaq 0x28b18(%rip), %rdi     # 0x68617
callq 0x191a3
leaq 0x28ae8(%rip), %rdi     # 0x685f3
leaq -0x60(%rbp), %rsi
xorl %eax, %eax
callq 0x190bb
leaq 0x28a8c(%rip), %rdi     # 0x685a9
callq 0x191a3
leaq 0x28a96(%rip), %rdi     # 0x685bf
callq 0x191a3