// File: /workspace/github_c_makefile_star2_O2/msteveb[P]autosetup/./jimsh0.c
// Function: aio_cmd_gets
static int aio_cmd_gets(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    AioFile *af = Jim_CmdPrivData(interp);
    Jim_Obj *objPtr = NULL;
    int len;
    int nb;
    unsigned flags = AIO_ONEREAD;
    char *nl = NULL;
    int offset = 0;

    errno = 0;


    nb = aio_start_nonblocking(af);
    if (nb) {
        flags |= AIO_NONBLOCK;
    }

    while (!aio_eof(af)) {
        if (af->readbuf) {
            const char *pt = Jim_GetString(af->readbuf, &len);
            nl = memchr(pt + offset, '\n', len - offset);
            if (nl) {

                objPtr = Jim_NewStringObj(interp, pt, nl - pt);

                aio_consume(af->readbuf, nl - pt + 1);
                break;
            }
            offset = len;
        }


        if (aio_read_len(interp, af, flags, -1) != JIM_OK) {
            break;
        }
    }

    aio_set_nonblocking(af, nb);

    if (!nl && aio_eof(af) && af->readbuf) {

        objPtr = af->readbuf;
        af->readbuf = NULL;
    }
    else if (!objPtr) {
        objPtr = Jim_NewStringObj(interp, NULL, 0);
    }

    if (argc) {
        if (Jim_SetVariable(interp, argv[0], objPtr) != JIM_OK) {
            Jim_FreeNewObj(interp, objPtr);
            return JIM_ERR;
        }

        len = Jim_Length(objPtr);

        if (!nl && len == 0) {

            len = -1;
        }
        Jim_SetResultInt(interp, len);
    }
    else {
        Jim_SetResult(interp, objPtr);
    }
    return JIM_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, -0x40(%rbp)
movl %esi, -0x34(%rbp)
movq %rdi, %rbx
movq 0x1b8(%rdi), %r13
callq 0x6080
andl $0x0, (%rax)
movq %r13, %rdi
callq 0x12d64
xorl %ecx, %ecx
movl %eax, -0x30(%rbp)
testl %eax, %eax
setne %cl
shll $0x4, %ecx
orl $0x20, %ecx
movl %ecx, -0x38(%rbp)
xorl %r12d, %r12d
movb $0x1, %r15b
testb $0x4, 0xc(%r13)
jne 0x1264d
movq %rbx, %r15
movq 0x30(%r13), %rdi
testq %rdi, %rdi
je 0x1262d
leaq -0x2c(%rbp), %rsi
callq 0x7fc7
movq %rax, %r14
movslq %r12d, %rax
leaq (%r14,%rax), %rdi
movl -0x2c(%rbp), %r12d
movl %r12d, %ecx
subl %eax, %ecx
movslq %ecx, %rdx
pushq $0xa
popq %rsi
callq 0x6290
testq %rax, %rax
jne 0x12652
movq %r15, %rbx
movq %r15, %rdi
movq %r13, %rsi
movl -0x38(%rbp), %edx
pushq $-0x1
popq %rcx
callq 0x12d8b
testl %eax, %eax
je 0x125eb
xorl %r14d, %r14d
movb $0x1, %r15b
jmp 0x1267b
xorl %r14d, %r14d
jmp 0x1267b
movq %rax, %rbx
subl %r14d, %ebx
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x7363
movq %rax, %r14
movq 0x30(%r13), %rdi
incl %ebx
movl %ebx, %esi
movq %r15, %rbx
callq 0x1303c
xorl %r15d, %r15d
movq %r13, %rdi
movl -0x30(%rbp), %esi
callq 0x12e9b
testb %r15b, %r15b
je 0x126a2
testb $0x4, 0xc(%r13)
je 0x126a2
movq 0x30(%r13), %rax
testq %rax, %rax
je 0x126a2
andq $0x0, 0x30(%r13)
jmp 0x126b3
testq %r14, %r14
jne 0x126b6
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x7363
movq %rax, %r14
cmpl $0x0, -0x34(%rbp)
je 0x126e2
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x8306
testl %eax, %eax
je 0x12713
movq %rbx, %rdi
movq %r14, %rsi
callq 0x73bf
pushq $0x1
popq %rax
jmp 0x12704
incl 0x10(%r14)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x126ff
movq %rbx, %rdi
callq 0x73bf
movq %r14, (%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0xa61a
xorl %ecx, %ecx
cmpl $0x1, %eax
sbbl %ecx, %ecx
orl %eax, %ecx
testb %r15b, %r15b
cmovel %eax, %ecx
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rsi
movq %rbx, %rdi
callq 0x8212
movq %rax, %r14
incl 0x10(%rax)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x2, %eax
jl 0x126f7
jmp 0x126ff