// File: stetre[P]moonvulkan/src/display_mode.c
// Function: Create
static int Create(lua_State *L)
    {
    int err;
    ud_t *display_ud;
    VkResult ec;
    VkDisplayModeKHR display_mode;
    VkDisplayModeCreateInfoKHR* info = NULL;
    VkDisplayKHR display = checkdisplay(L, 1, &display_ud);
    VkPhysicalDevice physical_device = (VkPhysicalDevice)(uintptr_t)display_ud->parent_ud->handle;
    const VkAllocationCallbacks *allocator = NULL;
    CheckInstancePfn(L, display_ud, CreateDisplayModeKHR);

#define CLEANUP zfreeVkDisplayModeCreateInfoKHR(L, info, 1)
    if(lua_istable(L, 2))
        {
        info = zcheckVkDisplayModeCreateInfoKHR(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        allocator = optallocator(L, 3);
        }
    else
        {
#define CLEANUP1 zfreeVkDisplayModeParametersKHR(L, parameters, 1)
        VkDisplayModeCreateFlagsKHR flags = checkflags(L, 2);
        VkDisplayModeParametersKHR* parameters = zcheckVkDisplayModeParametersKHR(L, 3, &err);
        if(err) { CLEANUP1; return argerror(L, 3); }
        info = znewVkDisplayModeCreateInfoKHR(L, &err);
        if(err) { CLEANUP; CLEANUP1; return lua_error(L); }
#undef CLEANUP1
        info->flags = flags;
        memcpy(&info->parameters, parameters, sizeof(VkDisplayModeParametersKHR));
        Free(L, parameters); /* no zfree here */
        allocator = optallocator(L, 4);
        }
    ec = display_ud->idt->CreateDisplayModeKHR(physical_device, display, info, allocator, &display_mode);
    CLEANUP;
#undef CLEANUP
    CheckError(L, ec);
    pushdisplaymode(L, display_mode, display_ud, allocator);
    return 1;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1, %esi
leaq 0x58(%rsp), %rdx
leaq 0xa358e(%rip), %rcx     # 0xd1606
callq 0x1a640
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0xb8(%rax)
jne 0x2e0cb
movq 0x68(%rsp), %rdi
leaq 0xa3818(%rip), %rsi     # 0xd18d3
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x74(%rsp)
jmp 0x2e324
jmp 0x2e0cd
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x2e16a
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x64(%rsp), %rdx
callq 0x1a260
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x2e151
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x10(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x2e324
movq 0x68(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x28(%rsp)
jmp 0x2e297
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x24(%rsp)
movq 0x68(%rsp), %rdi
movl $0x3, %esi
leaq 0x64(%rsp), %rdx
callq 0x1a2c0
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x2e1ed
movq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x19710
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x3, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x2e324
movq 0x68(%rsp), %rdi
movl $0x3b9ad1d0, %esi       # imm = 0x3B9AD1D0
movl $0x20, %edx
leaq 0x64(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x2e251
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x19710
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x2e324
movl 0x24(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x40(%rsp), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x14(%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x1c(%rax)
movq 0x68(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x18300
movq 0x68(%rsp), %rdi
movl $0x4, %esi
callq 0x19260
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rax
movq 0x48(%rax), %rax
movq 0xb8(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x28(%rsp), %rcx
leaq 0x48(%rsp), %r8
callq *%rax
movl %eax, 0x54(%rsp)
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpl $0x0, 0x54(%rsp)
je 0x2e301
movq 0x68(%rsp), %rdi
movl 0x54(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x2e324
jmp 0x2e303
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0x2e4e0
movl $0x1, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax)