// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/build/c/shell.c
// Function: doc_format
static void doc_format(JanetString doc, int32_t width) {
    int32_t maxcol = width - 8;
    uint8_t wordbuf[256] = {0};
    int32_t wordp = 0;
    int32_t current = 0;
    if (maxcol > 200) maxcol = 200;
    fprintf(stderr, "    ");
    for (int32_t i = 0; i < janet_string_length(doc); i++) {
        uint8_t b = doc[i];
        switch (b) {
            default: {
                if (maxcol <= current + wordp + 1) {
                    if (!current) {
                        fwrite(wordbuf, wordp, 1, stderr);
                        wordp = 0;
                    }
                    fprintf(stderr, "\n    ");
                    gbl_lines_below++;
                    current = 0;
                }
                wordbuf[wordp++] = b;
                break;
            }
            case '\t': {
                if (maxcol <= current + wordp + 2) {
                    if (!current) {
                        fwrite(wordbuf, wordp, 1, stderr);
                        wordp = 0;
                    }
                    fprintf(stderr, "\n    ");
                    gbl_lines_below++;
                    current = 0;
                }
                wordbuf[wordp++] = ' ';
                wordbuf[wordp++] = ' ';
                break;
            }
            case '\n':
            case ' ': {
                if (wordp) {
                    int32_t oldcur = current;
                    int spacer = maxcol > current + wordp + 1;
                    if (spacer) current++;
                    else current = 0;
                    current += wordp;
                    if (oldcur) fprintf(stderr, spacer ? " " : "\n    ");
                    if (oldcur && !spacer) gbl_lines_below++;
                    fwrite(wordbuf, wordp, 1, stderr);
                    wordp = 0;
                }
                if (b == '\n') {
                    fprintf(stderr, "\n    ");
                    gbl_lines_below++;
                    current = 0;
                }
            }
        }
    }
    if (wordp) {
        int32_t oldcur = current;
        int spacer = maxcol > current + wordp + 1;
        if (spacer) current++;
        else current = 0;
        current += wordp + 1;
        if (oldcur) fprintf(stderr, spacer ? " " : "\n    ");
        if (oldcur && !spacer) gbl_lines_below++;
        fwrite(wordbuf, wordp, 1, stderr);
        wordp = 0;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x15400
movl $0xd0, %r13d
cmpl %r13d, %ebp
cmovll %ebp, %r13d
movq 0xaeeee(%rip), %rax     # 0xc5ff0
movq (%rax), %rcx
leaq 0x95447(%rip), %rdi     # 0xac553
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
cmpl $0x0, -0x8(%rbx)
jle 0x172fa
addl $-0x8, %r13d
movq %fs:0x0, %rax
movq %rax, 0x18(%rsp)
leaq -0x100c(%rax), %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %eax, %eax
movzbl (%rbx,%r12), %r15d
movslq %ebp, %r14
cmpl $0x9, %r15d
je 0x17198
cmpl $0xa, %r15d
je 0x17163
cmpl $0x20, %r15d
jne 0x171b6
testl %ebp, %ebp
jne 0x171e3
xorl %ebp, %ebp
cmpb $0xa, %r15b
jne 0x171ce
movq 0xaee7a(%rip), %rax     # 0xc5ff0
movq (%rax), %rcx
leaq 0x953d2(%rip), %rdi     # 0xac552
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
movq 0x8(%rsp), %rax
incl (%rax)
xorl %eax, %eax
xorl %ebp, %ebp
jmp 0x171ce
leal (%rax,%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %r13d
jle 0x1726a
movslq %ebp, %rbp
movw $0x2020, 0x20(%rsp,%rbp) # imm = 0x2020
addl $0x2, %ebp
jmp 0x171ce
leal (%rax,%rbp), %ecx
incl %ecx
cmpl %ecx, %r13d
jle 0x172ad
movslq %ebp, %rcx
incl %ebp
movb %r15b, 0x20(%rsp,%rcx)
incq %r12
movslq -0x8(%rbx), %rcx
cmpq %rcx, %r12
jl 0x17149
jmp 0x172f6
leal 0x1(%rax), %edx
leal (%rax,%rbp), %esi
incl %esi
cmpl %esi, %r13d
movl $0x0, %ecx
cmovlel %ecx, %edx
movl %edx, 0x14(%rsp)
testl %eax, %eax
je 0x17236
cmpl %esi, %r13d
movq 0xaede8(%rip), %rax     # 0xc5ff0
movq (%rax), %rdi
movl %esi, 0x4(%rsp)
leaq 0x9533c(%rip), %rsi     # 0xac552
leaq 0x95339(%rip), %rax     # 0xac556
cmovgq %rax, %rsi
xorl %eax, %eax
callq 0x15600
cmpl 0x4(%rsp), %r13d
jg 0x17236
movq 0x8(%rsp), %rax
incl (%rax)
movl %r13d, 0x4(%rsp)
movl 0x14(%rsp), %r13d
addl %ebp, %r13d
movq 0xaeda6(%rip), %rax     # 0xc5ff0
movq (%rax), %rcx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
movl %r13d, %eax
movl 0x4(%rsp), %r13d
jmp 0x17167
testl %eax, %eax
movq 0xaed7d(%rip), %r15     # 0xc5ff0
jne 0x1728a
movq (%r15), %rcx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
xorl %ebp, %ebp
movq (%r15), %rcx
leaq 0x952be(%rip), %rdi     # 0xac552
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
movq 0x8(%rsp), %rax
incl (%rax)
xorl %eax, %eax
jmp 0x171a7
testl %eax, %eax
movq 0xaed3a(%rip), %rax     # 0xc5ff0
jne 0x172d3
movq (%rax), %rcx
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
movq %rax, %r14
callq 0x15ac0
movq %r14, %rax
xorl %ebp, %ebp
movq (%rax), %rcx
leaq 0x95275(%rip), %rdi     # 0xac552
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x15ac0
movq 0x8(%rsp), %rax
incl (%rax)
xorl %eax, %eax
jmp 0x171c4
testl %ebp, %ebp
jne 0x1730c
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
movq 0xaecdb(%rip), %r14     # 0xc5ff0
je 0x1734b
leal (%rax,%rbp), %ebx
incl %ebx
cmpl %ebx, %r13d
movq (%r14), %rdi
leaq 0x95229(%rip), %rsi     # 0xac552
leaq 0x95226(%rip), %rax     # 0xac556
cmovgq %rax, %rsi
xorl %eax, %eax
callq 0x15600
cmpl %ebx, %r13d
jg 0x1734b
movq 0x18(%rsp), %rax
incl -0x100c(%rax)
movslq %ebp, %rsi
movq (%r14), %rcx
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x15ac0
jmp 0x172fa