// File: stetre[P]moonvulkan/src/device_memory.c
// Function: GetImageSparseMemoryRequirements2
static int GetImageSparseMemoryRequirements2(lua_State *L, VkImage image, ud_t *ud)
    {
    int err;
    uint32_t count, i;
    VkSparseImageMemoryRequirements2 *req=NULL;
    VkImageSparseMemoryRequirementsInfo2KHR* info=NULL;
    VkDevice device = ud->device;
#define CLEANUP do {                                            \
    zfreeVkImageSparseMemoryRequirementsInfo2KHR(L, info, 1);   \
    zfreearrayVkSparseImageMemoryRequirements2(L, req, count, 1);   \
} while(0)
    if(lua_istable(L, 2))
        {
        info = zcheckVkImageSparseMemoryRequirementsInfo2KHR(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        info = znewVkImageSparseMemoryRequirementsInfo2KHR(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        }
    info->image = image;
    lua_newtable(L);
    ud->ddt->GetImageSparseMemoryRequirements2(device, info, &count, NULL);
    if(count == 0) { CLEANUP; return 1; }
    req = znewchainarrayVkSparseImageMemoryRequirements2(L, count, &err);
    if(err) { CLEANUP; return lua_error(L); }
    ud->ddt->GetImageSparseMemoryRequirements2(device, info, &count, req);
    for(i = 0; i <count; i++)
        {
        zpushVkSparseImageMemoryRequirements2(L, &req[i]);
        lua_rawseti(L, -2, i+1);
        }
    CLEANUP;
#undef CLEANUP
    return 1;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x2c299
movq 0x48(%rsp), %rdi
movl $0x2, %esi
leaq 0x34(%rsp), %rdx
callq 0x187d0
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x2c297
jmp 0x2c22d
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x54(%rsp)
jmp 0x2c4a9
jmp 0x2c307
movq 0x48(%rsp), %rdi
movl $0x3b9d0452, %esi       # imm = 0x3B9D0452
movl $0x18, %edx
leaq 0x34(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x2c305
jmp 0x2c2c0
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x2c4a9
jmp 0x2c307
movq 0x40(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x4b8(%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq *%rax
cmpl $0x0, 0x30(%rsp)
jne 0x2c38e
jmp 0x2c34f
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x54(%rsp)
jmp 0x2c4a9
movq 0x48(%rsp), %rdi
movl 0x30(%rsp), %esi
leaq 0x34(%rsp), %rdx
callq 0x19d10
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x2c3f4
jmp 0x2c3af
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x2c4a9
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x4b8(%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
leaq 0x30(%rsp), %rdx
callq *%rax
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x2c46d
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %eax
shlq $0x6, %rax
addq %rax, %rsi
callq 0x1a1b0
movq 0x48(%rsp), %rdi
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2c422
jmp 0x2c46f
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)