// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdi, %rbx
movq 0x1b8(%rdi), %r15
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x30(%rbp)
pushq $0x1
popq %r13
cmpl $0x2, %esi
jne 0x1239f
movq 0x8(%r14), %rsi
leaq -0x30(%rbp), %rdx
movq %rbx, %rdi
callq 0xc979
testl %eax, %eax
jne 0x12543
movq (%r14), %rax
leaq -0x60(%rbp), %r12
movq %rax, (%r12)
leaq 0x15094(%rip), %rsi     # 0x27445
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x7363
movq %rax, 0x8(%r12)
pushq $0x2
popq %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0xf32e
movq (%r14), %rdx
testl %eax, %eax
je 0x123ec
leaq 0x14636(%rip), %rsi     # 0x26a13
movq %rbx, %rdi
xorl %eax, %eax
callq 0x68a7
jmp 0x12543
movq %rdx, (%r12)
leaq 0x15031(%rip), %rsi     # 0x27428
pushq $-0x1
popq %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0x7363
movq %rax, 0x8(%r12)
leaq 0x16027(%rip), %rsi     # 0x28439
movq %rbx, %rdi
movl %r14d, %edx
callq 0x7363
movq %rax, 0x10(%r12)
movq 0x8(%r12), %rcx
incl 0x10(%rcx)
incl 0x10(%rax)
xorl %r12d, %r12d
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
subq %r12, %rax
jle 0x124d3
movq 0x48(%r15), %r14
cmpq %r14, %rax
cmovbq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r14d, %ecx
callq 0x12d8b
movb $0x1, %r13b
testl %eax, %eax
jne 0x124d6
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x12ef6
movq %rax, -0x48(%rbp)
movq %rax, %rdi
callq 0xa61a
cltq
addq %rax, %r12
movq %rbx, %rdi
pushq $0x4
popq %rsi
leaq -0x60(%rbp), %rdx
callq 0xf32e
testl %eax, %eax
jne 0x124d6
testb $0x4, 0xc(%r15)
jne 0x124d3
cmpq $0x4000, %r12           # imm = 0x4000
jl 0x12438
cmpq $0xffff, 0x48(%r15)     # imm = 0xFFFF
ja 0x12438
movq $0x10000, 0x48(%r15)    # imm = 0x10000
movq 0x40(%r15), %rdi
movl $0x10000, %esi          # imm = 0x10000
callq *0x20dbe(%rip)          # 0x33288
movq %rax, 0x40(%r15)
jmp 0x12438
xorl %r13d, %r13d
movq -0x58(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x124f0
movq %rbx, %rdi
callq 0x73bf
movq -0x50(%rbp), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1250a
movq %rbx, %rdi
callq 0x73bf
testb %r13b, %r13b
pushq $0x1
popq %r13
jne 0x12543
movq %rbx, %rdi
movq %r12, %rsi
callq 0x8212
movq %rax, %r14
incl 0x10(%rax)
movq (%rbx), %rsi
movl 0x10(%rsi), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsi)
cmpl $0x1, %eax
jg 0x1253d
movq %rbx, %rdi
callq 0x73bf
movq %r14, (%rbx)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq