// File: stetre[P]moonvulkan/src/layers.c
// Function: EnumerateDeviceLayerProperties
static int EnumerateDeviceLayerProperties(lua_State *L) /* DEPRECATED */
    {
    int err;
    uint32_t count, remaining, tot, i;
    VkResult ec;
    ud_t *ud;
    VkLayerProperties* properties;//[N];
    VkPhysicalDevice physical_device = checkphysical_device(L, 1, &ud);
    int byname = optboolean(L, 2, 0);

#define CLEANUP zfreearrayVkLayerProperties(L, properties, N, 1) 
    properties = znewarrayVkLayerProperties(L, N, &err);
    if(err) { CLEANUP; lua_error(L); }
    lua_newtable(L);
    ec = ud->idt->EnumerateDeviceLayerProperties(physical_device, &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->EnumerateDeviceLayerProperties(physical_device, &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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movl $0x1, %esi
leaq 0x18(%rsp), %rdx
leaq 0x76c2d(%rip), %rcx     # 0xd0eac
callq 0x1a640
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x198b0
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
leaq 0x34(%rsp), %r8
callq 0x19920
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x5a2f6
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x38(%rsp), %rdi
callq 0x19ad0
movq 0x38(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x5a37e
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x20(%rsp)
je 0x5a37a
movq 0x38(%rsp), %rdi
movl 0x20(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x5a572
jmp 0x5a37c
jmp 0x5a37e
cmpl $0x0, 0x2c(%rsp)
jne 0x5a3b6
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x44(%rsp)
jmp 0x5a572
movl $0x0, 0x28(%rsp)
cmpl $0x20, 0x2c(%rsp)
jbe 0x5a3da
movl $0x20, 0x30(%rsp)
movl 0x2c(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x2c(%rsp)
jmp 0x5a3ea
movl 0x2c(%rsp), %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rsi
callq *%rax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x5a46c
cmpl $0x5, 0x20(%rsp)
je 0x5a46c
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x20(%rsp)
je 0x5a468
movq 0x38(%rsp), %rdi
movl 0x20(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x5a572
jmp 0x5a46a
jmp 0x5a46c
cmpl $0x0, 0x4(%rsp)
je 0x5a4dd
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x5a4db
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x24(%rsp), %eax
imulq $0x208, %rax, %rax      # imm = 0x208
addq %rax, %rsi
callq 0x1a420
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x24(%rsp), %eax
imulq $0x208, %rax, %rax      # imm = 0x208
addq %rax, %rsi
callq 0x18e90
movq 0x38(%rsp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18860
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x5a47b
jmp 0x5a539
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x5a537
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x24(%rsp), %eax
imulq $0x208, %rax, %rax      # imm = 0x208
addq %rax, %rsi
callq 0x18e90
movq 0x38(%rsp), %rdi
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x5a4e5
jmp 0x5a539
jmp 0x5a53b
cmpl $0x0, 0x2c(%rsp)
ja 0x5a3be
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x208, %edx            # imm = 0x208
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)