// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdx, -0x50(%rbp)
movl %esi, -0x38(%rbp)
movq %rdi, %rbx
movq 0x1b8(%rdi), %r13
callq 0x6080
movl $0x0, (%rax)
movl 0xc(%r13), %r14d
cmpq $0x0, 0x10(%r13)
je 0x141b5
movq %r13, %rdi
movl $0x1, %esi
callq 0x14c5d
shrl $0x4, %r14d
andl $0x1, %r14d
movl %r14d, -0x34(%rbp)
shll $0x4, %r14d
orl $0x20, %r14d
movl %r14d, -0x3c(%rbp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movq $0x0, -0x48(%rbp)
movq %rbx, -0x30(%rbp)
testb $0x4, 0xc(%r13)
jne 0x14279
movq 0x30(%r13), %r15
testq %r15, %r15
je 0x1425e
cmpq $0x0, (%r15)
jne 0x14203
movq 0x8(%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movl 0x14(%r15), %ebx
movq (%r15), %r15
movslq %r12d, %rax
leaq (%r15,%rax), %rdi
movl %ebx, %ecx
subl %eax, %ecx
movslq %ecx, %rdx
movl $0xa, %esi
callq 0x6290
movq %rax, %r14
testq %rax, %rax
je 0x14252
movl %r14d, %ebx
subl %r15d, %ebx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x7516
movq %rax, -0x48(%rbp)
movq 0x30(%r13), %rdi
incl %ebx
movl %ebx, %esi
callq 0x14e1f
movl %r12d, %ebx
movl %ebx, %r12d
testq %r14, %r14
movq -0x30(%rbp), %rbx
jne 0x14279
movq %rbx, %rdi
movq %r13, %rsi
movl -0x3c(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x14ad8
testl %eax, %eax
je 0x141df
movq %r13, %rdi
movl -0x34(%rbp), %esi
callq 0x14c5d
testq %r14, %r14
jne 0x1429f
testb $0x4, 0xc(%r13)
je 0x1429f
movq 0x30(%r13), %r15
testq %r15, %r15
je 0x1429f
addq $0x30, %r13
jmp 0x142cb
movq -0x48(%rbp), %r15
testq %r15, %r15
jne 0x142d3
movq %rbx, %rdi
callq 0xae58
movq %rax, %r15
leaq 0x23fde(%rip), %rcx     # 0x38298
movq %rcx, (%rax)
movl $0x0, 0x14(%rax)
movq %rax, %r13
addq $0x8, %r13
movq $0x0, (%r13)
cmpl $0x0, -0x38(%rbp)
je 0x14301
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x871b
testl %eax, %eax
je 0x14332
movq %rbx, %rdi
movq %r15, %rsi
callq 0x759a
movl $0x1, %eax
jmp 0x14323
incl 0x10(%r15)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1431e
movq %rbx, %rdi
callq 0x759a
movq %r15, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, (%r15)
jne 0x14342
movq 0x8(%r15), %rax
movq %r15, %rdi
callq *0x18(%rax)
movslq 0x14(%r15), %rax
orq %rax, %r14
movq $-0x1, %rbx
cmovneq %rax, %rbx
movq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0xae58
movq %rax, %r15
leaq 0x21f76(%rip), %rax     # 0x362e0
movq %rax, 0x8(%r15)
movq $0x0, (%r15)
movq %rbx, 0x18(%r15)
movq %r14, %rbx
incl 0x10(%r15)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x2, %eax
jl 0x14316
jmp 0x1431e