// File: stetre[P]moonvulkan/src/debug_report_callback.c
// Function: Create
static int Create(lua_State *L)
    {
    ud_info_t *ud_info;
    ud_t *ud, *instance_ud;
    VkResult ec;
    VkDebugReportCallbackEXT debug_report_callback;
    VkDebugReportCallbackCreateInfoEXT info;
    int ref;
    VkInstance instance = checkinstance(L, 1, &instance_ud);
    const VkAllocationCallbacks *allocator = optallocator(L, 4);
    CheckInstancePfn(L, instance_ud, CreateDebugReportCallbackEXT);
    if(!lua_isfunction(L, 3)) return argerrorc(L, 3, ERR_TYPE);

    info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
    info.pNext = NULL;
    info.flags = checkflags(L, 2);
    info.pfnCallback = (PFN_vkDebugReportCallbackEXT)Callback;

    ud_info = (ud_info_t*)MallocNoErr(L, sizeof(ud_info_t));
    if(!ud_info) return errmemory(L);
    info.pUserData = ud_info;
    ec = instance_ud->idt->CreateDebugReportCallbackEXT(instance, &info, allocator, 
                            &debug_report_callback);
    if(ec)
        {
        Free(L, ud_info);
        CheckError(L, ec);
        return 0;
        }
    lua_pushvalue(L, 3);
    ref = luaL_ref(L, LUA_REGISTRYINDEX);
    TRACE_CREATE(debug_report_callback, "debug_report_callback");
    ud = newuserdata_nondispatchable(L, debug_report_callback, DEBUG_REPORT_CALLBACK_MT);
    ud->ref1 = ref;
    ud->info = ud_info;
    ud_info->ud = ud;
    ud->ref1 = ref;
    ud->parent_ud = instance_ud;
    ud->instance = instance;
    ud->allocator = allocator;
    ud->destructor = freedebug_report_callback;
    ud->idt = instance_ud->idt;
    return 1;
    }

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq 0x78(%rsp), %rdi
movl $0x1, %esi
leaq 0x60(%rsp), %rdx
leaq 0xaadc7(%rip), %rcx     # 0xd06c9
callq 0x1a640
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rdi
movl $0x4, %esi
callq 0x19260
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, 0xd0(%rax)
jne 0x25952
movq 0x78(%rsp), %rdi
leaq 0xaad9e(%rip), %rsi     # 0xd06dd
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x84(%rsp)
jmp 0x25b86
jmp 0x25954
movq 0x78(%rsp), %rdi
movl $0x3, %esi
callq 0x1a240
cmpl $0x6, %eax
je 0x2599a
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x19a60
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movl $0x3, %esi
callq 0x18460
movl %eax, 0x84(%rsp)
jmp 0x25b86
movl $0x3b9af4f8, 0x28(%rsp) # imm = 0x3B9AF4F8
movq $0x0, 0x30(%rsp)
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x38(%rsp)
leaq 0x5cb(%rip), %rax       # 0x25f90
movq %rax, 0x40(%rsp)
movq 0x78(%rsp), %rdi
movl $0x8, %esi
callq 0x18050
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jne 0x25a13
movq 0x78(%rsp), %rax
movq %rax, (%rsp)
movl $0xfffffffa, %edi       # imm = 0xFFFFFFFA
callq 0x19a60
movq (%rsp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x84(%rsp)
jmp 0x25b86
movq 0x70(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rax), %rax
movq 0xd0(%rax), %rax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rsi
leaq 0x50(%rsp), %rcx
callq *%rax
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
je 0x25a9c
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x18300
cmpl $0x0, 0x5c(%rsp)
je 0x25a8a
movq 0x78(%rsp), %rdi
movl 0x5c(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x78(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x84(%rsp)
jmp 0x25b86
jmp 0x25a8c
movl $0x0, 0x84(%rsp)
jmp 0x25b86
movq 0x78(%rsp), %rdi
movl $0x3, %esi
callq 0x18f40
movq 0x78(%rsp), %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x18800
movl %eax, 0x24(%rsp)
movq 0xd74d3(%rip), %rax     # 0xfcf98
cmpl $0x0, (%rax)
je 0x25add
movq 0x50(%rsp), %rsi
leaq 0xaac39(%rip), %rdi     # 0xd070f
movb $0x0, %al
callq 0x189d0
jmp 0x25adf
movq 0x78(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0xaab2f(%rip), %rdx     # 0xd061f
xorl %ecx, %ecx
callq 0x18350
movq %rax, 0x68(%rsp)
movl 0x24(%rsp), %ecx
movq 0x68(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x58(%rax)
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, (%rax)
movl 0x24(%rsp), %ecx
movq 0x68(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x68(%rsp), %rax
leaq 0x5db(%rip), %rcx       # 0x26140
movq %rcx, 0x8(%rax)
movq 0x60(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x48(%rax)
movl $0x1, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)