// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
leaq 0x508ce(%rip), %rcx     # 0x67280
xorl %ebp, %ebp
movl $0x1, %esi
xorl %edx, %edx
callq 0x120d0
movq %rax, 0x18(%rsp)
leaq 0x31d0(%rax), %rdi
callq 0x132d0
movq %rax, %r14
movq %rbx, %rdi
movl $0x2, %esi
callq 0x12f30
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %r12
movq %rbx, %rdi
movl $0x3, %esi
movq %r12, %rdx
callq 0x12cd0
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movl $0x4, %esi
callq 0x12f30
movq %rax, %r13
movl (%r12), %r15d
movl %r15d, 0x4(%rsp)
movq %rbx, %rdi
movl $0x5, %esi
callq 0x13df0
movl %eax, %r12d
cmpl $0x6, %eax
je 0x16a3e
movq %rbx, %rdi
movl $0x5, %esi
callq 0x136e0
movq %rax, %rbp
testl %r13d, %r13d
sete %al
cmpl %r13d, %r15d
setg %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x16a70
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
callq 0x13ac0
movq %rbx, %rdi
movl $0x4, %esi
movq %rax, %rdx
callq 0x12460
jmp 0x16b7d
movq 0x88(%r14), %rax
testq %rax, %rax
je 0x16a90
cmpl %r13d, 0x90(%r14)
jge 0x16aa9
movq %rbx, %rdi
movq %rax, %rsi
callq 0x130d0
movslq %r13d, %rsi
movq %rbx, %rdi
callq 0x13a00
movq %rax, 0x88(%r14)
movl %r13d, 0x90(%r14)
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x16ac0
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x13010
cmpl $0x6, %r12d
jne 0x16b1f
movq %rbx, %rdi
movl $0x5, %esi
callq 0x13df0
cmpl $0x6, %eax
jne 0x16b8c
movl 0x74(%r14), %edx
cmpl $-0x2, %edx
je 0x16afa
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x13f50
movl $0xfffffffe, 0x74(%r14) # imm = 0xFFFFFFFE
movq %rbx, %rdi
movl $0x5, %esi
callq 0x12d70
movq %rbx, %rdi
movl $0xfff0b9d8, %esi       # imm = 0xFFF0B9D8
callq 0x12780
movl %eax, 0x74(%r14)
leaq 0x84(%rip), %rbp        # 0x16ba3
movq 0x88(%r14), %rdx
leaq 0x4(%rsp), %r12
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rcx
movl %r13d, %r8d
movq %rbp, %r9
callq 0x13ea0
movl %eax, %ebp
movslq (%r12), %rdx
testq %rdx, %rdx
je 0x16b5f
movq 0x88(%r14), %rsi
movq %rbx, %rdi
callq 0x13670
jmp 0x16b6e
leaq 0x5b7cb(%rip), %rsi     # 0x72331
movq %rbx, %rdi
callq 0x13f90
movl %ebp, %esi
movq %rbx, %rdi
callq 0x12b60
movl $0x2, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x13ac0
movq %rbx, %rdi
movl $0x5, %esi
jmp 0x16a63