// File: /workspace/github_c_makefile_star2_O2/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 0x4744c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0xc0(%rdi), %r12
imulq $0xc, %rax, %rax
movl -0xc(%rax,%r12), %r14d
movswl -0x8(%rax,%r12), %ebp
movswl -0x6(%rax,%r12), %edx
movswq -0x4(%rax,%r12), %r15
movswq 0x1502(%rdi), %rax
imulq $0xc, %rax, %rcx
orw $-0x1, -0x4(%rcx,%r12)
movw %dx, -0x8(%rcx,%r12)
movw %bp, -0x6(%rcx,%r12)
movl %r14d, -0xc(%rcx,%r12)
testl %edx, %edx
je 0x473f5
movswl 0x1504(%rbx), %esi
addl %edx, %esi
cmpl $0x3e6, %esi            # imm = 0x3E6
jle 0x472d4
leaq (%rcx,%r12), %rax
addq $-0xc, %rax
andw $0x0, 0x4(%rax)
jmp 0x473e9
movl %edx, (%rsp)
movq %r15, 0x18(%rsp)
movl %ebp, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x564(%rbx), %rcx
movq %rcx, 0x10(%rsp)
leaq 0xc8(%rbx), %r15
movswl 0x1504(%rbx), %ebp
addl (%rsp), %ebp
movswl 0x1506(%rbx), %r13d
cmpl %r13d, %ebp
jle 0x4744d
cmpw $0x62, %ax
jg 0x473c9
cmpw $0x0, 0x560(%rbx)
js 0x47390
movswq 0x55c(%rbx), %r14
leal (%r14,%r13), %eax
movw %ax, 0x1506(%rbx)
movswq %ax, %rax
movl $0x3e7, %edx            # imm = 0x3E7
subq %rax, %rdx
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movq %r14, %rax
shlq $0x2, %rax
movq %rdi, %rsi
subq %rax, %rsi
callq 0x24323
movzwl 0x1502(%rbx), %eax
movswq %ax, %rcx
imulq $0xc, %rcx, %rdx
addq %r15, %rdx
cmpq $0x61, %rcx
jg 0x47390
movzwl (%rdx), %esi
testw %si, %si
js 0x47387
addl %r14d, %esi
movw %si, (%rdx)
incq %rcx
addq $0xc, %rdx
jmp 0x47373
incl %eax
movw %ax, 0x1502(%rbx)
cmpw $0x63, %ax
je 0x473d3
movswq %ax, %rax
pushq $0x63
popq %rcx
subq %rax, %rcx
imulq $0xc, %rax, %rax
leaq (%r12,%rax), %rsi
leaq (%r12,%rax), %rdi
addq $-0xc, %rdi
imulq $0xc, %rcx, %rdx
callq 0x24323
movzwl 0x1502(%rbx), %eax
cmpw $0x63, %ax
jne 0x472f8
cmpl %r13d, %ebp
movq 0x8(%rsp), %r14
movl 0x4(%rsp), %ebp
movq 0x18(%rsp), %r15
movl (%rsp), %edx
jg 0x4743e
leaq 0x18(%rbx), %rdi
movl %r14d, %esi
callq 0x12e20
testw %bp, %bp
je 0x4741a
leaq 0x18(%rbx), %rdi
leaq (%rbx,%r15,4), %rdx
addq $0x564, %rdx            # imm = 0x564
movl %r14d, %esi
movl %ebp, %ecx
callq 0x13c20
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 $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movswq %ax, %rax
movl %r13d, %ecx
movl (%rsp), %edx
subl %edx, %ecx
imulq $0xc, %rax, %rax
addq %r12, %rax
addq $-0x4, %rax
movq %rax, 0x20(%rsp)
movw %cx, (%rax)
movw %cx, 0x1506(%rbx)
leaq 0x18(%rbx), %r12
xorl %r15d, %r15d
testl %edx, %edx
movl $0x0, %r14d
cmovgl %edx, %r14d
cmpl %r15d, %r14d
je 0x473d3
movq 0x8(%rsp), %rax
leal (%rax,%r15), %esi
movq %r12, %rdi
callq 0x12a60
movq 0x20(%rsp), %rcx
movswq (%rcx), %rcx
addq %r15, %rcx
movq 0x10(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
incq %r15
jmp 0x47486