// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce.c
// Function: ce_rune_string_to_char_string
char* ce_rune_string_to_char_string(const CeRune_t* int_str){
     // build length
     size_t len = 1; // account for NULL terminator
     const int* int_itr = int_str;
     while(*int_itr){
          if(isprint(*int_itr)){
               len++;
          }else{
               switch(*int_itr){
               default:
                    if(*int_itr >= 1 && *int_itr <= 31){
                         len += 3;
                    }else{
                         len++; // going to fill in with '~' for now
                    }
                    break;
               case KEY_ONLY_BACKSPACE:
               case KEY_ESCAPE:
               case KEY_CARRIAGE_RETURN:
               case CE_TAB:
               case KEY_UP_ARROW:
               case KEY_DOWN_ARROW:
               case KEY_LEFT_ARROW:
               case KEY_RIGHT_ARROW:
               case '\\':
                    len += 2;
                    break;
               case KEY_REDO:
                    len += 3;
                    break;
               }
          }

          int_itr++;
     }

     char* char_str = malloc(len);
     if(!char_str) return NULL;

     char* char_itr = char_str;
     int_itr = int_str;
     while(*int_itr){
          if(isprint(*int_itr)){
               *char_itr = *int_itr;
               char_itr++;
          }else{
               switch(*int_itr){
               default:
                    if(*int_itr >= 1 && *int_itr <= 26){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = 'a' + (*int_itr - 1); char_itr++;
                    }else if(*int_itr == 27){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = '['; char_itr++;
                    }else if(*int_itr == 28){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = '\\'; char_itr++;
                    }else if(*int_itr == 29){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = ']'; char_itr++;
                    }else if(*int_itr == 30){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = '^'; char_itr++;
                    }else if(*int_itr == 31){
                         *char_itr = '\\'; char_itr++;
                         *char_itr = '^'; char_itr++;
                         *char_itr = '_'; char_itr++;
                    }else{
                         *char_itr = '~';
                         char_itr++;
                    }
                    break;
               case KEY_ONLY_BACKSPACE:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'b'; char_itr++;
                    break;
               case KEY_ESCAPE:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'e'; char_itr++;
                    break;
               case KEY_CARRIAGE_RETURN:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'r'; char_itr++;
                    break;
               case CE_TAB:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 't'; char_itr++;
                    break;
               case KEY_UP_ARROW:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'u'; char_itr++;
                    break;
               case KEY_DOWN_ARROW:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'd'; char_itr++;
                    break;
               case KEY_LEFT_ARROW:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'l'; char_itr++;
                    break;
               case KEY_RIGHT_ARROW:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = 'i'; char_itr++; // NOTE: not happy with 'i'
                    break;
               case KEY_REDO:
                    *char_itr = '\\'; char_itr++;
                    *char_itr = '^'; char_itr++;
                    *char_itr = 'r'; char_itr++;
                    break;
               case '\\':
                    *char_itr = '\\'; char_itr++;
                    *char_itr = '\\'; char_itr++;
                    break;
               }
          }

          int_itr++;
     }

     char_str[len - 1] = 0;

     return char_str;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl (%rdi), %r12d
testl %r12d, %r12d
je 0x10416
movq %rdi, %r14
callq 0xd720
movq (%rax), %rax
leaq 0x4(%r14), %rcx
movl $0x1, %ebx
movl %r12d, %edx
movslq %edx, %rsi
testb $0x40, 0x1(%rax,%rsi,2)
movl $0x1, %esi
jne 0x10267
movl $0x2, %esi
cmpl $0x101, %edx            # imm = 0x101
jle 0x10276
leal -0x102(%rdx), %edi
cmpl $0x5, %edi
ja 0x10287
cmpl $0x4, %edi
je 0x10287
addq %rsi, %rbx
movl (%rcx), %edx
addq $0x4, %rcx
testl %edx, %edx
jne 0x1023b
jmp 0x102b1
cmpl $0x9, %edx
je 0x10267
cmpl $0x1b, %edx
je 0x10267
cmpl $0x5c, %edx
je 0x10267
jmp 0x1029e
cmpl $0x157, %edx            # imm = 0x157
je 0x10267
cmpl $0x173, %edx            # imm = 0x173
jne 0x1029e
movl $0x3, %esi
jmp 0x10267
xorl %esi, %esi
cmpl $0x20, %edx
setb %sil
leaq 0x1(,%rsi,2), %rsi
jmp 0x10267
movq %rbx, %rdi
callq 0xd4c0
testq %rax, %rax
je 0x10435
movq %rax, %r15
testl %r12d, %r12d
je 0x1042d
callq 0xd720
addq $0x4, %r14
leaq 0x1cd3e(%rip), %rcx     # 0x2d01c
leaq 0x1cd1f(%rip), %rdx     # 0x2d004
movq %r15, %rsi
movq (%rax), %rdi
movslq %r12d, %r8
testb $0x40, 0x1(%rdi,%r8,2)
jne 0x1031f
cmpl $0x101, %r12d           # imm = 0x101
jle 0x1032a
leal -0x102(%r12), %edi
cmpl $0x5, %edi
ja 0x10343
movslq (%rdx,%rdi,4), %rdi
addq %rdx, %rdi
jmpq *%rdi
movw $0x645c, (%rsi)         # imm = 0x645C
jmp 0x103a8
movb %r12b, (%rsi)
incq %rsi
jmp 0x103ac
cmpl $0x9, %r12d
je 0x10395
cmpl $0x1b, %r12d
je 0x1039c
cmpl $0x5c, %r12d
jne 0x10360
movw $0x5c5c, (%rsi)         # imm = 0x5C5C
jmp 0x103a8
cmpl $0x157, %r12d           # imm = 0x157
je 0x103a3
cmpl $0x173, %r12d           # imm = 0x173
jne 0x10360
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x72, 0x2(%rsi)
jmp 0x10373
cmpl $0x1a, %r12d
ja 0x103be
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
orb $0x60, %r12b
movb %r12b, 0x2(%rsi)
addq $0x3, %rsi
jmp 0x103ac
movw $0x625c, (%rsi)         # imm = 0x625C
jmp 0x103a8
movw $0x755c, (%rsi)         # imm = 0x755C
jmp 0x103a8
movw $0x695c, (%rsi)         # imm = 0x695C
jmp 0x103a8
movw $0x6c5c, (%rsi)         # imm = 0x6C5C
jmp 0x103a8
movw $0x745c, (%rsi)         # imm = 0x745C
jmp 0x103a8
movw $0x655c, (%rsi)         # imm = 0x655C
jmp 0x103a8
movw $0x725c, (%rsi)         # imm = 0x725C
addq $0x2, %rsi
movl (%r14), %r12d
addq $0x4, %r14
testl %r12d, %r12d
jne 0x102e8
jmp 0x1042d
addl $-0x1b, %r12d
cmpl $0x4, %r12d
ja 0x1040e
movslq (%rcx,%r12,4), %rdi
addq %rcx, %rdi
jmpq *%rdi
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x5b, 0x2(%rsi)
jmp 0x10373
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x5f, 0x2(%rsi)
jmp 0x10373
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x5d, 0x2(%rsi)
jmp 0x10373
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x5e, 0x2(%rsi)
jmp 0x10373
movw $0x5e5c, (%rsi)         # imm = 0x5E5C
movb $0x5c, 0x2(%rsi)
jmp 0x10373
movb $0x7e, (%rsi)
jmp 0x10322
movl $0x1, %ebx
movl $0x1, %edi
callq 0xd4c0
movq %rax, %r15
testq %rax, %rax
je 0x10435
movb $0x0, -0x1(%r15,%rbx)
jmp 0x10438
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq