// File: /workspace/github_c_makefile_star2_O2/stetre[P]moonnuklear/src/edit.c
// Function: moonnuklear_edit_string
int edit_string(lua_State *L)
    {
    size_t in_len;
    nk_plugin_filter filter = NULL;
    nk_context_t *context = checkcontext(L, 1, NULL);
    nk_edit_t *edit = &context->text_edit;
    ud_t *ud = userdata(edit);
    nk_flags flags = checkflags(L, 2); /* editflags */
    const char *in_text = luaL_checklstring(L, 3, &in_len);
    int max = luaL_checkinteger(L, 4);
    int len = (int)in_len;
    int custom_filter = 0;
    if(lua_isfunction(L, 5))
        custom_filter = 1;
    else
        filter = testpluginfilter(L, 5);

    if(max == 0 || max < len) return argerrorc(L, 4, ERR_VALUE); /* too small */
    /* allocate or reallocate the internal buffer, if needed */
    if(!ud->buf || ud->bufsize < max)
        {
        if(ud->buf) Free(L, ud->buf);
        ud->buf = (char*)Malloc(L, max);
        ud->bufsize = max;
        }
    if(in_len>0) 
        memcpy(ud->buf, in_text, in_len);

    if(custom_filter)
        {
        /* get the plugin filter */
        if(!lua_isfunction(L, 5))
            return argerrorc(L, 5, ERR_TYPE);
        unreference(L, ud->ref1);
        lua_pushvalue(L, 5);
        ud->ref1 = luaL_ref(L, LUA_REGISTRYINDEX);
        }
    /* eventually execute the function */
    flags = nk_edit_string(context, flags, ud->buf, &len, max, custom_filter ? Filter : filter);
    if(len == 0)
        lua_pushstring(L, "");
    else
        lua_pushlstring(L, ud->buf, len);
    pushflags(L, flags); /* widgetlayoutstates */
    return 2;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x498c4(%rip), %rcx     # 0x60280
movq $0x0, 0x8(%rsp)
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x120e0
movq %rax, 0x28(%rsp)
leaq 0x31d0(%rax), %rdi
callq 0x13430
movq %rax, %r14
pushq $0x2
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x13060
movq %rax, 0x20(%rsp)
pushq $0x3
popq %rsi
leaq 0x30(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rdx
callq 0x12dd0
movq %rax, 0x18(%rsp)
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x13060
movq %rax, %r13
movl (%r15), %r12d
movl %r12d, 0x14(%rsp)
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x14030
movl %eax, %r15d
cmpl $0x6, %eax
je 0x16a46
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x138c0
movq %rax, 0x8(%rsp)
testl %r13d, %r13d
sete %al
cmpl %r13d, %r12d
setg %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x16a76
pushq $-0x3
popq %rdi
callq 0x13cc0
pushq $0x4
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x124a0
movl %eax, %ebp
jmp 0x16b83
movq 0x88(%r14), %rax
testq %rax, %rax
je 0x16a96
cmpl %r13d, 0x90(%r14)
jge 0x16aaf
movq %rbx, %rdi
movq %rax, %rsi
callq 0x13220
movslq %r13d, %rsi
movq %rbx, %rdi
callq 0x13c00
movq %rax, 0x88(%r14)
movl %r13d, 0x90(%r14)
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x16ac6
movq %rax, %rdi
movq 0x18(%rsp), %rsi
callq 0x13150
cmpl $0x6, %r15d
jne 0x16b26
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x14030
cmpl $0x6, %eax
jne 0x16b94
movl 0x74(%r14), %edx
cmpl $-0x2, %edx
je 0x16afe
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x14190
movl $0xfffffffe, 0x74(%r14) # imm = 0xFFFFFFFE
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x12e90
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x12800
movl %eax, 0x74(%r14)
leaq 0x82(%rip), %rax        # 0x16ba3
movq %rax, 0x8(%rsp)
movq 0x88(%r14), %rdx
leaq 0x14(%rsp), %r12
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rcx
movl %r13d, %r8d
movq 0x8(%rsp), %r9
callq 0x140e0
movl %eax, %r15d
movslq (%r12), %rdx
testq %rdx, %rdx
je 0x16b69
movq 0x88(%r14), %rsi
movq %rbx, %rdi
callq 0x13840
jmp 0x16b78
leaq 0x54731(%rip), %rsi     # 0x6b2a1
movq %rbx, %rdi
callq 0x141d0
movl %r15d, %esi
movq %rbx, %rdi
callq 0x12c20
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x2
popq %rdi
callq 0x13cc0
pushq $0x5
jmp 0x16a63