// File: /workspace/github_c_makefile_star2_O3/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 0x4b2cd
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), %r15d
movswl -0x8(%r12,%rax,4), %ebp
movswl -0x6(%r12,%rax,4), %esi
movswq -0x4(%r12,%rax,4), %rdx
movswq 0x1502(%rdi), %rax
leaq (%rax,%rax,2), %rcx
movw $0xffff, -0x4(%r12,%rcx,4) # imm = 0xFFFF
movw %si, -0x8(%r12,%rcx,4)
movw %bp, -0x6(%r12,%rcx,4)
movl %r15d, -0xc(%r12,%rcx,4)
testl %esi, %esi
je 0x4b276
movq %rdx, 0x20(%rsp)
movswl 0x1504(%rbx), %edx
movl %esi, 0x4(%rsp)
addl %esi, %edx
cmpl $0x3e6, %edx            # imm = 0x3E6
jle 0x4b0bf
leaq (%r12,%rcx,4), %rax
addq $-0xc, %rax
movw $0x0, 0x4(%rax)
jmp 0x4b261
movl %ebp, 0x8(%rsp)
movq %r15, 0x10(%rsp)
leaq 0x564(%rbx), %rcx
movq %rcx, 0x18(%rsp)
leaq 0xc8(%rbx), %r15
movswl 0x1504(%rbx), %r13d
addl 0x4(%rsp), %r13d
movswl 0x1506(%rbx), %r14d
cmpl %r14d, %r13d
jle 0x4b1cd
cmpw $0x62, %ax
jg 0x4b1be
cmpw $0x0, 0x560(%rbx)
js 0x4b17b
movswq 0x55c(%rbx), %rbp
leal (%r14,%rbp), %eax
movw %ax, 0x1506(%rbx)
movswq %ax, %rax
movl $0x3e7, %edx            # imm = 0x3E7
subq %rax, %rdx
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
leaq (,%rbp,4), %rax
movq %rdi, %rsi
subq %rax, %rsi
callq 0x25a38
movswq 0x1502(%rbx), %rax
cmpq $0x61, %rax
jg 0x4b17b
leaq (%rax,%rax,2), %rdx
movq %rax, %rcx
addq $-0x62, %rcx
leaq (%r15,%rdx,4), %rdx
movzwl (%rdx), %esi
testw %si, %si
js 0x4b172
addl %ebp, %esi
movw %si, (%rdx)
addq $0xc, %rdx
incq %rcx
jne 0x4b165
incl %eax
movw %ax, 0x1502(%rbx)
cmpw $0x63, %ax
je 0x4b253
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 0x25a38
movzwl 0x1502(%rbx), %eax
cmpw $0x63, %ax
jne 0x4b0db
jmp 0x4b253
movswq %ax, %rax
movl %r14d, %ecx
movl 0x4(%rsp), %edx
subl %edx, %ecx
leaq (%rax,%rax,2), %rax
movw %cx, -0x4(%r12,%rax,4)
movw %cx, 0x1506(%rbx)
testw %dx, %dx
movq 0x10(%rsp), %r15
movl 0x8(%rsp), %ebp
jle 0x4b261
leaq (%r12,%rax,4), %rax
addq $-0x4, %rax
movq %rax, 0x28(%rsp)
leaq 0x18(%rbx), %r12
movl 0x4(%rsp), %r15d
xorl %ebp, %ebp
movq 0x10(%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 0x28(%rsp), %rcx
movswq (%rcx), %rcx
addq %rbp, %rcx
movq 0x18(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incq %rbp
cmpl %ebp, %r15d
jne 0x4b211
cmpl %r14d, %r13d
movq 0x10(%rsp), %r15
movl 0x8(%rsp), %ebp
jg 0x4b2bf
leaq 0x18(%rbx), %rdi
movl %r15d, %esi
movl 0x4(%rsp), %edx
callq 0x12d10
movq 0x20(%rsp), %rdx
testw %bp, %bp
je 0x4b29b
leaq 0x18(%rbx), %rdi
leaq (%rbx,%rdx,4), %rdx
addq $0x564, %rdx            # imm = 0x564
movl %r15d, %esi
movl %ebp, %ecx
callq 0x13a20
subw %bp, 0x1504(%rbx)
addl %r15d, %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