// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0xc(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x10(%rbp)
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x15410
movl $0x0, -0x114(%rbp)
movl $0x0, -0x118(%rbp)
cmpl $0xc8, -0x10(%rbp)
jle 0x81e72
movl $0xc8, -0x10(%rbp)
movq 0x6b177(%rip), %rax     # 0xecff0
movq (%rax), %rdi
leaq 0x54ac0(%rip), %rsi     # 0xd6943
movb $0x0, %al
callq 0x15600
movl $0x0, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl -0x8(%rcx), %eax
jge 0x821c1
movq -0x8(%rbp), %rax
movslq -0x11c(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x11d(%rbp)
movzbl -0x11d(%rbp), %eax
movl %eax, -0x134(%rbp)
subl $0x9, %eax
je 0x81fa1
jmp 0x81ed3
movl -0x134(%rbp), %eax
subl $0xa, %eax
je 0x82063
jmp 0x81ee4
movl -0x134(%rbp), %eax
subl $0x20, %eax
je 0x82063
jmp 0x81ef5
movl -0x10(%rbp), %eax
movl -0x118(%rbp), %ecx
addl -0x114(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x81f7c
cmpl $0x0, -0x118(%rbp)
jne 0x81f40
leaq -0x110(%rbp), %rdi
movslq -0x114(%rbp), %rsi
movq 0x6b0c7(%rip), %rax     # 0xecff0
movq (%rax), %rcx
movl $0x1, %edx
callq 0x15ac0
movl $0x0, -0x114(%rbp)
movq 0x6b0a9(%rip), %rax     # 0xecff0
movq (%rax), %rdi
leaq 0x549f1(%rip), %rsi     # 0xd6942
movb $0x0, %al
callq 0x15600
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x118(%rbp)
movb -0x11d(%rbp), %cl
movl -0x114(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x114(%rbp)
cltq
movb %cl, -0x110(%rbp,%rax)
jmp 0x821ab
movl -0x10(%rbp), %eax
movl -0x118(%rbp), %ecx
addl -0x114(%rbp), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jg 0x82028
cmpl $0x0, -0x118(%rbp)
jne 0x81fec
leaq -0x110(%rbp), %rdi
movslq -0x114(%rbp), %rsi
movq 0x6b01b(%rip), %rax     # 0xecff0
movq (%rax), %rcx
movl $0x1, %edx
callq 0x15ac0
movl $0x0, -0x114(%rbp)
movq 0x6affd(%rip), %rax     # 0xecff0
movq (%rax), %rdi
leaq 0x54945(%rip), %rsi     # 0xd6942
movb $0x0, %al
callq 0x15600
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x118(%rbp)
movl -0x114(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x114(%rbp)
cltq
movb $0x20, -0x110(%rbp,%rax)
movl -0x114(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x114(%rbp)
cltq
movb $0x20, -0x110(%rbp,%rax)
jmp 0x821ab
cmpl $0x0, -0x114(%rbp)
je 0x82161
movl -0x118(%rbp), %eax
movl %eax, -0x124(%rbp)
movl -0x10(%rbp), %eax
movl -0x118(%rbp), %ecx
addl -0x114(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x128(%rbp)
cmpl $0x0, -0x128(%rbp)
je 0x820b8
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x820c2
movl $0x0, -0x118(%rbp)
movl -0x114(%rbp), %eax
addl -0x118(%rbp), %eax
movl %eax, -0x118(%rbp)
cmpl $0x0, -0x124(%rbp)
je 0x82109
movq 0x6af0c(%rip), %rax     # 0xecff0
movq (%rax), %rdi
movl -0x128(%rbp), %ecx
leaq 0x5484e(%rip), %rsi     # 0xd6942
leaq 0x5484b(%rip), %rax     # 0xd6946
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movb $0x0, %al
callq 0x15600
cmpl $0x0, -0x124(%rbp)
je 0x82135
cmpl $0x0, -0x128(%rbp)
jne 0x82135
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq -0x110(%rbp), %rdi
movslq -0x114(%rbp), %rsi
movq 0x6aea6(%rip), %rax     # 0xecff0
movq (%rax), %rcx
movl $0x1, %edx
callq 0x15ac0
movl $0x0, -0x114(%rbp)
movzbl -0x11d(%rbp), %eax
cmpl $0xa, %eax
jne 0x821a9
movq 0x6ae7c(%rip), %rax     # 0xecff0
movq (%rax), %rdi
leaq 0x547c4(%rip), %rsi     # 0xd6942
movb $0x0, %al
callq 0x15600
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0x118(%rbp)
jmp 0x821ab
jmp 0x821ad
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
jmp 0x81e94
cmpl $0x0, -0x114(%rbp)
je 0x822c2
movl -0x118(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl -0x10(%rbp), %eax
movl -0x118(%rbp), %ecx
addl -0x114(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x130(%rbp)
cmpl $0x0, -0x130(%rbp)
je 0x82216
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x82220
movl $0x0, -0x118(%rbp)
movl -0x114(%rbp), %eax
addl $0x1, %eax
addl -0x118(%rbp), %eax
movl %eax, -0x118(%rbp)
cmpl $0x0, -0x12c(%rbp)
je 0x8226a
movq 0x6adab(%rip), %rax     # 0xecff0
movq (%rax), %rdi
movl -0x130(%rbp), %ecx
leaq 0x546ed(%rip), %rsi     # 0xd6942
leaq 0x546ea(%rip), %rax     # 0xd6946
cmpl $0x0, %ecx
cmovneq %rax, %rsi
movb $0x0, %al
callq 0x15600
cmpl $0x0, -0x12c(%rbp)
je 0x82296
cmpl $0x0, -0x130(%rbp)
jne 0x82296
movq %fs:0x0, %rax
leaq -0x100c(%rax), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq -0x110(%rbp), %rdi
movslq -0x114(%rbp), %rsi
movq 0x6ad45(%rip), %rax     # 0xecff0
movq (%rax), %rcx
movl $0x1, %edx
callq 0x15ac0
movl $0x0, -0x114(%rbp)
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax,%rax)