// File: stetre[P]moonvulkan/src/cmd.c
// Function: CmdBlitImage
static int CmdBlitImage(lua_State *L)
    {
    int err;
    uint32_t count;
    ud_t *ud;
    VkCommandBuffer cb = checkcommand_buffer(L, 1, &ud);
    if(ud->ddt->CmdBlitImage2KHR && lua_type(L, 2)==LUA_TTABLE)
        {
        VkBlitImageInfo2KHR *info = zcheckVkBlitImageInfo2KHR(L, 2, &err);
#define CLEANUP zfreeVkBlitImageInfo2KHR(L, info, 1)
        if(err) { CLEANUP; return argerror(L, 2); }
        ud->ddt->CmdBlitImage2KHR(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);
        VkFilter filter = checkfilter(L, 7); /* before regions so there is no need to free them on error */
#define CLEANUP zfreearrayVkImageBlit(L, regions, count, 1)
        VkImageBlit* regions = zcheckarrayVkImageBlit(L, 6, &count, &err);
        if(err) { CLEANUP; return argerror(L, 6); }
        ud->ddt->CmdBlitImage(cb, srcImage, srcImageLayout, dstImage, dstImageLayout, count, regions, filter);
        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 0xb2caa(%rip), %rcx     # 0xcf909
callq 0x1a640
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x6c0(%rax)
je 0x1cd39
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x1cd39
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x64(%rsp), %rdx
callq 0x19b80
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x1cd04
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 0x1cea9
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x6c0(%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 0x1cea1
movq 0x68(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0xb2c4c(%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 0xb2c15(%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 $0x17, %esi
movl $0x7, %edx
callq 0x19d20
movl %eax, 0x28(%rsp)
movq 0x68(%rsp), %rdi
movl $0x6, %esi
leaq 0x60(%rsp), %rdx
leaq 0x64(%rsp), %rcx
callq 0x1a2e0
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x1ce3c
movq 0x68(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x60(%rsp), %ecx
movl $0x50, %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 0x1cea9
movq 0x58(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x378(%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), %r11
movl 0x28(%rsp), %r10d
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
callq *%rax
movq 0x68(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x60(%rsp), %ecx
movl $0x50, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)