// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x3ba7d(%rip), %rcx     # 0x7eef4
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %rdx
callq 0x1a500
movq %rax, %r15
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x188a0
movq %rax, %r13
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x197c0
movl %eax, 0xc(%rsp)
pushq $-0x1
popq %rsi
pushq $0x20
popq %rcx
leaq 0x34(%rsp), %r14
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r14, %r8
callq 0x19820
movq %rax, %r12
cmpl $0x0, (%r14)
je 0x434f0
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r12, %rsi
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
callq 0x199c0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %rsp, %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq *0x18(%rax)
testl %eax, %eax
je 0x4354e
movl %eax, %ebp
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r12, %rsi
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199c0
movl %eax, %ebp
jmp 0x43684
movl (%rsp), %eax
testl %eax, %eax
je 0x43668
movq %r13, 0x28(%rsp)
pushq $-0x2
popq %rbp
pushq $-0x3
popq %r13
movl $0x0, 0x8(%rsp)
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %eax, %ecx
subl $0x20, %ecx
pushq $0x20
popq %rdx
cmovael %edx, %eax
movl $0x0, %edx
cmovbl %edx, %ecx
movl %eax, 0x4(%rsp)
movl %ecx, (%rsp)
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %r15, %rdi
movq 0x28(%rsp), %rsi
leaq 0x4(%rsp), %rdx
movq %r12, %rcx
callq *0x18(%rax)
testl %eax, %eax
je 0x435bd
movl %eax, %r14d
cmpl $0x5, %eax
jne 0x43695
cmpl $0x0, 0xc(%rsp)
je 0x43600
movq %r12, %r14
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
cmpq %rax, %r15
jae 0x43645
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a2e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a590
movq %rbx, %rdi
movl %r13d, %esi
callq 0x18800
incq %r15
addq $0x104, %r14            # imm = 0x104
jmp 0x435ca
movq %r12, %r14
movl 0x8(%rsp), %r12d
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
cmpq %rax, %r15
jae 0x4363b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a590
leal (%r12,%r15), %edx
incl %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x19120
incq %r15
addq $0x104, %r14            # imm = 0x104
jmp 0x4360b
addl %r15d, 0x8(%rsp)
movq 0x18(%rsp), %r12
movl (%rsp), %eax
testl %eax, %eax
movq 0x20(%rsp), %r15
jne 0x43577
pushq $0x20
popq %rcx
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r12, %rsi
pushq $0x1
popq %rbp
jmp 0x43679
pushq $0x20
popq %rcx
pushq $0x1
popq %rbp
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x18d30
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r12, %rsi
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
jmp 0x4353a