// File: /workspace/github_c_makefile_star2_O1/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
xorl %r12d, %r12d
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x16400
movl $0xd0, %r14d
cmpl %r14d, %ebp
cmovll %ebp, %r14d
addl $-0x8, %r14d
movq 0xafe8d(%rip), %rax     # 0xc7ff0
movq (%rax), %rcx
leaq 0x962f6(%rip), %rdi     # 0xae463
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
movl %r14d, %ecx
cmpl $0x0, -0x8(%rbx)
movl $0x0, %r14d
movl %ecx, 0xc(%rsp)
jle 0x1837f
movq %fs:0x0, %rax
movl 0xc(%rsp), %ecx
leaq -0x100c(%rax), %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movzbl (%rbx,%r15), %r13d
movslq %r14d, %rbp
cmpl $0x9, %r13d
je 0x1820f
cmpl $0xa, %r13d
je 0x181ce
cmpl $0x20, %r13d
jne 0x1822f
testl %r14d, %r14d
jne 0x1825d
xorl %r14d, %r14d
cmpb $0xa, %r13b
jne 0x18248
movq 0xafe09(%rip), %rax     # 0xc7ff0
movq (%rax), %rcx
leaq 0x96271(%rip), %rdi     # 0xae462
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
incl (%rax)
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x18248
leal (%r14,%r12), %eax
addl $0x2, %eax
cmpl %eax, %ecx
jle 0x182e7
movslq %r14d, %r14
movw $0x2020, 0x20(%rsp,%r14) # imm = 0x2020
addl $0x2, %r14d
jmp 0x18248
leal (%r12,%r14), %eax
incl %eax
cmpl %eax, %ecx
jle 0x18333
movslq %r14d, %rax
incl %r14d
movb %r13b, 0x20(%rsp,%rax)
incq %r15
movslq -0x8(%rbx), %rax
cmpq %rax, %r15
jl 0x181b4
jmp 0x1837f
leal 0x1(%r12), %edx
leal (%r12,%r14), %esi
incl %esi
cmpl %esi, %ecx
movl $0x0, %eax
cmovlel %eax, %edx
movl %edx, 0x1c(%rsp)
testl %r12d, %r12d
je 0x182ac
cmpl %esi, %ecx
movq 0xafd6c(%rip), %rax     # 0xc7ff0
movq (%rax), %rdi
movl %esi, 0x18(%rsp)
leaq 0x961d0(%rip), %rsi     # 0xae462
leaq 0x961cd(%rip), %rax     # 0xae466
cmovgq %rax, %rsi
xorl %eax, %eax
callq 0x16600
movl 0x18(%rsp), %esi
movl 0xc(%rsp), %ecx
testl %r12d, %r12d
je 0x182bc
cmpl %esi, %ecx
jg 0x182bc
movq 0x10(%rsp), %rax
incl (%rax)
movl 0x1c(%rsp), %r12d
addl %r14d, %r12d
movq 0xafd25(%rip), %rax     # 0xc7ff0
movq (%rax), %rcx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
movl 0xc(%rsp), %ecx
jmp 0x181d7
testl %r12d, %r12d
movq 0xafcff(%rip), %r12     # 0xc7ff0
jne 0x1830a
movq (%r12), %rcx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
xorl %r14d, %r14d
movq (%r12), %rcx
leaq 0x9614d(%rip), %rdi     # 0xae462
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
movq 0x10(%rsp), %rax
incl (%rax)
xorl %r12d, %r12d
movl 0xc(%rsp), %ecx
jmp 0x1821e
testl %r12d, %r12d
movq 0xafcb3(%rip), %r12     # 0xc7ff0
jne 0x18356
movq (%r12), %rcx
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
xorl %r14d, %r14d
movq (%r12), %rcx
leaq 0x96101(%rip), %rdi     # 0xae462
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x16ac0
movq 0x10(%rsp), %rax
incl (%rax)
xorl %r12d, %r12d
movl 0xc(%rsp), %ecx
jmp 0x1823d
testl %r14d, %r14d
jne 0x18396
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal (%r12,%r14), %ebx
incl %ebx
testl %r12d, %r12d
je 0x183ca
cmpl %ebx, %ecx
movq 0xafc46(%rip), %rax     # 0xc7ff0
movq (%rax), %rdi
leaq 0x960b2(%rip), %rax     # 0xae466
leaq 0x960a7(%rip), %rsi     # 0xae462
cmovgq %rax, %rsi
xorl %eax, %eax
callq 0x16600
movl 0xc(%rsp), %ecx
testl %r12d, %r12d
je 0x183e5
cmpl %ebx, %ecx
jg 0x183e5
movq %fs:0x0, %rax
incl -0x100c(%rax)
movslq %r14d, %rsi
movq 0xafc01(%rip), %rax     # 0xc7ff0
movq (%rax), %rcx
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x16ac0
jmp 0x18384