// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rdi, %rbx
leaq 0x4898f(%rip), %rcx     # 0x90ef4
leaq 0x20(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a520
movq %rax, %r13
movq %rbx, %rdi
movl $0x2, %esi
callq 0x190f0
movq %rax, %rbp
movq (%r14), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x1d8(%rax)
je 0x485cb
leaq 0x1c(%rsp), %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x19480
movq %rax, %r12
cmpl $0x0, (%r14)
je 0x485de
testq %r12, %r12
je 0x4863c
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4862c
leaq 0x5a4f0(%rip), %rsi     # 0xa2ac2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19be0
jmp 0x48644
leaq 0x1c(%rsp), %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r14, %rdx
callq 0x19e70
movq %rax, %r15
cmpl $0x0, (%r14)
je 0x48657
testq %r12, %r12
je 0x4861c
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
testq %r15, %r15
je 0x4863c
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
callq 0x199e0
movl %eax, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0xc(%rsp), %rdx
movq %r13, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x1d8(%rax)
testl %eax, %eax
je 0x486e4
movl %eax, %ebp
testq %r12, %r12
je 0x486b3
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
testq %r15, %r15
je 0x486d3
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18990
jmp 0x4863c
movq %rbp, 0x30(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x487f8
movq %r13, 0x28(%rsp)
movq %r15, 0x10(%rsp)
xorl %ebp, %ebp
movl 0xc(%rsp), %r15d
movl %r15d, %eax
subl $0x20, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
movl $0x20, %r13d
cmovbl %r15d, %r13d
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r8
callq *0x1d8(%rax)
cmpl $0x5, %eax
je 0x48757
movl %eax, %r14d
testl %eax, %eax
jne 0x48846
testl %r15d, %r15d
je 0x487b0
movl %r13d, %r13d
movq 0x10(%rsp), %r14
movq %r12, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19880
leal 0x1(%rbp), %edx
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x19140
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19f00
addl $0x2, %ebp
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %rbp, %rdx
callq 0x19140
addq $0x30, %r15
addq $0x318, %r14            # imm = 0x318
decq %r13
jne 0x48767
cmpl $0x0, 0xc(%rsp)
jne 0x48700
testq %r12, %r12
je 0x487db
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movl $0x2, %ebp
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x48646
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
jmp 0x48831
testq %r12, %r12
je 0x48818
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movl $0x2, %ebp
testq %r15, %r15
je 0x48646
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movq %r15, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
jmp 0x48646
testq %r12, %r12
je 0x48866
movl $0x30, %edx
movq %rbx, %rdi
movq %r12, %rsi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x48888
movl $0x318, %edx            # imm = 0x318
movq %rbx, %rdi
movl $0x20, %ecx
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
xorl %esi, %esi
movl %r14d, %edx
jmp 0x486da