// File: stetre[P]moonvulkan/src/device_memory.c
// Function: GetDeviceImageSparseMemoryRequirements
static int GetDeviceImageSparseMemoryRequirements(lua_State *L)
    {
    int err;
    uint32_t count, i;
    ud_t *ud;
    VkDeviceImageMemoryRequirementsKHR *info = NULL;
    VkSparseImageMemoryRequirements2 *req = NULL;
    VkDevice device = checkdevice(L, 1, &ud);
    CheckDevicePfn(L, ud, GetDeviceImageSparseMemoryRequirementsKHR);
#define CLEANUP do {                                                \
    zfreeVkDeviceImageMemoryRequirementsKHR(L, info, 1);            \
    zfreearrayVkSparseImageMemoryRequirements2(L, req, count, 1);   \
} while(0)
    info = zcheckVkDeviceImageMemoryRequirementsKHR(L, 2, &err);
    if(err) { CLEANUP; return argerror(L, 2); }
    lua_newtable(L);
    ud->ddt->GetDeviceImageSparseMemoryRequirementsKHR(device, info, &count, NULL);
    if(count == 0) { CLEANUP; return 1; }
    req = znewchainarrayVkSparseImageMemoryRequirements2(L, count, &err);
    if(err) { CLEANUP; return lua_error(L); }
    ud->ddt->GetDeviceImageSparseMemoryRequirementsKHR(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 $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x38(%rsp), %rdi
movl $0x1, %esi
leaq 0x20(%rsp), %rdx
leaq 0xa3d4a(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x878(%rax)
jne 0x2b32a
movq 0x38(%rsp), %rdi
leaq 0xa60d9(%rip), %rsi     # 0xd13f3
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x44(%rsp)
jmp 0x2b54a
jmp 0x2b32c
movq 0x38(%rsp), %rdi
movl $0x2, %esi
leaq 0x34(%rsp), %rdx
callq 0x18620
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x2b3b6
jmp 0x2b34e
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq (%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x44(%rsp)
jmp 0x2b54a
movq 0x38(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x878(%rax), %rax
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq *%rax
cmpl $0x0, 0x30(%rsp)
jne 0x2b42f
jmp 0x2b3f0
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x44(%rsp)
jmp 0x2b54a
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %esi
leaq 0x34(%rsp), %rdx
callq 0x19d10
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x2b495
jmp 0x2b450
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x2b54a
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x878(%rax), %rax
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rcx
leaq 0x30(%rsp), %rdx
callq *%rax
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x2b50e
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x2c(%rsp), %eax
shlq $0x6, %rax
addq %rax, %rsi
callq 0x1a1b0
movq 0x38(%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 0x2b4c3
jmp 0x2b510
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x30(%rsp), %ecx
movl $0x40, %edx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)