// File: /workspace/github_c_makefile_star2_O1/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 0x40218
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 0x3ff47
movb (%r14), %al
cmpb $0x25, %al
jne 0x3ff57
addq $0x2, %rbx
movzbl %al, %esi
movq %r12, %rdi
callq 0x179a7
movq %rbx, %r14
jmp 0x400b7
movzbl %al, %esi
movq %r12, %rdi
callq 0x179a7
jmp 0x400b7
incl %r15d
cmpl -0x3c(%rbp), %r15d
jge 0x4022a
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
leaq -0x3f(%rbp), %rdx
leaq -0x33(%rbp), %rcx
callq 0x3fba9
movq %rax, %r14
movzbl (%rax), %ebx
leal -0x41(%rbx), %eax
cmpl $0x37, %eax
ja 0x40242
leaq 0x29477(%rip), %rcx     # 0x69408
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x33(%rbp), %rdi
callq 0x12a30
testl %eax, %eax
movl $0x400, %ecx            # imm = 0x400
cmovlel %ecx, %eax
leal -0x4d(%rbx), %esi
cmpl $0x4, %esi
ja 0x3ffc4
movl $0x1, %ecx
movl $0x19, %edx
btl %esi, %edx
jb 0x3ffcc
xorl %ecx, %ecx
cmpl $0x4e, %ebx
sete %cl
leal -0x4e(%rbx), %edi
cmpl $0x23, %edi
ja 0x3ffe9
movl $0x2, %edx
movabsq $0x800000009, %r8       # imm = 0x800000009
btq %rdi, %r8
jb 0x3fff3
xorl %edx, %edx
cmpl $0x6e, %ebx
sete %dl
addl %edx, %edx
cmpl $0x20, %esi
ja 0x4000d
movl $0x4, %edi
movabsq $0x100000003, %r8       # imm = 0x100000003
btq %rsi, %r8
jb 0x40019
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 0x3f509
xorl %edx, %edx
jmp 0x40095
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x1940c
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movb $0x1, %al
callq 0x12390
jmp 0x40093
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19c23
jmp 0x40079
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19c12
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x12390
movl %eax, %edx
cmpl $0x100, %edx            # imm = 0x100
jge 0x40236
testl %edx, %edx
jle 0x400b4
movq %r12, %rdi
leaq -0x170(%rbp), %rsi
callq 0x17925
incq %r14
movq %r14, %rbx
cmpq %r13, %r14
jb 0x3ff1f
jmp 0x40218
movslq %r15d, %rax
movq -0x30(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x3ef10
jmp 0x40036
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x199cf
movl %edx, %ebx
cmpb $0x0, -0x5e(%rbp)
je 0x40206
movslq %ebx, %rsi
movq %rax, -0x68(%rbp)
movq %rax, %rdi
callq 0x12420
cmpl %eax, %ebx
jne 0x40254
leaq -0x60(%rbp), %rdi
movl $0x2e, %esi
callq 0x12370
testq %rax, %rax
jne 0x4012b
cmpl $0x64, %ebx
jge 0x40260
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
jmp 0x4008c
movslq %r15d, %rax
movq -0x30(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x3f295
jmp 0x40036
movq -0x30(%rbp), %rdi
movl %r15d, %esi
callq 0x19b1d
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x12390
jmp 0x40093
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 0x401ec
callq 0x4f838
movq -0x10(%rax), %rax
jmp 0x401f6
leaq -0x33(%rbp), %rdi
callq 0x12a30
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 0x3f5a4
jmp 0x40036
shll $0x3, %eax
addq 0x45daa(%rip), %rax     # 0x85fa0
movq (%rax), %rsi
movq %r12, %rdi
callq 0x178d8
jmp 0x40036
movq %r12, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x17925
jmp 0x40036
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2941d(%rip), %rdi     # 0x6964e
callq 0x19263
leaq 0x293fa(%rip), %rdi     # 0x69637
callq 0x19263
leaq 0x293ca(%rip), %rdi     # 0x69613
leaq -0x60(%rbp), %rsi
xorl %eax, %eax
callq 0x1917b
leaq 0x2936e(%rip), %rdi     # 0x695c9
callq 0x19263
leaq 0x29378(%rip), %rdi     # 0x695df
callq 0x19263