// File: stetre[P]moonvulkan/src/swapchain.c
// Function: CreateSharedSwapchains
static int CreateSharedSwapchains(lua_State *L)
    {
    int err;
    VkResult ec;
    ud_t *ud;
    uint32_t count, i;
    VkSwapchainKHR *swapchains;
    VkSwapchainCreateInfoKHR* infos;
    VkDevice device = checkdevice(L, 1, &ud);
    const VkAllocationCallbacks *allocator = optallocator(L, 3);
    CheckDevicePfn(L, ud, CreateSharedSwapchainsKHR);
#define CLEANUP zfreearrayVkSwapchainCreateInfoKHR(L, infos, count, 1)
    infos = zcheckarrayVkSwapchainCreateInfoKHR(L, 2, &count, &err);
    swapchains = (VkSwapchainKHR*)MallocNoErr(L, count*sizeof(VkSwapchainKHR));
    if(!swapchains) { CLEANUP; return errmemory(L); }
    ec = ud->ddt->CreateSharedSwapchainsKHR(device, count, infos, allocator, swapchains);
    CLEANUP;
#undef CLEANUP
    if(ec) { Free(L, swapchains); CheckError(L, ec); }
    
    lua_newtable(L);
    for(i = 0; i < count; i++)
        {
        newswapchain(L, swapchains[i], device, allocator);
        lua_rawseti(L, -2, i+1);
        }
    Free(L, swapchains);
    return 0;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x38(%rsp), %rdx
leaq 0x6a3ac(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x278(%rax)
jne 0x64cdc
movq 0x48(%rsp), %rdi
leaq 0x7ebcc(%rip), %rsi     # 0xe3898
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x54(%rsp)
jmp 0x64e76
jmp 0x64cde
movq 0x48(%rsp), %rdi
movl $0x2, %esi
leaq 0x34(%rsp), %rdx
leaq 0x44(%rsp), %rcx
callq 0x18b90
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rdi
movl 0x34(%rsp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x18050
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x64d67
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %ecx
movl $0x68, %edx
movl $0x1, %r8d
callq 0x198d0
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19a60
movq 0x8(%rsp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x54(%rsp)
jmp 0x64e76
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x278(%rax), %rax
movq 0x18(%rsp), %rdi
movl 0x34(%rsp), %esi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %r8
callq *%rax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %ecx
movl $0x68, %edx
movl $0x1, %r8d
callq 0x198d0
cmpl $0x0, 0x40(%rsp)
je 0x64df7
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
cmpl $0x0, 0x40(%rsp)
je 0x64df3
movq 0x48(%rsp), %rdi
movl 0x40(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x64e76
jmp 0x64df5
jmp 0x64df7
movq 0x48(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x34(%rsp), %eax
jae 0x64e5f
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x30(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x656c0
movq 0x48(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x64e0d
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x18300
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nop