// File: 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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movl $0x1, %esi
leaq 0x18(%rsp), %rdx
leaq 0x6d90d(%rip), %rcx     # 0xd0eac
callq 0x1a640
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0x7eee2(%rip), %rcx     # 0xe24a0
callq 0x1a640
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x198b0
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0x90(%rax)
jne 0x6360c
movq 0x38(%rsp), %rdi
leaq 0x80001(%rip), %rsi     # 0xe35fd
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x44(%rsp)
jmp 0x637df
jmp 0x6360e
movq 0x38(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x90(%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq *%rax
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x6366d
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x637df
jmp 0x6366f
cmpl $0x0, 0x30(%rsp)
jne 0x63683
movl $0x1, 0x44(%rsp)
jmp 0x637df
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x192c0
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x90(%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rcx
leaq 0x30(%rsp), %rdx
callq *%rax
cmpl $0x0, 0x34(%rsp)
je 0x63711
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x18300
cmpl $0x0, 0x34(%rsp)
je 0x63702
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x637df
jmp 0x63704
movl $0x0, 0x44(%rsp)
jmp 0x637df
cmpl $0x0, 0x4(%rsp)
je 0x63772
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x63770
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movl $0x23, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0x19480
movq 0x38(%rsp), %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
callq 0x18860
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x63720
jmp 0x637c8
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jae 0x637c6
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movl $0x23, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x6377a
jmp 0x637c8
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x18300
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)