// File: /workspace/github_c_makefile_star2_O3/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, -0x30(%rbp)
movq %rdi, %rbx
movq 0x1b8(%rdi), %r13
callq 0x6080
movl $0x0, (%rax)
movl 0xc(%r13), %r14d
cmpq $0x0, 0x10(%r13)
je 0x13d53
movq %r13, %rdi
movl $0x1, %esi
callq 0x147c8
shrl $0x4, %r14d
andl $0x1, %r14d
movl %r14d, -0x2c(%rbp)
shll $0x4, %r14d
orl $0x20, %r14d
movl %r14d, -0x34(%rbp)
leaq 0x30(%r13), %r15
xorl %r12d, %r12d
movq %rbx, -0x40(%rbp)
movq %r13, %r14
movq %r13, -0x48(%rbp)
testb $0x4, 0xc(%r14)
jne 0x13dea
movq %r15, %r13
movq (%r15), %r14
testq %r14, %r14
je 0x13dcc
movq (%r14), %r15
testq %r15, %r15
jne 0x13da4
movq 0x8(%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movq (%r14), %r15
movl 0x14(%r14), %ebx
movslq %r12d, %rax
leaq (%r15,%rax), %rdi
movl %ebx, %ecx
subl %eax, %ecx
movslq %ecx, %rdx
movl $0xa, %esi
callq 0x6290
movl %ebx, %r12d
testq %rax, %rax
movq -0x40(%rbp), %rbx
jne 0x13e0e
movq %rbx, %rdi
movq -0x48(%rbp), %r14
movq %r14, %rsi
movl -0x34(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x14696
testl %eax, %eax
movq %r13, %r15
je 0x13d7d
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x147c8
movq %r14, %rax
movb $0x1, %r14b
testb $0x4, 0xc(%rax)
je 0x13e4b
movq (%r15), %r12
movb $0x1, %r14b
testq %r12, %r12
jne 0x13e71
jmp 0x13e4b
movq %rax, %r14
subl %r15d, %r14d
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x7508
movq %rax, %r12
movq -0x48(%rbp), %r15
movq 0x30(%r15), %rdi
incl %r14d
movl %r14d, %esi
callq 0x1498c
movq %r15, %rdi
movl -0x2c(%rbp), %esi
callq 0x147c8
xorl %r14d, %r14d
testq %r12, %r12
jne 0x13e78
movq %rbx, %rdi
callq 0xae38
movq %rax, %r12
leaq 0x2343b(%rip), %rax     # 0x37298
movq %rax, (%r12)
movl $0x0, 0x14(%r12)
movq %r12, %r15
addq $0x8, %r15
movq $0x0, (%r15)
cmpl $0x0, -0x30(%rbp)
je 0x13ea6
movq -0x50(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x876e
testl %eax, %eax
je 0x13ed8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x758c
movl $0x1, %eax
jmp 0x13ec9
incl 0x10(%r12)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x13ec4
movq %rbx, %rdi
callq 0x758c
movq %r12, (%rbx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, (%r12)
jne 0x13eea
movq 0x8(%r12), %rax
movq %r12, %rdi
callq *0x18(%rax)
movslq 0x14(%r12), %rax
xorl %ebx, %ebx
cmpq $0x1, %rax
sbbq %rbx, %rbx
orq %rax, %rbx
testb %r14b, %r14b
cmoveq %rax, %rbx
movq -0x40(%rbp), %r14
movq %r14, %rdi
callq 0xae38
movq %rax, %r12
leaq 0x213d8(%rip), %rax     # 0x352f0
movq %rax, 0x8(%r12)
movq $0x0, (%r12)
movq %rbx, 0x18(%r12)
movq %r14, %rbx
incl 0x10(%r12)
movq (%r14), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x2, %eax
jl 0x13ebc
jmp 0x13ec4