// File: /workspace/github_cpp_makefile_star2_O3/stetre[P]moonvulkan/src/surface.c
// Function: GetPhysicalDeviceSurfaceFormats
static int GetPhysicalDeviceSurfaceFormats(lua_State *L)
    {
    int err;
    VkResult ec;
    uint32_t count, i;
    VkSurfaceFormatKHR* formats;
    VkSurfaceKHR surface;
    ud_t *ud;
    VkPhysicalDevice physdev = checkphysical_device(L, 1, &ud);

    if(ud->idt->GetPhysicalDeviceSurfaceFormats2KHR)
        return GetPhysicalDeviceSurfaceFormats2(L, physdev, ud);
    CheckInstancePfn(L, ud, GetPhysicalDeviceSurfaceFormatsKHR);
    surface = checksurface(L, 2, NULL);

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

#define CLEANUP zfreearrayVkSurfaceFormatKHR(L, formats, count, 1)
    formats = znewarrayVkSurfaceFormatKHR(L, count, &err);
    if(err) { CLEANUP; return lua_error(L); }
    
    ec = ud->idt->GetPhysicalDeviceSurfaceFormatsKHR(physdev, surface, &count, formats);
    if(ec) { CLEANUP; CheckError(L, ec); return 0; }
    for(i = 0; i < count; i++)
        {
        zpushVkSurfaceFormatKHR(L, &formats[i]);
        lua_rawseti(L, -2, i+1);
        }
    CLEANUP;
#undef CLEANUP
    return 1;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x41ad2(%rip), %rcx     # 0x8def4
leaq 0x10(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a4e0
movq %rax, %r15
movq (%r14), %r14
movq 0x48(%r14), %rax
cmpq $0x0, 0x88(%rax)
je 0x4c4bd
movl $0x0, 0x8(%rsp)
leaq 0x53082(%rip), %rcx     # 0x9f4d9
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a4e0
movq %rax, %r12
leaq 0xc(%rsp), %r13
movl $0x18, %edx
movq %rbx, %rdi
movl $0x3b9c9ad8, %esi       # imm = 0x3B9C9AD8
movq %r13, %rcx
callq 0x19da0
movq %rax, %rbp
cmpl $0x0, (%r13)
je 0x4c51d
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x19160
jmp 0x4c589
cmpq $0x0, 0x80(%rax)
je 0x4c5a4
leaq 0x53007(%rip), %rcx     # 0x9f4d9
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a4e0
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq *0x80(%rax)
testl %eax, %eax
je 0x4c5b7
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
jmp 0x4c584
movq %r12, 0x10(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x48(%r14), %rax
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq *0x88(%rax)
movq %rbp, %r13
movl (%r12), %ecx
testl %eax, %eax
je 0x4c60d
movl %eax, %ebp
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x19160
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199a0
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x54068(%rip), %rsi     # 0xa0613
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19ba0
jmp 0x4c591
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
je 0x4c656
leaq 0xc(%rsp), %r13
movl $0x8, %edx
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r13, %r8
callq 0x19810
movq %rax, %r14
cmpl $0x0, (%r13)
je 0x4c691
movl 0x8(%rsp), %ecx
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
jmp 0x4c589
movq %r13, %r12
testl %ecx, %ecx
je 0x4c660
leaq 0xc(%rsp), %r13
movq %rbx, %rdi
movl %ecx, %esi
movq %r13, %rdx
callq 0x19dc0
cmpl $0x0, (%r13)
je 0x4c6d9
movl 0x8(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4c4ae
movl $0x1, %ebp
jmp 0x4c593
movl $0x1, %ebp
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x19160
jmp 0x4c593
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
leaq 0x8(%rsp), %r13
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq *0x80(%rax)
movl (%r13), %ecx
testl %eax, %eax
je 0x4c726
movl %eax, %ebp
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
jmp 0x4c57d
movq 0x48(%r14), %r8
leaq 0x8(%rsp), %r13
movq %r15, %rdi
movq %r12, %r14
movq %r12, %rsi
movq %r13, %rdx
movq %rax, %rcx
movq %rax, %r15
callq *0x88(%r8)
movl (%r13), %ecx
testl %eax, %eax
je 0x4c75d
movl %eax, %ebp
movl $0x18, %edx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %r8d
callq 0x197d0
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x4c573
testl %ecx, %ecx
je 0x4c797
xorl %r15d, %r15d
movq %r14, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x18c20
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19130
movl 0x8(%rsp), %ecx
addq $0x8, %r12
cmpq %rcx, %r15
jb 0x4c730
jmp 0x4c799
movq %r15, %r14
testl %ecx, %ecx
je 0x4c7bc
xorl %r15d, %r15d
movq %r14, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18280
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19130
movl 0x8(%rsp), %ecx
addq $0x18, %r13
cmpq %rcx, %r15
jb 0x4c76a
jmp 0x4c7be
xorl %ecx, %ecx
movl $0x1, %ebp
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d30
jmp 0x4c593
xorl %ecx, %ecx
movq %r14, %rsi
movl $0x1, %ebp
movl $0x18, %edx
movq %rbx, %rdi
jmp 0x4c671