// File: stetre[P]moonvulkan/src/shader_module.c
// Function: Create
static int Create(lua_State *L)
    {
    int err;
    ud_t *ud, *device_ud;
    VkResult ec;
    VkShaderModule shader_module;
    VkShaderModuleCreateInfo* info;
    size_t size;
    const char *code;
    VkDevice device = checkdevice(L, 1, &device_ud);
    const VkAllocationCallbacks *allocator = NULL;
#define CLEANUP zfreeVkShaderModuleCreateInfo(L, info, 1)
    if(lua_istable(L, 2))
        {
        allocator = optallocator(L, 3);
        info = zcheckVkShaderModuleCreateInfo(L, 2, &err);
        if(err) { CLEANUP; return argerror(L, 2); }
        lua_getfield(L, 2, "code");
        code = luaL_optlstring(L, -1, NULL, &size);
        }
    else
        {
        VkFlags flags = checkflags(L, 2);
        info = znewVkShaderModuleCreateInfo(L, &err);
        if(err) { CLEANUP; return lua_error(L); }
        info->flags = flags;
        code = luaL_optlstring(L, 3, NULL, &size);
        }

    if(!code || (size == 0))
        return luaL_error(L, "missing shader code");
    info->codeSize = size;
    info->pCode = (uint32_t*)code;
    ec = device_ud->ddt->CreateShaderModule(device, info, allocator, &shader_module);
    CLEANUP;
    CheckError(L, ec);
#undef CLEANUP
    TRACE_CREATE(shader_module, "shader_module");
    ud = newuserdata_nondispatchable(L, shader_module, SHADER_MODULE_MT);
    ud->parent_ud = device_ud;
    ud->device = device;
    ud->instance = device_ud->instance;
    ud->allocator = allocator;
    ud->destructor = freeshader_module;
    ud->ddt = device_ud->ddt;
    return 1;
    }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq 0x68(%rsp), %rdi
movl $0x1, %esi
leaq 0x50(%rsp), %rdx
leaq 0x6c5cc(%rip), %rcx     # 0xcf03b
callq 0x1a640
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x1a240
cmpl $0x5, %eax
jne 0x62b52
movq 0x68(%rsp), %rdi
movl $0x3, %esi
callq 0x19260
movq %rax, 0x18(%rsp)
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x64(%rsp), %rdx
callq 0x185c0
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x62b1a
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
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 $0x2, %esi
callq 0x18460
movl %eax, 0x74(%rsp)
jmp 0x62d32
movq 0x68(%rsp), %rdi
movl $0x2, %esi
leaq 0x8073e(%rip), %rdx     # 0xe3269
callq 0x1a5a0
movq 0x68(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
leaq 0x30(%rsp), %rcx
callq 0x18900
movq %rax, 0x28(%rsp)
jmp 0x62bda
movq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x19010
movl %eax, 0x14(%rsp)
movq 0x68(%rsp), %rdi
movl $0x10, %esi
movl $0x28, %edx
leaq 0x64(%rsp), %rcx
callq 0x19ee0
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x64(%rsp)
je 0x62bb1
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x62d32
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x68(%rsp), %rdi
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %edx
leaq 0x30(%rsp), %rcx
callq 0x18900
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x62bea
cmpq $0x0, 0x30(%rsp)
jne 0x62c06
movq 0x68(%rsp), %rdi
leaq 0x80664(%rip), %rsi     # 0xe325a
movb $0x0, %al
callq 0x19ce0
movl %eax, 0x74(%rsp)
jmp 0x62d32
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x150(%rax), %rax
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq *%rax
movl %eax, 0x4c(%rsp)
movq 0x68(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x1, %edx
callq 0x19210
cmpl $0x0, 0x4c(%rsp)
je 0x62c8a
movq 0x68(%rsp), %rdi
movl 0x4c(%rsp), %edx
xorl %esi, %esi
callq 0x18a00
movq 0x68(%rsp), %rdi
callq 0x19ad0
movl %eax, 0x74(%rsp)
jmp 0x62d32
jmp 0x62c8c
jmp 0x62c8e
movq 0x9a303(%rip), %rax     # 0xfcf98
cmpl $0x0, (%rax)
je 0x62cad
movq 0x40(%rsp), %rsi
leaq 0x805c8(%rip), %rdi     # 0xe326e
movb $0x0, %al
callq 0x189d0
jmp 0x62caf
movq 0x68(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0x6e2cd(%rip), %rdx     # 0xd0f8d
xorl %ecx, %ecx
callq 0x18350
movq %rax, 0x58(%rsp)
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x58(%rsp), %rax
leaq 0x6c(%rip), %rcx        # 0x62d80
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x50(%rax)
movl $0x1, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax,%rax)