// File: /workspace/github_c_makefile_star2_O1/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_textedit_undo
NK_API void
nk_textedit_undo(struct nk_text_edit *state)
{
    struct nk_text_undo_state *s = &state->undo;
    struct nk_text_undo_record u, *r;
    if (s->undo_point == 0)
        return;

    /* we need to do two things: apply the undo record, and create a redo record */
    u = s->undo_rec[s->undo_point-1];
    r = &s->undo_rec[s->redo_point-1];
    r->char_storage = -1;

    r->insert_length = u.delete_length;
    r->delete_length = u.insert_length;
    r->where = u.where;

    if (u.delete_length)
    {
       /*   if the undo record says to delete characters, then the redo record will
            need to re-insert the characters that get deleted, so we need to store
            them.
            there are three cases:
                - there's enough room to store the characters
                - characters stored for *redoing* don't leave room for redo
                - characters stored for *undoing* don't leave room for redo
            if the last is true, we have to bail */
        if (s->undo_char_point + u.delete_length >= NK_TEXTEDIT_UNDOCHARCOUNT) {
            /* the undo records take up too much character space; there's no space
            * to store the redo characters */
            r->insert_length = 0;
        } else {
            int i;
            /* there's definitely room to store the characters eventually */
            while (s->undo_char_point + u.delete_length > s->redo_char_point) {
                /* there's currently not enough room, so discard a redo record */
                nk_textedit_discard_redo(s);
                /* should never happen: */
                if (s->redo_point == NK_TEXTEDIT_UNDOSTATECOUNT)
                    return;
            }

            r = &s->undo_rec[s->redo_point-1];
            r->char_storage = (short)(s->redo_char_point - u.delete_length);
            s->redo_char_point = (short)(s->redo_char_point -  u.delete_length);

            /* now save the characters */
            for (i=0; i < u.delete_length; ++i)
                s->undo_char[r->char_storage + i] =
                    nk_str_rune_at(&state->string, u.where + i);
        }
        /* now we can carry out the deletion */
        nk_str_delete_runes(&state->string, u.where, u.delete_length);
    }

    /* check type of recorded action: */
    if (u.insert_length) {
        /* easy case: was a deletion, so we need to insert n characters */
        nk_str_insert_text_runes(&state->string, u.where,
            &s->undo_char[u.char_storage], u.insert_length);
        s->undo_char_point = (short)(s->undo_char_point - u.insert_length);
    }
    state->cursor = (short)(u.where + u.insert_length);

    s->undo_point--;
    s->redo_point--;
}

// Assembly:
movswq 0x1500(%rdi), %rax
testq %rax, %rax
je 0x4bec2
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0xc0(%rdi), %r12
leaq (%rax,%rax,2), %rax
movl -0xc(%r12,%rax,4), %r14d
movswl -0x8(%r12,%rax,4), %ebp
movswl -0x6(%r12,%rax,4), %edx
movswq -0x4(%r12,%rax,4), %r15
movswq 0x1502(%rdi), %rax
leaq (%rax,%rax,2), %rax
movw $0xffff, -0x4(%r12,%rax,4) # imm = 0xFFFF
movw %dx, -0x8(%r12,%rax,4)
movw %bp, -0x6(%r12,%rax,4)
movl %r14d, -0xc(%r12,%rax,4)
testl %edx, %edx
je 0x4be6b
movswl 0x1504(%rbx), %ecx
addl %edx, %ecx
cmpl $0x3e6, %ecx            # imm = 0x3E6
jle 0x4bcab
leaq (%r12,%rax,4), %rax
addq $-0xc, %rax
movw $0x0, 0x4(%rax)
jmp 0x4be5f
movl %edx, 0x8(%rsp)
movq %r15, 0x28(%rsp)
movl %ebp, 0x1c(%rsp)
movq %r14, 0x20(%rsp)
leaq 0x564(%rbx), %r15
leaq 0xc8(%rbx), %rax
movq %rax, 0x10(%rsp)
movswl 0x1504(%rbx), %r14d
addl 0x8(%rsp), %r14d
movswl 0x1506(%rbx), %r13d
cmpl %r13d, %r14d
jle 0x4bdc8
cmpw $0x62, 0x1502(%rbx)
jg 0x4bdb5
cmpw $0x0, 0x560(%rbx)
js 0x4bd76
movswq 0x55c(%rbx), %rbp
movzwl 0x1506(%rbx), %eax
addw %bp, %ax
movw %ax, 0x1506(%rbx)
movswq %ax, %rax
movl $0x3e7, %edx            # imm = 0x3E7
subq %rax, %rdx
leaq (%r15,%rax,4), %rdi
movq %rbp, %rax
shlq $0x2, %rax
movq %rdi, %rsi
subq %rax, %rsi
callq 0x258b3
movswq 0x1502(%rbx), %rax
cmpq $0x61, %rax
jg 0x4bd76
leaq (%rax,%rax,2), %rcx
addq $-0x62, %rax
movq 0x10(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
movzwl (%rcx), %edx
testw %dx, %dx
js 0x4bd6d
addl %ebp, %edx
movw %dx, (%rcx)
addq $0xc, %rcx
incq %rax
jne 0x4bd60
movzwl 0x1502(%rbx), %eax
incl %eax
movw %ax, 0x1502(%rbx)
cmpw $0x63, %ax
je 0x4bdb5
movswq %ax, %rax
movl $0x63, %ecx
subq %rax, %rcx
leaq (%rax,%rax,2), %rax
leaq (%r12,%rax,4), %rsi
leaq (%r12,%rax,4), %rdi
addq $-0xc, %rdi
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rdx
callq 0x258b3
cmpw $0x63, 0x1502(%rbx)
jne 0x4bcd0
jmp 0x4be48
movswq 0x1502(%rbx), %rax
movl %r13d, %ecx
movl 0x8(%rsp), %edx
subl %edx, %ecx
leaq (%rax,%rax,2), %rax
movw %cx, -0x4(%r12,%rax,4)
movw %cx, 0x1506(%rbx)
testw %dx, %dx
jle 0x4be48
leaq (%r12,%rax,4), %rax
addq $-0x4, %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%rbx), %r12
movl 0x8(%rsp), %r15d
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
leal (%rax,%rbp), %esi
movl $0x0, 0xc(%rsp)
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x34(%rsp), %rcx
callq 0x13f60
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rcx
movswq (%rcx), %rcx
addq %rbp, %rcx
movl %eax, 0x564(%rbx,%rcx,4)
incq %rbp
cmpl %ebp, %r15d
jne 0x4be07
cmpl %r13d, %r14d
movq 0x20(%rsp), %r14
movl 0x1c(%rsp), %ebp
movq 0x28(%rsp), %r15
movl 0x8(%rsp), %edx
jg 0x4beb4
leaq 0x18(%rbx), %rdi
movl %r14d, %esi
callq 0x12d10
testw %bp, %bp
je 0x4be90
leaq 0x18(%rbx), %rdi
leaq (%rbx,%r15,4), %rdx
addq $0x564, %rdx            # imm = 0x564
movl %r14d, %esi
movl %ebp, %ecx
callq 0x13a20
subw %bp, 0x1504(%rbx)
addl %r14d, %ebp
movswl %bp, %eax
movl %eax, 0xa8(%rbx)
movd 0x1500(%rbx), %xmm0
pcmpeqd %xmm1, %xmm1
paddw %xmm0, %xmm1
movd %xmm1, 0x1500(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq