// File: /workspace/github_cpp_makefile_star2_O2/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 0x35af7(%rip), %rcx     # 0x7eef4
pushq $0x1
popq %rbp
leaq 0x10(%rsp), %r14
movl %ebp, %esi
movq %r14, %rdx
callq 0x1a500
movq %rax, %r15
movq (%r14), %r14
movq 0x48(%r14), %rax
cmpq $0x0, 0x88(%rax)
je 0x4948e
andl $0x0, (%rsp)
leaq 0x470ab(%rip), %rcx     # 0x904d9
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1a500
movq %rax, %r12
pushq $0x18
popq %rdx
leaq 0x4(%rsp), %r13
movq %rbx, %rdi
movl $0x3b9c9ad8, %esi       # imm = 0x3B9C9AD8
movq %r13, %rcx
callq 0x19dc0
movq %rax, %rbp
cmpl $0x0, (%r13)
je 0x494ea
pushq $0x18
popq %rdx
movq %rbp, %r14
pushq $0x1
popq %rbp
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x197e0
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x19150
jmp 0x49551
cmpq $0x0, 0x80(%rax)
je 0x4956c
leaq 0x47036(%rip), %rcx     # 0x904d9
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1a500
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %rsp, %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq *0x80(%rax)
testl %eax, %eax
je 0x4957f
movq %rbx, %rdi
xorl %esi, %esi
movl %eax, %edx
jmp 0x4954c
movq %r12, 0x10(%rbp)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x187d0
movq 0x48(%r14), %rax
movq %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 0x495c4
movl %eax, %ebp
pushq $0x18
popq %rdx
pushq $0x1
popq %r15
movq %rbx, %rdi
xorl %esi, %esi
movl %r15d, %r8d
callq 0x197e0
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x19150
movq %rbx, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18980
movq %rbx, %rdi
callq 0x199c0
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x480a0(%rip), %rsi     # 0x91613
movq %rbx, %rdi
xorl %eax, %eax
callq 0x19bc0
jmp 0x49559
movl (%rsp), %ecx
testl %ecx, %ecx
je 0x4955b
pushq $-0x1
popq %rsi
pushq $0x8
popq %rdx
leaq 0x4(%rsp), %r13
movq %rbx, %rdi
movq %r13, %r8
callq 0x19820
movq %rax, %r14
cmpl $0x0, (%r13)
je 0x4963a
movl (%rsp), %ecx
pushq $0x8
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %r9d, %r9d
callq 0x18d30
jmp 0x49551
movq %r13, 0x8(%rsp)
testl %ecx, %ecx
je 0x49611
leaq 0x4(%rsp), %r13
movq %rbx, %rdi
movl %ecx, %esi
movq %r13, %rdx
callq 0x19de0
movq %rax, %r12
cmpl $0x0, (%r13)
je 0x49678
movl (%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %r8d
callq 0x197e0
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
jmp 0x49482
pushq $0x18
popq %rdx
pushq $0x1
popq %rbp
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x197e0
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x19150
jmp 0x4955b
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
movq %rsp, %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq *0x80(%rax)
testl %eax, %eax
je 0x496bc
movl %eax, %ebp
movl (%rsp), %ecx
pushq $0x8
popq %rdx
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %r14, %rsi
xorl %r9d, %r9d
callq 0x18d30
jmp 0x49545
movq 0x48(%r14), %rax
movq %rsp, %rdx
movq %r15, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %r12, %rcx
callq *0x88(%rax)
testl %eax, %eax
je 0x496ee
movl %eax, %ebp
movl (%rsp), %ecx
pushq $0x18
popq %rdx
pushq $0x1
popq %r15
movq %rbx, %rdi
movq %r12, %rsi
movl %r15d, %r8d
callq 0x197e0
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x4953d
xorl %r15d, %r15d
pushq $-0x2
popq %rbp
movq %r14, %r12
movl (%rsp), %ecx
cmpq %rcx, %r15
jae 0x49725
movq %rbx, %rdi
movq %r12, %rsi
callq 0x18c20
incq %r15
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x19120
addq $0x8, %r12
jmp 0x496c5
pushq $0x1
popq %r15
pushq $-0x2
popq %rbp
movq %r12, %r13
leaq -0x1(%r15), %rax
movl (%rsp), %ecx
cmpq %rcx, %rax
jae 0x49741
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18290
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x19120
incq %r15
addq $0x18, %r13
jmp 0x496f8
pushq $0x8
popq %rdx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %r8d
xorl %r9d, %r9d
callq 0x18d30
jmp 0x4955b
pushq $0x18
popq %rdx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x4961e