// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %rdx, %r15
movq %rdi, %rbx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x38(%rbp)
movq 0x1b8(%rdi), %r14
cmpl $0x2, %esi
jne 0x13f0b
movq 0x8(%r15), %r12
leaq 0x2240c(%rip), %rax     # 0x362e0
cmpq %rax, 0x8(%r12)
je 0x13ef3
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0xd6d7
testl %eax, %eax
je 0x13ef3
xorl %ecx, %ecx
jmp 0x13efe
movq 0x18(%r12), %rax
movq %rax, -0x38(%rbp)
movb $0x1, %cl
movl $0x1, %eax
testb %cl, %cl
je 0x140f3
movq (%r15), %rax
leaq -0x60(%rbp), %r12
movq %rax, (%r12)
leaq 0x18533(%rip), %rsi     # 0x2c450
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7516
movq %rax, 0x8(%r12)
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x10562
movq (%r15), %rdx
testl %eax, %eax
je 0x13f61
leaq 0x17ace(%rip), %rsi     # 0x2ba1b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x692d
movl $0x1, %eax
jmp 0x140f3
leaq -0x60(%rbp), %r15
movq %rdx, (%r15)
leaq 0x184c4(%rip), %rsi     # 0x2c433
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7516
movq %rax, 0x8(%r15)
leaq 0x194c0(%rip), %rsi     # 0x2d447
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x7516
movq %rax, 0x10(%r15)
movq 0x8(%r15), %rcx
incl 0x10(%rcx)
incl 0x10(%rax)
movl $0x1, -0x2c(%rbp)
xorl %r15d, %r15d
movq -0x38(%rbp), %rax
subq %r15, %rax
jle 0x14072
movq 0x48(%r14), %r12
cmpq %r12, %rax
cmovbq %rax, %r12
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x14ad8
testl %eax, %eax
jne 0x14021
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x14cbc
movq %rax, %r12
movq %rax, -0x48(%rbp)
cmpq $0x0, (%rax)
jne 0x14001
movq 0x8(%r12), %rax
movq %r12, %rdi
callq *0x18(%rax)
movslq 0x14(%r12), %rax
addq %rax, %r15
movq %rbx, %rdi
movl $0x4, %esi
leaq -0x60(%rbp), %rdx
callq 0x10562
xorl %r13d, %r13d
testl %eax, %eax
je 0x14033
movl $0x0, -0x2c(%rbp)
testb %r13b, %r13b
jne 0x13fac
jmp 0x14072
testb $0x4, 0xc(%r14)
jne 0x1406d
movb $0x1, %r13b
cmpq $0x4000, %r15           # imm = 0x4000
jl 0x14028
cmpq $0xffff, 0x48(%r14)     # imm = 0xFFFF
ja 0x14028
movq $0x10000, 0x48(%r14)    # imm = 0x10000
movq 0x40(%r14), %rdi
movl $0x10000, %esi          # imm = 0x10000
callq *0x24221(%rip)          # 0x38288
movq %rax, 0x40(%r14)
jmp 0x14028
xorl %r13d, %r13d
jmp 0x14028
movq -0x58(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1408c
movq %rbx, %rdi
callq 0x759a
movq -0x50(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x140a6
movq %rbx, %rdi
callq 0x759a
cmpl $0x0, -0x2c(%rbp)
je 0x13f57
movq %rbx, %rdi
callq 0xae58
movq %rax, %r14
leaq 0x2221e(%rip), %rax     # 0x362e0
movq %rax, 0x8(%r14)
movq $0x0, (%r14)
movq %r15, 0x18(%r14)
incl 0x10(%r14)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x140ee
movq %rbx, %rdi
callq 0x759a
movq %r14, (%rbx)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq