// File: /workspace/github_c_makefile_star2_O3/msteveb[P]autosetup/./jimsh0.c
// Function: aio_cmd_copy
static int aio_cmd_copy(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    AioFile *af = Jim_CmdPrivData(interp);
    jim_wide count = 0;
    jim_wide maxlen = JIM_WIDE_MAX;
    int ok = 1;
    Jim_Obj *objv[4];

    if (argc == 2) {
        if (Jim_GetWide(interp, argv[1], &maxlen) != JIM_OK) {
            return JIM_ERR;
        }
    }

    objv[0] = argv[0];
    objv[1] = Jim_NewStringObj(interp, "flush", -1);
    if (Jim_EvalObjVector(interp, 2, objv) != JIM_OK) {
        Jim_SetResultFormatted(interp, "Not a filehandle: \"%#s\"", argv[0]);
        return JIM_ERR;
    }


    objv[0] = argv[0];
    objv[1] = Jim_NewStringObj(interp, "puts", -1);
    objv[2] = Jim_NewStringObj(interp, "-nonewline", -1);
    Jim_IncrRefCount(objv[1]);
    Jim_IncrRefCount(objv[2]);

    while (count < maxlen) {
        jim_wide len = maxlen - count;
        if (len > af->rbuf_len) {
            len = af->rbuf_len;
        }
        if (aio_read_len(interp, af, 0, len) != JIM_OK) {
            ok = 0;
            break;
        }
        objv[3] = aio_read_consume(interp, af, len);
        count += Jim_Length(objv[3]);
        if (Jim_EvalObjVector(interp, 4, objv) != JIM_OK) {
            ok = 0;
            break;
        }
        if (aio_eof(af)) {
            break;
        }
        if (count >= 16384 && af->rbuf_len < 65536) {

            af->rbuf_len = 65536;
            af->rbuf = Jim_Realloc(af->rbuf, af->rbuf_len);
        }
    }

    Jim_DecrRefCount(interp, objv[1]);
    Jim_DecrRefCount(interp, objv[2]);

    if (!ok) {
        return JIM_ERR;
    }

    Jim_SetResultInt(interp, count);

    return JIM_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rdi, %rbx
movq 0x1b8(%rdi), %r14
cmpl $0x2, %esi
jne 0x13aa2
movq 0x8(%r15), %r13
leaq 0x21878(%rip), %rax     # 0x352f0
cmpq %rax, 0x8(%r13)
je 0x13a9c
movl $0x1, %r12d
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0xd6c3
testl %eax, %eax
jne 0x13c8e
movq 0x18(%r13), %rax
jmp 0x13aac
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x30(%rbp)
movq (%r15), %rax
leaq -0x50(%rbp), %r12
movq %rax, (%r12)
leaq 0x17933(%rip), %rsi     # 0x2b3f5
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, 0x8(%r12)
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x10431
movq (%r15), %rdx
testl %eax, %eax
je 0x13b07
leaq 0x16ed1(%rip), %rsi     # 0x2a9c3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6923
movl $0x1, %r12d
jmp 0x13c8e
movq %rdx, -0x50(%rbp)
leaq 0x178c6(%rip), %rsi     # 0x2b3d8
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, -0x48(%rbp)
leaq 0x188bf(%rip), %rsi     # 0x2c3e9
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7508
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rsi
incl 0x10(%rsi)
incl 0x10(%rax)
movq -0x30(%rbp), %r12
xorl %r13d, %r13d
testq %r12, %r12
jle 0x13c0c
subq %r13, %r12
movq 0x48(%r14), %rax
cmpq %rax, %r12
cmovaeq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x14696
movb $0x1, %r15b
testl %eax, %eax
jne 0x13c06
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x14827
movq %rax, %r12
movq %rax, -0x38(%rbp)
cmpq $0x0, (%rax)
jne 0x13ba4
movq 0x8(%r12), %rax
movq %r12, %rdi
callq *0x18(%rax)
movslq 0x14(%r12), %rax
addq %rax, %r13
movq %rbx, %rdi
movl $0x4, %esi
leaq -0x50(%rbp), %rdx
callq 0x10431
testl %eax, %eax
jne 0x13c06
testb $0x4, 0xc(%r14)
jne 0x13c03
cmpq $0x4000, %r13           # imm = 0x4000
jl 0x13bf6
cmpq $0xffff, 0x48(%r14)     # imm = 0xFFFF
ja 0x13bf6
movq $0x10000, 0x48(%r14)    # imm = 0x10000
movq 0x40(%r14), %rdi
movl $0x10000, %esi          # imm = 0x10000
callq *0x23696(%rip)          # 0x37288
movq %rax, 0x40(%r14)
movq -0x30(%rbp), %r12
cmpq %r12, %r13
jl 0x13b55
xorl %r15d, %r15d
movq -0x48(%rbp), %rsi
jmp 0x13c0f
xorl %r15d, %r15d
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x13c25
movq %rbx, %rdi
callq 0x758c
movq -0x40(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x13c3f
movq %rbx, %rdi
callq 0x758c
movl $0x1, %r12d
testb %r15b, %r15b
jne 0x13c8e
movq %rbx, %rdi
callq 0xae38
movq %rax, %r14
leaq 0x21694(%rip), %rax     # 0x352f0
movq %rax, 0x8(%r14)
movq $0x0, (%r14)
movq %r13, 0x18(%r14)
incl 0x10(%r14)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x13c88
movq %rbx, %rdi
callq 0x758c
movq %r14, (%rbx)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq