// File: stetre[P]moonvulkan/src/cmd.c
// Function: CmdCopyImage
static int CmdCopyImage(lua_State *L)
    {
    int err;
    uint32_t count;
    ud_t *ud;
    VkCommandBuffer cb = checkcommand_buffer(L, 1, &ud);
    if(ud->ddt->CmdCopyImage2KHR && lua_type(L, 2)==LUA_TTABLE)
        {
        VkCopyImageInfo2KHR *info = zcheckVkCopyImageInfo2KHR(L, 2, &err);
#define CLEANUP zfreeVkCopyImageInfo2KHR(L, info, 1)
        if(err) { CLEANUP; return argerror(L, 2); }
        ud->ddt->CmdCopyImage2KHR(cb, info);
        CLEANUP;
#undef CLEANUP
        }
    else
        {
        VkImage srcImage = checkimage(L, 2, NULL);
        VkImageLayout srcImageLayout = checkimagelayout(L, 3);
        VkImage dstImage = checkimage(L, 4, NULL);
        VkImageLayout dstImageLayout = checkimagelayout(L, 5);
#define CLEANUP zfreearrayVkImageCopy(L, regions, count, 1)
        VkImageCopy* regions = zcheckarrayVkImageCopy(L, 6, &count, &err);
        if(err) { CLEANUP; return argerror(L, 6); }
        ud->ddt->CmdCopyImage(cb, srcImage, srcImageLayout, dstImage, dstImageLayout, count, regions);
        CLEANUP;
#undef CLEANUP
        }
    return 0;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1, %esi
leaq 0x58(%rsp), %rdx
leaq 0xb2efa(%rip), %rcx     # 0xcf909
callq 0x1a640
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x6a8(%rax)
je 0x1cae9
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x1cae9
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x64(%rsp), %rdx
callq 0x197a0
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x1cab4
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x18(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x1cc37
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x6a8(%rax), %rax
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq *%rax
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
jmp 0x1cc2f
movq 0x68(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb2e9c(%rip), %rcx     # 0xcf99a
callq 0x1a640
movq %rax, 0x40(%rsp)
movq 0x68(%rsp), %rdi
movl $0xa, %esi
movl $0x3, %edx
callq 0x19d20
movl %eax, 0x3c(%rsp)
movq 0x68(%rsp), %rdi
movl $0x4, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb2e65(%rip), %rcx     # 0xcf99a
callq 0x1a640
movq %rax, 0x30(%rsp)
movq 0x68(%rsp), %rdi
movl $0xa, %esi
movl $0x5, %edx
callq 0x19d20
movl %eax, 0x2c(%rsp)
movq 0x68(%rsp), %rdi
movl $0x6, %esi
leaq 0x60(%rsp), %rdx
leaq 0x64(%rsp), %rcx
callq 0x188c0
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x1cbd4
movq 0x68(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x60(%rsp), %ecx
movl $0x44, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movl $0x6, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x1cc37
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x370(%rax), %rax
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x3c(%rsp), %edx
movq 0x30(%rsp), %rcx
movl 0x2c(%rsp), %r8d
movl 0x60(%rsp), %r9d
movq 0x20(%rsp), %r10
movq %r10, (%rsp)
callq *%rax
movq 0x68(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x60(%rsp), %ecx
movl $0x44, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq