// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
pushq $0x1
popq %r15
pushq $0x2
popq %r12
movq %r15, %r14
movq %rdi, %rbp
movslq (%rbp), %r13
testq %r13, %r13
je 0xfeff
callq 0xd720
movq (%rax), %rax
testb $0x40, 0x1(%rax,%r13,2)
movq %r15, %rax
jne 0xfee3
leal -0x102(%r13), %ecx
cmpl $0x5, %ecx
jbe 0xfedb
movq %r12, %rax
cmpl $0x9, %r13d
je 0xfee3
movq %r12, %rax
cmpl $0x1b, %r13d
je 0xfee3
movq %r12, %rax
cmpl $0x5c, %r13d
je 0xfee3
movq %r12, %rax
cmpl $0x157, %r13d           # imm = 0x157
je 0xfee3
cmpl $0x173, %r13d           # imm = 0x173
jne 0xfeec
pushq $0x3
popq %rax
jmp 0xfee3
movq %r12, %rax
cmpl $0x4, %ecx
je 0xfea6
addq %rax, %r14
addq $0x4, %rbp
jmp 0xfe7e
xorl %eax, %eax
cmpl $0x20, %r13d
setb %al
leaq 0x1(,%rax,2), %rax
jmp 0xfee3
movq %r14, %rdi
callq 0xd4c0
movq %rax, %r15
testq %rax, %rax
je 0x1006f
leaq 0x1a0ea(%rip), %r13     # 0x2a004
movq %r15, %rbp
movslq (%rbx), %r12
testq %r12, %r12
je 0x10069
callq 0xd720
movq (%rax), %rax
testb $0x40, 0x1(%rax,%r12,2)
jne 0xff7e
leal -0x102(%r12), %eax
cmpl $0x5, %eax
jbe 0xff87
cmpl $0x9, %r12d
je 0xffeb
cmpl $0x1b, %r12d
je 0xffd3
cmpl $0x5c, %r12d
je 0xffe3
cmpl $0x157, %r12d           # imm = 0x157
je 0xffdb
cmpl $0x173, %r12d           # imm = 0x173
jne 0xff99
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x72, 0x2(%rbp)
jmp 0xffad
movb %r12b, (%rbp)
incq %rbp
jmp 0xfff5
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movw $0x645c, (%rbp)         # imm = 0x645C
jmp 0xfff1
cmpl $0x1a, %r12d
ja 0xfffe
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
orb $0x60, %r12b
movb %r12b, 0x2(%rbp)
addq $0x3, %rbp
jmp 0xfff5
movw $0x625c, (%rbp)         # imm = 0x625C
jmp 0xfff1
movw $0x755c, (%rbp)         # imm = 0x755C
jmp 0xfff1
movw $0x695c, (%rbp)         # imm = 0x695C
jmp 0xfff1
movw $0x6c5c, (%rbp)         # imm = 0x6C5C
jmp 0xfff1
movw $0x655c, (%rbp)         # imm = 0x655C
jmp 0xfff1
movw $0x725c, (%rbp)         # imm = 0x725C
jmp 0xfff1
movw $0x5c5c, (%rbp)         # imm = 0x5C5C
jmp 0xfff1
movw $0x745c, (%rbp)         # imm = 0x745C
addq $0x2, %rbp
addq $0x4, %rbx
jmp 0xff1d
addl $-0x1b, %r12d
cmpl $0x4, %r12d
ja 0x10060
leaq 0x1a00d(%rip), %rcx     # 0x2a01c
movslq (%rcx,%r12,4), %rax
addq %rcx, %rax
jmpq *%rax
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x5b, 0x2(%rbp)
jmp 0xffad
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x5f, 0x2(%rbp)
jmp 0xffad
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x5d, 0x2(%rbp)
jmp 0xffad
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x5e, 0x2(%rbp)
jmp 0xffad
movw $0x5e5c, (%rbp)         # imm = 0x5E5C
movb $0x5c, 0x2(%rbp)
jmp 0xffad
movb $0x7e, (%rbp)
jmp 0xff82
movb $0x0, -0x1(%r15,%r14)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq