// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0xc0, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movswl 0x1440(%rax), %eax
cmpl $0x0, %eax
jne 0x6fcff
jmp 0x6ff72
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movswl 0x1440(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x1c(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movswl 0x1442(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movw $0xffff, 0x8(%rax)      # imm = 0xFFFF
movw 0x22(%rsp), %cx
movq 0x10(%rsp), %rax
movw %cx, 0x4(%rax)
movw 0x20(%rsp), %cx
movq 0x10(%rsp), %rax
movw %cx, 0x6(%rax)
movl 0x1c(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
cmpw $0x0, 0x22(%rsp)
je 0x6fed1
movq 0x28(%rsp), %rax
movswl 0x1444(%rax), %eax
movswl 0x22(%rsp), %ecx
addl %ecx, %eax
cmpl $0x3e7, %eax            # imm = 0x3E7
jl 0x6fdb7
movq 0x10(%rsp), %rax
movw $0x0, 0x4(%rax)
jmp 0x6feba
jmp 0x6fdb9
movq 0x28(%rsp), %rax
movswl 0x1444(%rax), %eax
movswl 0x22(%rsp), %ecx
addl %ecx, %eax
movq 0x28(%rsp), %rcx
movswl 0x1446(%rcx), %ecx
cmpl %ecx, %eax
jle 0x6fdfe
movq 0x28(%rsp), %rdi
callq 0x6ff80
movq 0x28(%rsp), %rax
movswl 0x1442(%rax), %eax
cmpl $0x63, %eax
jne 0x6fdfc
jmp 0x6ff72
jmp 0x6fdb9
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movswl 0x1442(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movswl 0x1446(%rax), %eax
movswl 0x22(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq 0x10(%rsp), %rax
movw %cx, 0x8(%rax)
movq 0x28(%rsp), %rax
movswl 0x1446(%rax), %eax
movswl 0x22(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq 0x28(%rsp), %rax
movw %cx, 0x1446(%rax)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movswl 0x22(%rsp), %ecx
cmpl %ecx, %eax
jge 0x6feb8
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
movl 0x1c(%rsp), %esi
addl 0xc(%rsp), %esi
callq 0x13a90
movl %eax, %edx
movq 0x28(%rsp), %rax
movq 0x10(%rsp), %rcx
movswl 0x8(%rcx), %ecx
addl 0xc(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, 0x4a4(%rax,%rcx,4)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x6fe6a
jmp 0x6feba
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
movl 0x1c(%rsp), %esi
movswl 0x22(%rsp), %edx
callq 0x13e40
cmpw $0x0, 0x20(%rsp)
je 0x6ff2b
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
movl 0x1c(%rsp), %esi
movq 0x28(%rsp), %rdx
addq $0x4a4, %rdx            # imm = 0x4A4
movswq 0x24(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movswl 0x20(%rsp), %ecx
callq 0x14c60
movq 0x28(%rsp), %rax
movswl 0x1444(%rax), %eax
movswl 0x20(%rsp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq 0x28(%rsp), %rax
movw %cx, 0x1444(%rax)
movl 0x1c(%rsp), %eax
movswl 0x20(%rsp), %ecx
addl %ecx, %eax
movswl %ax, %ecx
movq 0x30(%rsp), %rax
movl %ecx, 0xa8(%rax)
movq 0x28(%rsp), %rax
movw 0x1440(%rax), %cx
addw $-0x1, %cx
movw %cx, 0x1440(%rax)
movq 0x28(%rsp), %rax
movw 0x1442(%rax), %cx
addw $-0x1, %cx
movw %cx, 0x1442(%rax)
addq $0x38, %rsp
retq
nopw (%rax,%rax)