// File: /workspace/github_c_makefile_star2_O2/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, -0x38(%rbp)
movl %ecx, -0x4c(%rbp)
movl %edx, -0x2c(%rbp)
movq %rsi, %r15
movq %rdi, %r12
movq %rsi, %rdi
callq 0x12310
movq %rax, %r13
addq %r15, %r13
movl 0x10(%r12), %eax
movl %eax, -0x40(%rbp)
leaq -0x70(%rbp), %rbx
cmpq %r13, %r15
jae 0x3c53b
movb (%r15), %al
leaq 0x1(%r15), %r14
cmpb $0x25, %al
jne 0x3c2ac
cmpb $0x25, (%r14)
jne 0x3c2bc
addq $0x2, %r15
movq %r12, %rdi
pushq $0x25
popq %rsi
callq 0x161be
jmp 0x3c281
movzbl %al, %esi
movq %r12, %rdi
callq 0x161be
movq %r14, %r15
jmp 0x3c281
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl -0x4c(%rbp), %eax
jge 0x3c54d
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x4f(%rbp), %rdx
leaq -0x3b(%rbp), %rcx
callq 0x3beb6
movq %rax, %r15
movzbl (%rax), %r14d
leal -0x41(%r14), %eax
cmpl $0x37, %eax
ja 0x3c565
leaq 0x2810d(%rip), %rcx     # 0x64408
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movslq -0x2c(%rbp), %rcx
jmpq *%rax
movq %rcx, -0x48(%rbp)
leaq -0x3b(%rbp), %rdi
callq 0x12a20
testl %eax, %eax
movl $0x400, %ecx            # imm = 0x400
cmovlel %ecx, %eax
leal -0x4d(%r14), %esi
cmpl $0x4, %esi
ja 0x3c333
pushq $0x19
popq %rcx
btl %esi, %ecx
pushq $0x1
popq %rcx
jb 0x3c33c
xorl %ecx, %ecx
cmpl $0x4e, %r14d
sete %cl
leal -0x4e(%r14), %edx
cmpl $0x23, %edx
ja 0x3c358
movabsq $0x800000009, %rdi      # imm = 0x800000009
btq %rdx, %rdi
pushq $0x2
popq %rdx
jb 0x3c363
xorl %edx, %edx
cmpl $0x6e, %r14d
sete %dl
addl %edx, %edx
cmpl $0x20, %esi
ja 0x3c37b
movabsq $0x100000003, %rdi      # imm = 0x100000003
btq %rsi, %rdi
pushq $0x4
popq %rsi
jb 0x3c388
xorl %esi, %esi
cmpl $0x6e, %r14d
sete %sil
shll $0x2, %esi
orl %ecx, %edx
orl %esi, %edx
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movq %r12, %rdi
movl %eax, %esi
movl -0x40(%rbp), %r8d
callq 0x3b8ae
jmp 0x3c41f
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x17937
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
movq %rbx, %rdx
movb $0x1, %al
callq 0x12390
jmp 0x3c3ff
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x180f6
jmp 0x3c3e6
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x180e5
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x12390
cmpl $0x100, %eax            # imm = 0x100
jge 0x3c559
testl %eax, %eax
jle 0x3c41f
movq %r12, %rdi
leaq -0x170(%rbp), %rsi
movl %eax, %edx
callq 0x16172
incq %r15
jmp 0x3c281
movq -0x38(%rbp), %rax
movq (%rax,%rcx,8), %rsi
movq %r12, %rdi
callq 0x3b300
jmp 0x3c41f
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x17ea2
cmpb $0x0, -0x6e(%rbp)
je 0x3c530
movslq %edx, %rsi
movq %rax, -0x48(%rbp)
movq %rax, %rdi
movl %edx, %r14d
callq 0x12420
cmpl %eax, %r14d
jne 0x3c577
movq %rbx, %rdi
pushq $0x2e
popq %rsi
callq 0x12370
testq %rax, %rax
sete %al
cmpl $0x64, %r14d
setge %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x3c583
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
jmp 0x3c3f8
movq -0x38(%rbp), %rax
movq (%rax,%rcx,8), %rsi
movq %r12, %rdi
callq 0x3b65f
jmp 0x3c41f
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x17ff0
movl $0x100, %esi            # imm = 0x100
leaq -0x170(%rbp), %rdi
movq %rbx, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x12390
jmp 0x3c3ff
movq -0x38(%rbp), %rax
movq (%rax,%rcx,8), %rdi
callq 0x3c0b2
movq %r12, %rdi
movq %rax, %rsi
callq 0x1614c
jmp 0x3c41f
leaq -0x3b(%rbp), %rdi
movq %rcx, %r14
callq 0x12a20
testl %eax, %eax
movl $0x400, %ecx            # imm = 0x400
cmovlel %ecx, %eax
movq -0x38(%rbp), %rcx
movq (%rcx,%r14,8), %rdx
movq %r12, %rdi
movl %eax, %esi
movl -0x40(%rbp), %ecx
callq 0x3b944
jmp 0x3c41f
movq %r12, %rdi
movq %rax, %rsi
jmp 0x3c41a
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x280fa(%rip), %rdi     # 0x6464e
callq 0x177b1
leaq 0x280d7(%rip), %rdi     # 0x64637
callq 0x177b1
leaq 0x280a7(%rip), %rdi     # 0x64613
leaq -0x70(%rbp), %rsi
xorl %eax, %eax
callq 0x176c9
leaq 0x2804b(%rip), %rdi     # 0x645c9
callq 0x177b1
leaq 0x28055(%rip), %rdi     # 0x645df
callq 0x177b1