// File: stetre[P]moonvulkan/src/device.c
// Function: GetDeviceQueue
static int GetDeviceQueue(lua_State *L)
    {
    int err;
    VkQueue queue;
    ud_t *ud;
    VkDeviceQueueInfo2* info;
    VkDevice device = checkdevice(L, 1, &ud);
#define CLEANUP zfreeVkDeviceQueueInfo2(L, info, 1)
    if(lua_istable(L, 2))
        {
        info = zcheckVkDeviceQueueInfo2(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        }
    else
        {
        uint32_t queueFamilyIndex = luaL_checkinteger(L, 2);
        uint32_t queueIndex = luaL_checkinteger(L, 3);
        VkFlags flags = optflags(L, 4, 0);
        info = znewVkDeviceQueueInfo2(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        info->queueFamilyIndex = queueFamilyIndex;
        info->queueIndex = queueIndex;
        info->flags = flags;
        }
    if(ud->ddt->GetDeviceQueue2 && info->flags != 0)
        ud->ddt->GetDeviceQueue2(device, info, &queue);
    else
        ud->ddt->GetDeviceQueue(device, info->queueFamilyIndex, info->queueIndex, &queue);
    CLEANUP;
#undef CLEANUP
    if(!queue) return luaL_error(L, "cannot retrieve queue");
    pushqueue(L, queue, device);
    return 1;
    }

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x30(%rsp), %rdx
leaq 0xa5b6c(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x2955e
movq 0x48(%rsp), %rdi
movl $0x2, %esi
leaq 0x44(%rsp), %rdx
callq 0x18260
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x29559
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x186d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x2, %esi
callq 0x18460
movl %eax, 0x54(%rsp)
jmp 0x296c6
jmp 0x2960b
movq 0x48(%rsp), %rdi
movl $0x2, %esi
callq 0x19190
movl %eax, 0x1c(%rsp)
movq 0x48(%rsp), %rdi
movl $0x3, %esi
callq 0x19190
movl %eax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movl $0x4, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x19370
movl %eax, 0x14(%rsp)
movq 0x48(%rsp), %rdi
movl $0x3b9d006b, %esi       # imm = 0x3B9D006B
movl $0x20, %edx
leaq 0x44(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x295e7
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x48(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x54(%rsp)
jmp 0x296c6
movl 0x1c(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x14(%rax)
movl 0x18(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x18(%rax)
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x30(%rsp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, 0x450(%rax)
je 0x2964c
movq 0x28(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x2964c
movq 0x30(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x450(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq *%rax
jmp 0x29675
movq 0x30(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rcx
movl 0x14(%rcx), %esi
movq 0x28(%rsp), %rcx
movl 0x18(%rcx), %edx
leaq 0x38(%rsp), %rcx
callq *%rax
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpq $0x0, 0x38(%rsp)
jne 0x296aa
movq 0x48(%rsp), %rdi
leaq 0xa794f(%rip), %rsi     # 0xd0fec
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x54(%rsp)
jmp 0x296c6
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x18a60
movl $0x1, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nop