// File: stetre[P]moonvulkan/src/physical_device.c
// Function: EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters
static int EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(lua_State *L)
    {
    int err;
    ud_t *ud;
    uint32_t count, remaining, tot, i;
    VkResult ec;
    VkPerformanceCounterKHR *counters = NULL;
    VkPerformanceCounterDescriptionKHR *descriptions = NULL;
    VkPhysicalDevice physical_device = checkphysical_device(L, 1, &ud);
    uint32_t queue_family_index = luaL_checkinteger(L, 2);
    CheckInstancePfn(L, ud, EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR);
#define CLEANUP do { \
    if(counters) zfreearrayVkPerformanceCounterKHR(L, counters, N, 1);                          \
    if(descriptions) zfreearrayVkPerformanceCounterDescriptionKHR(L, descriptions, N, 1);       \
} while(0)
    counters = znewchainarrayVkPerformanceCounterKHR(L, N, &err);
    if(err) { CLEANUP; return lua_error(L); }
    descriptions = znewchainarrayVkPerformanceCounterDescriptionKHR(L, N, &err);
    if(err) { CLEANUP; return lua_error(L); }
    lua_newtable(L);
    lua_newtable(L);
    ec = ud->idt->EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(physical_device,
            queue_family_index, &remaining, NULL, NULL);
    if(ec) { CLEANUP; CheckError(L, ec); }
    if(remaining == 0) { CLEANUP; return 2; }
    tot = 0;
    do {
        if(remaining > N)
            { count = N; remaining -= N; }
        else
            { count = remaining; remaining = 0; }
        ec = ud->idt->EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(physical_device,
            queue_family_index, &remaining, counters, descriptions);
        if(ec && ec != VK_INCOMPLETE) { CLEANUP; CheckError(L, ec); }
        for(i=0; i<count; i++)
            {
            zpushVkPerformanceCounterKHR(L, &counters[i]);
            lua_rawseti(L, -3, ++tot);
            zpushVkPerformanceCounterDescriptionKHR(L, &descriptions[i]);
            lua_rawseti(L, -2, ++tot);
            }
    } while(remaining > 0);
    CLEANUP;
#undef CLEANUP
    return 2;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x38(%rsp), %rdx
leaq 0x7425b(%rip), %rcx     # 0xd0eac
callq 0x1a640
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x19190
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x1d8(%rax)
jne 0x5cc9d
movq 0x48(%rsp), %rdi
leaq 0x85e07(%rip), %rsi     # 0xe2a94
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x54(%rsp)
jmp 0x5d0de
jmp 0x5cc9f
movq 0x48(%rsp), %rdi
movl $0x20, %esi
leaq 0x44(%rsp), %rdx
callq 0x19540
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x5cd24
jmp 0x5ccc1
cmpq $0x0, 0x18(%rsp)
je 0x5cce8
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5cd0f
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5cd11
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5d0de
movq 0x48(%rsp), %rdi
movl $0x20, %esi
leaq 0x44(%rsp), %rdx
callq 0x19f70
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x5cda9
jmp 0x5cd46
cmpq $0x0, 0x18(%rsp)
je 0x5cd6d
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5cd94
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5cd96
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5d0de
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x1d8(%rax), %rax
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
movl %ecx, %r8d
movq %r8, %rcx
callq *%rax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x5ce7e
jmp 0x5cdfe
cmpq $0x0, 0x18(%rsp)
je 0x5ce25
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5ce4c
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5ce4e
jmp 0x5ce50
cmpl $0x0, 0x24(%rsp)
je 0x5ce7a
movq 0x48(%rsp), %rdi
movl 0x24(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5d0de
jmp 0x5ce7c
jmp 0x5ce7e
cmpl $0x0, 0x30(%rsp)
jne 0x5cee4
jmp 0x5ce87
cmpq $0x0, 0x18(%rsp)
je 0x5ceae
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5ced5
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5ced7
movl $0x2, 0x54(%rsp)
jmp 0x5d0de
movl $0x0, 0x2c(%rsp)
cmpl $0x20, 0x30(%rsp)
jbe 0x5cf08
movl $0x20, 0x34(%rsp)
movl 0x30(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x30(%rsp)
jmp 0x5cf18
movl 0x30(%rsp), %eax
movl %eax, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x1d8(%rax), %rax
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r8
leaq 0x30(%rsp), %rdx
callq *%rax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x5cfde
cmpl $0x5, 0x24(%rsp)
je 0x5cfde
jmp 0x5cf5e
cmpq $0x0, 0x18(%rsp)
je 0x5cf85
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5cfac
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5cfae
jmp 0x5cfb0
cmpl $0x0, 0x24(%rsp)
je 0x5cfda
movq 0x48(%rsp), %rdi
movl 0x24(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x5d0de
jmp 0x5cfdc
jmp 0x5cfde
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x34(%rsp), %eax
jae 0x5d077
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x28(%rsp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rsi
callq 0x19970
movq 0x48(%rsp), %rdi
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x191e0
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl 0x28(%rsp), %eax
imulq $0x318, %rax, %rax      # imm = 0x318
addq %rax, %rsi
callq 0x1a000
movq 0x48(%rsp), %rdi
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x5cfe6
jmp 0x5d079
cmpl $0x0, 0x30(%rsp)
ja 0x5ceec
jmp 0x5d086
cmpq $0x0, 0x18(%rsp)
je 0x5d0ad
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x30, %edx
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
cmpq $0x0, 0x10(%rsp)
je 0x5d0d4
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x318, %edx            # imm = 0x318
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x198d0
jmp 0x5d0d6
movl $0x2, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw (%rax,%rax)