// File: /workspace/github_cpp_makefile_star2_O3/stetre[P]moonvulkan/src/layers.c
// Function: EnumerateInstanceLayerProperties
static int EnumerateInstanceLayerProperties(lua_State *L)
    {
    int err;
    uint32_t count, remaining, tot, i;
    VkResult ec;
    VkLayerProperties* properties;//[N];
    int byname = optboolean(L, 1, 0);

#define CLEANUP zfreearrayVkLayerProperties(L, properties, N, 1) 
    properties = znewarrayVkLayerProperties (L, N, &err);
    if(err) { CLEANUP; lua_error(L); }
    lua_newtable(L);
    ec = vk.EnumerateInstanceLayerProperties(&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 = vk.EnumerateInstanceLayerProperties(&count, properties);
        if(ec && ec!=VK_INCOMPLETE) { CLEANUP; CheckError(L, ec); }
        
        if(byname)
            {
            for(i = 0; i < count; i++)
                {
                lua_pushstring(L, properties[i].layerName);
                zpushVkLayerProperties(L, &properties[i]);
                lua_rawset(L, -3);
                }
            }
        else
            {
            for(i = 0; i < count; i++)
                {
                zpushVkLayerProperties(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 $0x18, %rsp
movq %rdi, %rbx
movl $0x1, %esi
xorl %edx, %edx
callq 0x197b0
movl %eax, %ebp
leaq 0x14(%rsp), %r15
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x20, %ecx
movq %r15, %r8
callq 0x19810
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x45ea3
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
movq %r14, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
callq 0x199a0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x7a12a(%rip), %r13     # 0xbffe0
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq *0x8(%r13)
testl %eax, %eax
je 0x45f02
movl %eax, %r15d
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
movq %r14, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199a0
movl %eax, %ebp
jmp 0x4601f
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x45ffc
movl $0x0, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
movl %eax, %ecx
subl $0x20, %ecx
movl $0x20, %edx
cmovael %edx, %eax
movl $0x0, %edx
cmovbl %edx, %ecx
movl %eax, 0x4(%rsp)
movl %ecx, 0x8(%rsp)
leaq 0x4(%rsp), %rdi
movq %r14, %rsi
callq *0x8(%r13)
testl %eax, %eax
je 0x45f53
movl %eax, %r12d
cmpl $0x5, %eax
jne 0x46030
movl 0x4(%rsp), %eax
testl %ebp, %ebp
je 0x45fa1
testl %eax, %eax
je 0x45ff0
movq %r14, %r12
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1a2c0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x18de0
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18800
incq %r15
movl 0x4(%rsp), %eax
addq $0x208, %r12            # imm = 0x208
cmpq %rax, %r15
jb 0x45f69
jmp 0x45ff0
testl %eax, %eax
je 0x45ff0
movq %r13, %rbp
movl 0xc(%rsp), %r13d
movq %r14, %r12
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x18de0
leal (%r15,%r13), %edx
incl %edx
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x19130
incq %r15
movl 0x4(%rsp), %eax
addq $0x208, %r12            # imm = 0x208
cmpq %rax, %r15
jb 0x45fb3
addl %r15d, 0xc(%rsp)
movq %rbp, %r13
movl 0x10(%rsp), %ebp
movl 0x8(%rsp), %eax
testl %eax, %eax
jne 0x45f1a
movl $0x1, %ebp
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
movq %r14, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
movq %r14, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
movq %rbx, %rdi
xorl %esi, %esi
movl %r12d, %edx
jmp 0x45eee