// File: /workspace/github_c_makefile_star2_O0/msteveb[P]autosetup/./jimsh0.c
// Function: aio_read_len
static int aio_read_len(Jim_Interp *interp, AioFile *af, unsigned flags, int neededLen)
{
    if (!af->readbuf) {
        af->readbuf = Jim_NewStringObj(interp, NULL, 0);
    }

    if (neededLen >= 0) {
        neededLen -= Jim_Length(af->readbuf);
        if (neededLen <= 0) {
            return JIM_OK;
        }
    }

    while (neededLen && !aio_eof(af)) {
        int retval;
        int readlen;

        if (neededLen == -1) {
            readlen = af->rbuf_len;
        }
        else {
            readlen = (neededLen > af->rbuf_len ? af->rbuf_len : neededLen);
        }

        if (!af->rbuf) {
            af->rbuf = Jim_Alloc(af->rbuf_len);
        }
        retval = af->fops->reader(af, af->rbuf, readlen, flags & AIO_NONBLOCK);
        if (retval > 0) {
            if (retval) {
                Jim_AppendString(interp, af->readbuf, af->rbuf, retval);
            }
            if (neededLen != -1) {
                neededLen -= retval;
            }
            if (flags & AIO_ONEREAD) {
                return JIM_OK;
            }
            continue;
        }
        if ((flags & AIO_ONEREAD) || JimCheckStreamError(interp, af)) {
            return JIM_ERR;
        }
        break;
    }

    return JIM_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x1854b
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x7990
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
cmpl $0x0, -0x20(%rbp)
jl 0x1857c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xc700
movl %eax, %ecx
movl -0x20(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jg 0x1857a
movl $0x0, -0x4(%rbp)
jmp 0x186b9
jmp 0x1857c
jmp 0x1857e
xorl %eax, %eax
cmpl $0x0, -0x20(%rbp)
movb %al, -0x29(%rbp)
je 0x1859d
movq -0x18(%rbp), %rdi
callq 0x18820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x185a9
jmp 0x186b2
cmpl $-0x1, -0x20(%rbp)
jne 0x185bc
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, -0x28(%rbp)
jmp 0x185e7
movslq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jbe 0x185d8
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x185e0
movslq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x18612
movq 0x2fc97(%rip), %rax     # 0x48290
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rsi
xorl %ecx, %ecx
movl %ecx, %edi
callq *%rax
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq 0x40(%rcx), %rsi
movl -0x28(%rbp), %edx
movl -0x1c(%rbp), %ecx
andl $0x10, %ecx
callq *%rax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x1868a
cmpl $0x0, -0x24(%rbp)
je 0x18660
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdx
movl -0x24(%rbp), %ecx
callq 0x8db0
cmpl $-0x1, -0x20(%rbp)
je 0x18671
movl -0x24(%rbp), %ecx
movl -0x20(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x18685
movl $0x0, -0x4(%rbp)
jmp 0x186b9
jmp 0x1857e
movl -0x1c(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x186a7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x18840
cmpl $0x0, %eax
je 0x186b0
movl $0x1, -0x4(%rbp)
jmp 0x186b9
jmp 0x186b2
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)