// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movl %edx, -0x2c(%rbp)
movq %rsi, %r15
movq %rdi, -0x40(%rbp)
cmpq $0x0, 0x30(%rsi)
jne 0x14b22
movq -0x40(%rbp), %rdi
callq 0xae58
leaq 0x2378c(%rip), %rcx     # 0x38298
movq %rcx, (%rax)
movl $0x0, 0x14(%rax)
movq $0x0, 0x8(%rax)
movq %rax, 0x30(%r15)
testl %ebx, %ebx
js 0x14b44
movq 0x30(%r15), %r14
cmpq $0x0, (%r14)
jne 0x14b3a
movq 0x8(%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
subl 0x14(%r14), %ebx
jle 0x14c42
movl -0x2c(%rbp), %eax
movl %eax, %r14d
andl $0x10, %r14d
andl $0x20, %eax
movq $0x0, -0x38(%rbp)
cmpl $0x1, %eax
movl $0x0, %eax
adcl $0x1, %eax
movl %eax, -0x44(%rbp)
testl %ebx, %ebx
je 0x14c4a
testb $0x4, 0xc(%r15)
jne 0x14c4a
cmpl $-0x1, %ebx
je 0x14b8f
movslq %ebx, %rax
movq 0x48(%r15), %r13
cmpq %rax, %r13
cmovael %ebx, %r13d
jmp 0x14b93
movl 0x48(%r15), %r13d
cmpq $0x0, 0x40(%r15)
jne 0x14baa
movq 0x48(%r15), %rsi
xorl %edi, %edi
callq *0x236e2(%rip)          # 0x38288
movq %rax, 0x40(%r15)
movq 0x28(%r15), %rax
movq 0x40(%r15), %rsi
movq %r15, %rdi
movl %r13d, %edx
movl %r14d, %ecx
callq *0x8(%rax)
testl %eax, %eax
jle 0x14bf5
movl %eax, %r13d
movq 0x30(%r15), %rsi
movq 0x40(%r15), %rdx
movq -0x40(%rbp), %rdi
movl %eax, %ecx
callq 0x8653
movl %ebx, %eax
subl %r13d, %eax
cmpl $-0x1, %ebx
cmovnel %eax, %ebx
testb $0x20, -0x2c(%rbp)
movl $0x0, %eax
cmovnel %eax, %r12d
movl -0x44(%rbp), %eax
jmp 0x14c2b
movl $0x1, %eax
testb $0x20, -0x2c(%rbp)
jne 0x14c25
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x14d4a
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movl $0x1, %eax
cmovnel %eax, %r12d
leal 0x1(,%rcx,2), %eax
jmp 0x14c2b
movl $0x1, %r12d
cmpl $0x2, %eax
je 0x14b67
cmpl $0x3, %eax
je 0x14c4a
movl %r12d, %eax
movq %rax, -0x38(%rbp)
jmp 0x14c4a
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq