// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x45c2e(%rip), %rcx     # 0x8def4
leaq 0x8(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a4e0
movq %rax, %r13
movq %rbx, %rdi
movl $0x2, %esi
callq 0x190e0
movq %rax, %rbp
movq (%r14), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x1d8(%rax)
je 0x4832c
leaq 0x4(%rsp), %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x19460
movq %rax, %r12
cmpl $0x0, (%r14)
je 0x4833f
testq %r12, %r12
je 0x4839d
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4838d
leaq 0x577af(%rip), %rsi     # 0x9fae2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19ba0
jmp 0x483a5
leaq 0x4(%rsp), %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x19e30
movq %rax, %r15
cmpl $0x0, (%r14)
je 0x483b8
testq %r12, %r12
je 0x4837d
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
testq %r15, %r15
je 0x4839d
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
callq 0x199a0
movl %eax, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rax
movq %rsp, %rdx
movq %r13, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x1d8(%rax)
testl %eax, %eax
je 0x48443
movl %eax, %ebp
testq %r12, %r12
je 0x48412
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
testq %r15, %r15
je 0x48432
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
jmp 0x4839d
movq %rbp, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movl (%rsp), %r13d
testl %r13d, %r13d
je 0x48512
xorl %ebp, %ebp
movq %r15, 0x10(%rsp)
movl %r13d, %eax
subl $0x20, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
movl %eax, (%rsp)
movq 0x8(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rsp, %rdx
movq %r12, %rcx
movq %r15, %r8
callq *0x1d8(%rax)
cmpl $0x5, %eax
je 0x484a4
movl %eax, %r14d
testl %eax, %eax
jne 0x48560
cmpl $0x20, %r13d
movl $0x20, %eax
cmovael %eax, %r13d
movq %r15, %r14
movq %r12, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19840
leal 0x1(%rbp), %edx
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x19130
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19ec0
addl $0x2, %ebp
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %rbp, %rdx
callq 0x19130
addq $0x30, %r15
addq $0x318, %r14            # imm = 0x318
decq %r13
jne 0x484b7
movl (%rsp), %r13d
testl %r13d, %r13d
movq 0x10(%rsp), %r15
jne 0x48461
testq %r12, %r12
je 0x48532
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
movl $0x2, %ebp
testq %r15, %r15
je 0x483a7
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
jmp 0x483a7
testq %r12, %r12
je 0x48580
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
testq %r15, %r15
je 0x485a0
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
jmp 0x48439