// File: Ciaxur[P]yagb-emu/include/imgui/imstb_textedit.h
// Function: ImStb::stb_text_redo(ImGuiInputTextState*, ImStb::STB_TexteditState*)
static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
{
   StbUndoState *s = &state->undostate;
   StbUndoRecord *u, r;
   if (s->redo_point == STB_TEXTEDIT_UNDOSTATECOUNT)
      return;

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

   // we KNOW there must be room for the undo record, because the redo record
   // was derived from an undo record

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

   if (r.delete_length) {
      // the redo record requires us to delete characters, so the undo record
      // needs to store the characters

      if (s->undo_char_point + u->insert_length > s->redo_char_point) {
         u->insert_length = 0;
         u->delete_length = 0;
      } else {
         int i;
         u->char_storage = s->undo_char_point;
         s->undo_char_point = s->undo_char_point + u->insert_length;

         // now save the characters
         for (i=0; i < u->insert_length; ++i)
            s->undo_char[u->char_storage + i] = STB_TEXTEDIT_GETCHAR(str, u->where + i);
      }

      STB_TEXTEDIT_DELETECHARS(str, r.where, r.delete_length);
   }

   if (r.insert_length) {
      // easy case: need to insert n characters
      STB_TEXTEDIT_INSERTCHARS(str, r.where, &s->undo_char[r.char_storage], r.insert_length);
      s->redo_char_point += r.insert_length;
   }

   state->cursor = r.where + r.insert_length;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movswl 0xe00(%rax), %eax
cmpl $0x63, %eax
jne 0x159421
jmp 0x1595c7
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movswq 0xdfe(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movswq 0xe00(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
cmpl $0x0, -0x28(%rbp)
je 0x159552
movq -0x18(%rbp), %rax
movl 0xe04(%rax), %eax
movq -0x20(%rbp), %rcx
addl 0x4(%rcx), %eax
movq -0x18(%rbp), %rcx
cmpl 0xe08(%rcx), %eax
jle 0x1594c9
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x8(%rax)
jmp 0x159543
movq -0x18(%rbp), %rax
movl 0xe04(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl 0xe04(%rax), %ecx
movq -0x20(%rbp), %rax
addl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xe04(%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x159541
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
addl -0x34(%rbp), %esi
callq 0x159a30
movw %ax, %dx
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movw %dx, 0x630(%rax,%rcx,2)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1594fc
jmp 0x159543
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x158e00
cmpl $0x0, -0x2c(%rbp)
je 0x15958f
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
movq -0x18(%rbp), %rdx
addq $0x630, %rdx            # imm = 0x630
movslq -0x24(%rbp), %rax
shlq %rax
addq %rax, %rdx
movl -0x2c(%rbp), %ecx
callq 0x158ed0
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
addl 0xe08(%rax), %ecx
movl %ecx, 0xe08(%rax)
movl -0x30(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movw 0xdfe(%rax), %cx
addw $0x1, %cx
movw %cx, 0xdfe(%rax)
movq -0x18(%rbp), %rax
movw 0xe00(%rax), %cx
addw $0x1, %cx
movw %cx, 0xe00(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)