// File: /workspace/github_cpp_makefile_star2_O1/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 0x4abe0(%rip), %rcx     # 0x90ef4
leaq 0x20(%rsp), %rdx
movl $0x1, %esi
callq 0x1a520
movq %rax, %rbp
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x188b0
movq %rax, %r12
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x197e0
movl %eax, 0x1c(%rsp)
leaq 0x34(%rsp), %r14
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x20, %ecx
movq %r14, %r8
callq 0x19840
movq %rax, %r13
cmpl $0x0, (%r14)
je 0x4639b
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r13, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
movq %rbx, %rdi
callq 0x199e0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0xc(%rsp), %rdx
movq %rbp, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq *0x18(%rax)
testl %eax, %eax
je 0x46401
movl %eax, %r14d
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r13, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
callq 0x18990
movq %rbx, %rdi
callq 0x199e0
movl %eax, %ebp
jmp 0x4653a
cmpl $0x0, 0xc(%rsp)
je 0x46517
movq $0x0, 0x10(%rsp)
movq %r12, 0x28(%rsp)
movl 0xc(%rsp), %eax
cmpl $0x21, %eax
jb 0x46430
movl $0x20, 0x8(%rsp)
addl $-0x20, %eax
jmp 0x46436
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x8(%rsp), %rdx
movq %r13, %rcx
callq *0x18(%rax)
testl %eax, %eax
je 0x46464
movl %eax, %r14d
cmpl $0x5, %eax
jne 0x463c7
movl 0x8(%rsp), %eax
cmpl $0x0, 0x1c(%rsp)
je 0x464b5
testl %eax, %eax
je 0x4650c
movq %r13, %r14
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a300
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a5b0
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18810
incq %r15
movl 0x8(%rsp), %eax
addq $0x104, %r14            # imm = 0x104
cmpq %rax, %r15
jb 0x4647d
jmp 0x4650c
testl %eax, %eax
je 0x4650c
movq %rbp, %r12
movl 0x10(%rsp), %ebp
movq %r13, %r14
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a5b0
leal (%r15,%rbp), %edx
incl %edx
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x19140
incq %r15
movl 0x8(%rsp), %eax
addq $0x104, %r14            # imm = 0x104
cmpq %rax, %r15
jb 0x464c6
movq 0x10(%rsp), %rax
addl %r15d, %eax
movq %rax, 0x10(%rsp)
movq %r12, %rbp
movq 0x28(%rsp), %r12
cmpl $0x0, 0xc(%rsp)
jne 0x4641a
movl $0x1, %ebp
movl $0x104, %edx            # imm = 0x104
movq %rbx, %rdi
movq %r13, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq