// File: /workspace/github_cpp_makefile_star2_O3/stetre[P]moonvulkan/src/surface.c
// Function: GetPhysicalDeviceSurfacePresentModes
static int GetPhysicalDeviceSurfacePresentModes(lua_State *L)
    {
    VkResult ec;
    uint32_t count, i;
    VkPresentModeKHR* modes;
    ud_t *ud;
    VkPhysicalDevice physdev = checkphysical_device(L, 1, &ud);
    VkSurfaceKHR surface = checksurface(L, 2, NULL);
    int byname = optboolean(L, 3, 0);

    CheckInstancePfn(L, ud, GetPhysicalDeviceSurfacePresentModesKHR);
    lua_newtable(L);
    ec = ud->idt->GetPhysicalDeviceSurfacePresentModesKHR(physdev, surface, &count, NULL);
    CheckError(L, ec);
    if(count == 0) return 1;

    modes = (VkPresentModeKHR*)Malloc(L, sizeof(VkPresentModeKHR)*count);
    
    ud->idt->GetPhysicalDeviceSurfacePresentModesKHR(physdev, surface, &count, modes);
    if(ec) { Free(L, modes); CheckError(L, ec); return 0; }

    if(byname)
        {
        for(i = 0; i < count; i++)
            {
            pushpresentmode(L, modes[i]);
            lua_pushboolean(L, 1);
            lua_rawset(L, -3);
            }
        }
    else
        {
        for(i = 0; i < count; i++)
            {
            pushpresentmode(L, modes[i]);
            lua_rawseti(L, -2, i+1);
            }
        }
    Free(L, modes);
    return 1;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x41709(%rip), %rcx     # 0x8def4
leaq 0x10(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a4e0
movq %rax, %r15
leaq 0x52cd2(%rip), %rcx     # 0x9f4d9
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a4e0
movq %rax, %r12
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x197b0
movl %eax, %r13d
movq (%r14), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x90(%rax)
je 0x4c87e
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq *0x90(%rax)
testl %eax, %eax
je 0x4c8a2
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199a0
jmp 0x4c88f
leaq 0x53dc6(%rip), %rsi     # 0xa064b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19ba0
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %esi
movl $0x1, %ebp
testq %rsi, %rsi
je 0x4c891
shlq $0x2, %rsi
movq %rbx, %rdi
callq 0x19200
movq %rax, %r14
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %rdx, %r15
movq %r14, %rcx
callq *0x90(%rax)
movl (%r15), %eax
testl %r13d, %r13d
je 0x4c927
testl %eax, %eax
je 0x4c95b
xorl %r15d, %r15d
movl (%r14,%r15,4), %edx
movq %rbx, %rdi
movl $0x23, %esi
callq 0x18980
movq %rbx, %rdi
movl $0x1, %esi
callq 0x193a0
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18800
incq %r15
movl 0xc(%rsp), %eax
cmpq %rax, %r15
jb 0x4c8ee
jmp 0x4c95b
testl %eax, %eax
je 0x4c95b
xorl %r15d, %r15d
movl (%r14,%r15,4), %edx
movq %rbx, %rdi
movl $0x23, %esi
callq 0x18980
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19130
movl 0xc(%rsp), %eax
cmpq %rax, %r15
jb 0x4c92e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x182d0
jmp 0x4c891