// File: stetre[P]moonvulkan/src/instance.c
// Function: EnumeratePhysicalDeviceGroups
static int EnumeratePhysicalDeviceGroups(lua_State *L)
    {
    int err;
    ud_t *ud;
    uint32_t count, remaining, tot, i;
    VkResult ec;
    VkPhysicalDeviceGroupPropertiesKHR* props;
    VkInstance instance = checkinstance(L, 1, &ud);
    CheckInstancePfn(L, ud, EnumeratePhysicalDeviceGroups);
#define CLEANUP zfreearrayVkPhysicalDeviceGroupPropertiesKHR(L, props, N, 1)
    props = znewchainarrayVkPhysicalDeviceGroupPropertiesKHR(L, N, &err);
    if(err) { CLEANUP; return lua_error(L); }
    lua_newtable(L);
    ec = ud->idt->EnumeratePhysicalDeviceGroups(instance, &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->EnumeratePhysicalDeviceGroups(instance, &count, props);
        if(ec && ec != VK_INCOMPLETE) { CLEANUP; CheckError(L, ec); }

        for(i=0; i<count; i++)
            {
            zpushVkPhysicalDeviceGroupPropertiesKHR(L, &props[i], instance);
            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 0x28(%rsp), %rdx
leaq 0x771ba(%rip), %rcx     # 0xd06c9
callq 0x1a640
movq %rax, (%rsp)
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x1c0(%rax)
jne 0x59547
movq 0x38(%rsp), %rdi
leaq 0x88f96(%rip), %rsi     # 0xe24cd
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x44(%rsp)
jmp 0x59798
jmp 0x59549
movq 0x38(%rsp), %rdi
movl $0x20, %esi
leaq 0x34(%rsp), %rdx
callq 0x19bb0
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x5959b
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x59798
movq 0x38(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x1c0(%rax), %rax
movq (%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x59620
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpl $0x0, 0x14(%rsp)
je 0x5961c
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x59798
jmp 0x5961e
jmp 0x59620
cmpl $0x0, 0x20(%rsp)
jne 0x59653
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x44(%rsp)
jmp 0x59798
movl $0x0, 0x1c(%rsp)
cmpl $0x20, 0x20(%rsp)
jbe 0x59677
movl $0x20, 0x24(%rsp)
movl 0x20(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x20(%rsp)
jmp 0x59687
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x1c0(%rax), %rax
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
leaq 0x24(%rsp), %rsi
callq *%rax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x59706
cmpl $0x5, 0x14(%rsp)
je 0x59706
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpl $0x0, 0x14(%rsp)
je 0x59702
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x59798
jmp 0x59704
jmp 0x59706
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x24(%rsp), %eax
jae 0x59764
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %eax
imulq $0x120, %rax, %rax      # imm = 0x120
addq %rax, %rsi
movq (%rsp), %rdx
callq 0x18120
movq 0x38(%rsp), %rdi
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x5970e
jmp 0x59766
cmpl $0x0, 0x20(%rsp)
ja 0x5965b
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x120, %edx            # imm = 0x120
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)