// File: stetre[P]moonvulkan/src/display_mode.c
// Function: GetDisplayModeProperties1
static int GetDisplayModeProperties1(lua_State *L, VkDisplayKHR display, ud_t *ud)
    {
    int err;
    VkResult ec;
    uint32_t count, remaining, tot, i;
    VkDisplayModePropertiesKHR* properties; //[N];
    VkPhysicalDevice physical_device = (VkPhysicalDevice)(uintptr_t)ud->parent_ud->handle;
    CheckInstancePfn(L, ud, GetDisplayModePropertiesKHR);
#define CLEANUP zfreearrayVkDisplayModePropertiesKHR(L, properties, N, 1)
    properties = znewarrayVkDisplayModePropertiesKHR(L, N, &err);
    if(err) { CLEANUP; lua_error(L); }
    lua_newtable(L);
    ec = ud->idt->GetDisplayModePropertiesKHR(physical_device, display, &remaining, NULL);
    if(ec) { CLEANUP; CheckError(L, ec); }
    if(remaining==0) { CLEANUP; return 1; }
    tot = 0;
    do {
        if(remaining > N)
            { count = N; remaining -= N; }
        else
            { count = remaining; remaining = 0; }

        ec = ud->idt->GetDisplayModePropertiesKHR(physical_device, display, &count, properties);
        if(ec && ec != VK_INCOMPLETE) { CLEANUP; CheckError(L, ec); }
    
        for(i = 0; i < count; i++)
            {
            zpushVkDisplayModePropertiesKHR(L, &properties[i]);
            pushdisplaymode(L, properties[i].displayMode, ud, NULL);
            lua_setfield(L, -2, "display_mode");
            lua_rawseti(L, -2, ++tot);
            }
        } while (remaining > 0);

    CLEANUP;
#undef CLEANUP
    return 1;
    }

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0xb0(%rax)
jne 0x2e992
movq 0x38(%rsp), %rdi
leaq 0xa2fb7(%rip), %rsi     # 0xd1939
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x44(%rsp)
jmp 0x2ec41
jmp 0x2e994
movq 0x38(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x18, %edx
movl $0x20, %ecx
leaq 0x24(%rsp), %r8
callq 0x19920
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x2e9ec
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x18, %edx
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movq 0x38(%rsp), %rdi
callq 0x19ad0
movq 0x38(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x18830
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movq 0xb0(%rax), %rax
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x18(%rsp), %rdx
xorl %ecx, %ecx
callq *%rax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x2ea79
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x18, %edx
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x20(%rsp)
je 0x2ea75
movq 0x38(%rsp), %rdi
movl 0x20(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x2ec41
jmp 0x2ea77
jmp 0x2ea79
cmpl $0x0, 0x18(%rsp)
jne 0x2eab1
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x18, %edx
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x44(%rsp)
jmp 0x2ec41
movl $0x0, 0x14(%rsp)
cmpl $0x20, 0x18(%rsp)
jbe 0x2ead5
movl $0x20, 0x1c(%rsp)
movl 0x18(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x18(%rsp)
jmp 0x2eae5
movl 0x18(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
movq 0xb0(%rax), %rax
movq (%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x8(%rsp), %rcx
leaq 0x1c(%rsp), %rdx
callq *%rax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x2eb6e
cmpl $0x5, 0x20(%rsp)
je 0x2eb6e
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x18, %edx
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
cmpl $0x0, 0x20(%rsp)
je 0x2eb6a
movq 0x38(%rsp), %rdi
movl 0x20(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x38(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x44(%rsp)
jmp 0x2ec41
jmp 0x2eb6c
jmp 0x2eb6e
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jae 0x2ec08
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x190d0
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rax
movl 0x10(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2e4e0
movq 0x38(%rsp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
leaq 0xa2ca1(%rip), %rdx     # 0xd1876
callq 0x18b80
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movl %eax, %eax
movl %eax, %edx
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x191e0
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x2eb76
jmp 0x2ec0a
cmpl $0x0, 0x18(%rsp)
ja 0x2eab9
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl $0x18, %edx
movl $0x20, %ecx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18dd0
movl $0x1, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nopw (%rax,%rax)