// File: /workspace/github_cpp_makefile_star2_O1/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 0x447c1(%rip), %rcx     # 0x90ef4
leaq 0x10(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x1a520
movq %rax, %r15
movq (%r14), %r14
movq 0x48(%r14), %rax
cmpq $0x0, 0x88(%rax)
je 0x4c7d0
movl $0x0, 0x8(%rsp)
leaq 0x55d4e(%rip), %rcx     # 0xa24b6
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a520
movq %rax, %r12
leaq 0xc(%rsp), %r13
movl $0x18, %edx
movq %rbx, %rdi
movl $0x3b9c9ad8, %esi       # imm = 0x3B9C9AD8
movq %r13, %rcx
callq 0x19de0
movq %rax, %rbp
cmpl $0x0, (%r13)
je 0x4c830
movl 0x8(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x19170
jmp 0x4c89c
cmpq $0x0, 0x80(%rax)
je 0x4c8b7
leaq 0x55cd1(%rip), %rcx     # 0xa24b6
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1a520
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
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 0x4c8ca
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
jmp 0x4c897
movq %r12, 0x10(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187e0
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 0x4c920
movl %eax, %ebp
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x19170
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18990
movq %rbx, %rdi
callq 0x199e0
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x56d35(%rip), %rsi     # 0xa35f3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19be0
jmp 0x4c8a4
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
je 0x4c969
leaq 0xc(%rsp), %r13
movl $0x8, %edx
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r13, %r8
callq 0x19840
movq %rax, %r14
cmpl $0x0, (%r13)
je 0x4c9a4
movl 0x8(%rsp), %ecx
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
jmp 0x4c89c
movq %r13, %r12
testl %ecx, %ecx
je 0x4c973
leaq 0xc(%rsp), %r13
movq %rbx, %rdi
movl %ecx, %esi
movq %r13, %rdx
callq 0x19e00
cmpl $0x0, (%r13)
je 0x4c9ec
movl 0x8(%rsp), %ecx
movl $0x18, %edx
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4c7c1
movl $0x1, %ebp
jmp 0x4c8a6
movl $0x1, %ebp
movl $0x18, %edx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x19170
jmp 0x4c8a6
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 0x4ca39
movl %eax, %ebp
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
jmp 0x4c890
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 0x4ca91
movl %eax, %ebp
movl $0x18, %edx
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %r8d
callq 0x19800
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x4c886
testl %ecx, %ecx
je 0x4ca6e
xorl %r15d, %r15d
movq %r14, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x18c30
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19140
movl 0x8(%rsp), %ecx
addq $0x8, %r12
cmpq %rcx, %r15
jb 0x4ca43
movl $0x1, %ebp
movl $0x8, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x18d40
jmp 0x4c8a6
movq %r15, %r14
testl %ecx, %ecx
je 0x4cac9
xorl %r15d, %r15d
movq %r14, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18290
incq %r15
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq %r15, %rdx
callq 0x19140
movl 0x8(%rsp), %ecx
addq $0x18, %r13
cmpq %rcx, %r15
jb 0x4ca9e
movl $0x1, %ebp
movl $0x18, %edx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x4c984