// File: stetre[P]moonvulkan/src/layers.c
// Function: EnumerateDeviceExtensionProperties
static int EnumerateDeviceExtensionProperties(lua_State *L)
    {
    int err;
    uint32_t count, remaining, tot, i;
    VkResult ec;
    VkExtensionProperties* properties; //[N];
    ud_t *ud;
    VkPhysicalDevice physical_device = checkphysical_device(L, 1, &ud);
    const char* layername = luaL_optstring(L, 2, NULL);
    int byname = optboolean(L, 3, 0);
    
#define CLEANUP zfreearrayVkExtensionProperties(L, properties, N, 1) 
    properties = znewarrayVkExtensionProperties(L, N, &err);
    if(err) { CLEANUP; lua_error(L); }
    lua_newtable(L);
    ec = ud->idt->EnumerateDeviceExtensionProperties(physical_device, layername, &remaining, NULL);
    if(ec) { CLEANUP; CheckError(L, ec); }
    if(remaining==0) { CLEANUP; return 1; }

    tot = 0;
    do {
        if(remaining > N)
            { count = N; remaining -= N; }
        else
            { count = remaining; remaining = 0; }

        ec = ud->idt->EnumerateDeviceExtensionProperties(physical_device, layername, &count, properties);
        if(ec && ec!=VK_INCOMPLETE) { CLEANUP; CheckError(L, ec); }
    
        if(byname)
            {
            for(i = 0; i < count; i++)
                {
                lua_pushstring(L, properties[i].extensionName);
                zpushVkExtensionProperties(L, &properties[i]);
                lua_rawset(L, -3);
                }
            }
        else
            {
            for(i = 0; i < count; i++)
                {
                zpushVkExtensionProperties(L, &properties[i]);
                lua_rawseti(L, -2, ++tot);
                }
            }

    } while (remaining > 0);

    CLEANUP;
#undef CLEANUP
    return 1;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x20(%rsp), %rdx
leaq 0x76f6d(%rip), %rcx     # 0xd0eac
callq 0x1a640
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x18900
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x198b0
movl %eax, 0xc(%rsp)
movq 0x48(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
leaq 0x44(%rsp), %r8
callq 0x19920
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x59fd1
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x48(%rsp), %rdi
callq 0x19ad0
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x3c(%rsp), %rdx
xorl %ecx, %ecx
callq *%rax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
je 0x5a05c
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x30(%rsp)
je 0x5a058
movq 0x48(%rsp), %rdi
movl 0x30(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5a255
jmp 0x5a05a
jmp 0x5a05c
cmpl $0x0, 0x3c(%rsp)
jne 0x5a094
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x54(%rsp)
jmp 0x5a255
movl $0x0, 0x38(%rsp)
cmpl $0x20, 0x3c(%rsp)
jbe 0x5a0b8
movl $0x20, 0x40(%rsp)
movl 0x3c(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x3c(%rsp)
jmp 0x5a0c8
movl 0x3c(%rsp), %eax
movl %eax, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rcx
leaq 0x40(%rsp), %rdx
callq *%rax
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
je 0x5a14f
cmpl $0x5, 0x30(%rsp)
je 0x5a14f
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x30(%rsp)
je 0x5a14b
movq 0x48(%rsp), %rdi
movl 0x30(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5a255
jmp 0x5a14d
jmp 0x5a14f
cmpl $0x0, 0xc(%rsp)
je 0x5a1c0
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0x5a1be
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x34(%rsp), %eax
imulq $0x104, %rax, %rax      # imm = 0x104
addq %rax, %rsi
callq 0x1a420
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x34(%rsp), %eax
imulq $0x104, %rax, %rax      # imm = 0x104
addq %rax, %rsi
callq 0x1a6d0
movq 0x48(%rsp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18860
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x5a15e
jmp 0x5a21c
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x40(%rsp), %eax
jae 0x5a21a
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x34(%rsp), %eax
imulq $0x104, %rax, %rax      # imm = 0x104
addq %rax, %rsi
callq 0x1a6d0
movq 0x48(%rsp), %rdi
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x5a1c8
jmp 0x5a21c
jmp 0x5a21e
cmpl $0x0, 0x3c(%rsp)
ja 0x5a09c
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x104, %edx            # imm = 0x104
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nop