// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce.c
// Function: ce_char_string_to_rune_string
CeRune_t* ce_char_string_to_rune_string(const char* char_str){
     // we can just use the strlen, and it'll be over allocated because the command string will always be
     // the same size or small than the char string
     size_t str_len = strlen(char_str);

     int* int_str = malloc((str_len + 1) * sizeof(*int_str));
     if(!int_str) return NULL;

     int* int_itr = int_str;
     const char* char_itr = char_str;
     while(*char_itr){
          if(!isprint((int)(*char_itr))){
               free(int_str);
               ce_log("found unprintable char at position %d %d\n", char_itr - char_str, *char_itr);
               return NULL;
          }

          if(*char_itr == '\\'){
               char_itr++;
               switch(*char_itr){
               default:
                    ce_log("unrecognized escape char %c\n", *char_itr);
                    free(int_str);
                    return NULL;
               case 'b':
                    *int_itr = KEY_ONLY_BACKSPACE;
                    break;
               case 'e':
                    *int_itr = KEY_ESCAPE;
                    break;
               case 'r':
                    *int_itr = KEY_CARRIAGE_RETURN;
                    break;
               case 't':
                    *int_itr = CE_TAB;
                    break;
               case 'u':
                    *int_itr = KEY_UP_ARROW;
                    break;
               case 'd':
                    *int_itr = KEY_DOWN_ARROW;
                    break;
               case 'l':
                    *int_itr = KEY_LEFT_ARROW;
                    break;
               case 'i':
                    *int_itr = KEY_RIGHT_ARROW;
                    break;
               case '\\':
                    *int_itr = '\\';
                    break;
               case '^':
                    char_itr++;
                    if(*char_itr >= 'a' && *char_itr <= 'z'){
                         if(*char_itr == 'r'){
                              *int_itr = KEY_REDO;
                         }else{
                              *int_itr = (*char_itr - 'a') + 1;
                         }
                    }else if(*char_itr == '['){
                         *int_itr = 27;
                    }else if(*char_itr == '\\'){
                         *int_itr = 28;
                    }else if(*char_itr == ']'){
                         *int_itr = 29;
                    }else if(*char_itr == '^'){
                         *int_itr = 30;
                    }else if(*char_itr == '_'){
                         *int_itr = 31;
                    }
                    break;
               }

               char_itr++;
               int_itr++;
          }else{
               *int_itr = *char_itr;
               char_itr++;
               int_itr++;
          }
     }

     *int_itr = 0; // NULL terminate

     return int_str;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
callq 0xd210
leaq 0x4(,%rax,4), %rdi
callq 0xd4c0
testq %rax, %rax
je 0x1020b
movq %rax, %rbp
leaq 0x19f7c(%rip), %r13     # 0x2a030
movq %rax, %rbx
movq %r14, %r15
movsbq (%r15), %r12
testq %r12, %r12
je 0x101c9
callq 0xd720
movq (%rax), %rax
testb $0x40, 0x1(%rax,%r12,2)
je 0x101ce
cmpb $0x5c, %r12b
jne 0x101b4
leaq 0x1(%r15), %rax
movzbl 0x1(%r15), %ecx
leal -0x5c(%rcx), %edx
cmpl $0xd, %edx
ja 0x10104
movslq (%r13,%rdx,4), %rdx
addq %r13, %rdx
jmpq *%rdx
pushq $0x5c
jmp 0x10180
leal -0x6c(%rcx), %edx
cmpl $0x9, %edx
ja 0x101f2
leaq 0x19f51(%rip), %rsi     # 0x2a068
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x104, %r12d           # imm = 0x104
jmp 0x101b7
movl $0x102, %r12d           # imm = 0x102
jmp 0x101b7
movl $0x105, %r12d           # imm = 0x105
jmp 0x101b7
movzbl 0x2(%r15), %eax
addq $0x2, %r15
leal -0x61(%rax), %ecx
cmpb $0x19, %cl
ja 0x10186
movl $0x173, %r12d           # imm = 0x173
cmpl $0x72, %eax
je 0x101b4
addl $-0x60, %eax
movl %eax, %r12d
jmp 0x101b4
movl $0x107, %r12d           # imm = 0x107
jmp 0x101b7
pushq $0x1b
jmp 0x10180
movl $0x103, %r12d           # imm = 0x103
jmp 0x101b7
movl $0x157, %r12d           # imm = 0x157
jmp 0x101b7
pushq $0x9
popq %rcx
movl %ecx, %r12d
jmp 0x101b7
addl $-0x5b, %eax
cmpl $0x4, %eax
ja 0x101bd
leaq 0x19efb(%rip), %rcx     # 0x2a090
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x1b
jmp 0x101b0
pushq $0x1f
jmp 0x101b0
pushq $0x1d
jmp 0x101b0
pushq $0x1e
jmp 0x101b0
pushq $0x1c
popq %rax
movl %eax, %r12d
movq %r15, %rax
movl %r12d, (%rbx)
movq %rax, %r15
incq %r15
addq $0x4, %rbx
jmp 0x100ba
andl $0x0, (%rbx)
jmp 0x1020d
movq %rbp, %rdi
callq 0xd090
movsbl (%r15), %edx
subq %r14, %r15
leaq 0x1a63c(%rip), %rdi     # 0x2a820
xorl %ebp, %ebp
movq %r15, %rsi
xorl %eax, %eax
callq 0xd8e5
jmp 0x1020d
movsbl %cl, %esi
leaq 0x1a64e(%rip), %rdi     # 0x2a84a
xorl %eax, %eax
callq 0xd8e5
movq %rbp, %rdi
callq 0xd090
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq