// File: /workspace/github_cpp_makefile_star2_O2/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 0x399de(%rip), %rcx     # 0x7eef4
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdx
callq 0x1a500
movq %rax, %rbp
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x190d0
movq %rax, %r15
movq (%r14), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x1d8(%rax)
je 0x4557b
pushq $0x20
popq %rsi
leaq 0x4(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x19460
movq %rax, %r13
cmpl $0x0, (%r14)
je 0x4558e
testq %r13, %r13
je 0x455e5
pushq $0x30
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
jmp 0x455e0
leaq 0x4b560(%rip), %rsi     # 0x90ae2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19bc0
jmp 0x455ed
movq %r15, 0x8(%rsp)
pushq $0x20
popq %rsi
leaq 0x4(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x19e50
movq %rax, %r12
cmpl $0x0, (%r15)
je 0x45600
testq %r13, %r13
je 0x455c9
pushq $0x30
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
callq 0x197e0
testq %r12, %r12
je 0x455e5
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r12, %rsi
callq 0x197e0
movq %rbx, %rdi
callq 0x199c0
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 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %rsp, %rdx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x1d8(%rax)
testl %eax, %eax
je 0x45684
movl %eax, %ebp
testq %r13, %r13
je 0x45657
pushq $0x30
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
callq 0x197e0
testq %r12, %r12
je 0x45673
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r12, %rsi
callq 0x197e0
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
jmp 0x455e5
movq %rbp, 0x20(%rsp)
movl (%rsp), %r14d
testl %r14d, %r14d
je 0x45781
xorl %r15d, %r15d
movq %r13, 0x18(%rsp)
movl %r14d, %eax
subl $0x20, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
movl %eax, (%rsp)
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rsp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq *0x1d8(%rax)
cmpl $0x5, %eax
je 0x456e0
movl %eax, %ebp
testl %eax, %eax
jne 0x4563d
movq %r13, %rbp
movq %r12, %r13
cmpl $0x20, %r14d
pushq $0x20
popq %rax
cmovael %eax, %r14d
imulq $0x318, %r14, %r14      # imm = 0x318
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x45745
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x19860
leal 0x1(%r15), %edx
movq %rbx, %rdi
pushq $-0x3
popq %rsi
callq 0x19120
leaq (%r12,%r13), %rsi
movq %rbx, %rdi
callq 0x19ee0
addl $0x2, %r15d
movq %rbx, %rdi
pushq $-0x2
popq %rsi
movq %r15, %rdx
callq 0x19120
addq $0x318, %r12            # imm = 0x318
addq $0x30, %rbp
jmp 0x456fb
movl (%rsp), %r14d
testl %r14d, %r14d
movq %r13, %r12
movq 0x18(%rsp), %r13
jne 0x4569e
testq %r13, %r13
je 0x45774
pushq $0x30
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
callq 0x197e0
testq %r12, %r12
pushq $0x2
popq %rbp
jne 0x457a7
jmp 0x455ef
testq %r13, %r13
pushq $0x2
popq %rbp
je 0x4579e
pushq $0x30
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
callq 0x197e0
testq %r12, %r12
je 0x455ef
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r12, %rsi
callq 0x197e0
jmp 0x455ef