// File: /workspace/github_cpp_makefile_star2_O1/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 0x443fe(%rip), %rcx     # 0x90ef4
leaq 0x10(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a520
movq %rax, %r15
leaq 0x559a4(%rip), %rcx     # 0xa24b6
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a520
movq %rax, %r12
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x197e0
movl %eax, %r13d
movq (%r14), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x90(%rax)
je 0x4cb89
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
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 0x4cbad
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
callq 0x18990
movq %rbx, %rdi
callq 0x199e0
jmp 0x4cb9a
leaq 0x56a9b(%rip), %rsi     # 0xa362b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19be0
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 0x4cb9c
shlq $0x2, %rsi
movq %rbx, %rdi
callq 0x19210
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 0x4cc32
testl %eax, %eax
je 0x4cc66
xorl %r15d, %r15d
movl (%r14,%r15,4), %edx
movq %rbx, %rdi
movl $0x23, %esi
callq 0x18990
movq %rbx, %rdi
movl $0x1, %esi
callq 0x193c0
movq %rbx, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18810
incq %r15
movl 0xc(%rsp), %eax
cmpq %rax, %r15
jb 0x4cbf9
jmp 0x4cc66
testl %eax, %eax
je 0x4cc66
xorl %r15d, %r15d
movl (%r14,%r15,4), %edx
movq %rbx, %rdi
movl $0x23, %esi
callq 0x18990
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19140
movl 0xc(%rsp), %eax
cmpq %rax, %r15
jb 0x4cc39
movq %rbx, %rdi
movq %r14, %rsi
callq 0x182e0
jmp 0x4cb9c