// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd200
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
addq $0x1, %rdi
shlq $0x2, %rdi
callq 0xd4a0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12592
movq $0x0, -0x8(%rbp)
jmp 0x12827
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpb $0x0, (%rax)
je 0x12815
callq 0xd700
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
jne 0x12605
movq -0x20(%rbp), %rdi
callq 0xd090
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movq -0x30(%rbp), %rax
movsbl (%rax), %edx
leaq 0x301c9(%rip), %rdi     # 0x427ba
movb $0x0, %al
callq 0xd8f0
movq $0x0, -0x8(%rbp)
jmp 0x12827
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x127eb
movq -0x30(%rbp), %rax
incq %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
addl $-0x5c, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x19, %eax
ja 0x12649
movq -0x38(%rbp), %rax
leaq 0x2f9c8(%rip), %rcx     # 0x42008
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x30(%rbp), %rax
movsbl (%rax), %esi
leaq 0x3018d(%rip), %rdi     # 0x427e4
movb $0x0, %al
callq 0xd8f0
movq -0x20(%rbp), %rdi
callq 0xd090
movq $0x0, -0x8(%rbp)
jmp 0x12827
movq -0x28(%rbp), %rax
movl $0x107, (%rax)          # imm = 0x107
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x1b, (%rax)
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x157, (%rax)          # imm = 0x157
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x9, (%rax)
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x103, (%rax)          # imm = 0x103
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x102, (%rax)          # imm = 0x102
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x104, (%rax)          # imm = 0x104
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x105, (%rax)          # imm = 0x105
jmp 0x127d1
movq -0x28(%rbp), %rax
movl $0x5c, (%rax)
jmp 0x127d1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x61, %eax
jl 0x1274f
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7a, %eax
jg 0x1274f
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x72, %eax
jne 0x12737
movq -0x28(%rbp), %rax
movl $0x173, (%rax)          # imm = 0x173
jmp 0x1274a
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
subl $0x61, %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x127cf
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0x12767
movq -0x28(%rbp), %rax
movl $0x1b, (%rax)
jmp 0x127cd
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x1277f
movq -0x28(%rbp), %rax
movl $0x1c, (%rax)
jmp 0x127cb
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
jne 0x12797
movq -0x28(%rbp), %rax
movl $0x1d, (%rax)
jmp 0x127c9
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5e, %eax
jne 0x127af
movq -0x28(%rbp), %rax
movl $0x1e, (%rax)
jmp 0x127c7
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5f, %eax
jne 0x127c5
movq -0x28(%rbp), %rax
movl $0x1f, (%rax)
jmp 0x127c7
jmp 0x127c9
jmp 0x127cb
jmp 0x127cd
jmp 0x127cf
jmp 0x127d1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
jmp 0x12810
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
jmp 0x125a2
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)