// File: stetre[P]moonvulkan/src/cmd.c
// Function: CmdCopyBufferToImage
static int CmdCopyBufferToImage(lua_State *L)
    {
    int err;
    uint32_t count;
    ud_t *ud;
    VkCommandBuffer cb = checkcommand_buffer(L, 1, &ud);
    if(ud->ddt->CmdCopyBufferToImage2KHR && lua_type(L, 2)==LUA_TTABLE)
        {
        VkCopyBufferToImageInfo2KHR *info = zcheckVkCopyBufferToImageInfo2KHR(L, 2, &err);
#define CLEANUP zfreeVkCopyBufferToImageInfo2KHR(L, info, 1)
        if(err) { CLEANUP; return argerror(L, 2); }
        ud->ddt->CmdCopyBufferToImage2KHR(cb, info);
        CLEANUP;
#undef CLEANUP
        }
    else
        {
        VkBuffer srcBuffer = checkbuffer(L, 2, NULL);
        VkImage dstImage = checkimage(L, 3, NULL);
        VkImageLayout dstImageLayout = checkimagelayout(L, 4);
#define CLEANUP zfreearrayVkBufferImageCopy(L, regions, count, 1)
        VkBufferImageCopy* regions = zcheckarrayVkBufferImageCopy(L, 5, &count, &err);
        if(err) { CLEANUP; return argerror(L, 5); }
        ud->ddt->CmdCopyBufferToImage(cb, srcBuffer, dstImage, dstImageLayout, count, regions);
        CLEANUP;
#undef CLEANUP
        }
    return 0;
    }

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
leaq 0x48(%rsp), %rdx
leaq 0xb2a2a(%rip), %rcx     # 0xcf909
callq 0x1a640
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x6b0(%rax)
je 0x1cfb9
movq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x1cfb9
movq 0x58(%rsp), %rdi
movl $0x2, %esi
leaq 0x54(%rsp), %rdx
callq 0x18940
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x1cf84
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x64(%rsp)
jmp 0x1d0e6
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x6b0(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq *%rax
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
jmp 0x1d0de
movq 0x58(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb2032(%rip), %rcx     # 0xcf000
callq 0x1a640
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb29ad(%rip), %rcx     # 0xcf99a
callq 0x1a640
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rdi
movl $0xa, %esi
movl $0x4, %edx
callq 0x19d20
movl %eax, 0x24(%rsp)
movq 0x58(%rsp), %rdi
movl $0x5, %esi
leaq 0x50(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x19160
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x1d08c
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x5, %esi
callq 0x18460
movl %eax, 0x64(%rsp)
jmp 0x1d0e6
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x380(%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl 0x24(%rsp), %ecx
movl 0x50(%rsp), %r8d
movq 0x18(%rsp), %r9
callq *%rax
movq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %ecx
movl $0x38, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nop