// File: lvandeve[P]base256/base256.cpp
// Function: JavaString::encodeChar[abi:cxx11](unsigned char, unsigned char, unsigned char)
std::string encodeChar(unsigned char c, unsigned char prev, unsigned char next) {
    if(c == '\b') return "\\b";
    if(c == '\f') return "\\f";
    if(c == '\n') return "\\n";
    if(c == '\r') return "\\r";
    if(c == '\t') return "\\t";
    if(c == '\\') return "\\\\";
    if(c == '"') return "\\\"";
    if(c >= 32 && c < 127) {
      std::string result;
      result += c;
      return result;
    }
    // octal: we work byte-based, so don't use \u unicode escapes, which are longer
    bool digitnext = (next >= '0' && next <= '7');
    int o0 = (c >> 6) & 7;
    int o1 = (c >> 3) & 7;
    int o2 = (c >> 0) & 7;
    std::string result = "\\";
    // shorten if possible, e.g. many nulls in a row will be \0\0\0\0 instead of \000\\000\000\000
    // using \0 and other less than 3 digit codes is only ok if no real octal digit after it, else the next character becomes part of the code
    if(c < 8 && !digitnext) {
      result += ('0' + o2);
    } else if (c < 64 && !digitnext) {
      result += ('0' + o1);
      result += ('0' + o2);
    } else {
      result += ('0' + o0);
      result += ('0' + o1);
      result += ('0' + o2);
    }
    return result;
  }

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x48(%rsp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, 0x50(%rsp)
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movb %dl, 0x87(%rsp)
movb %cl, 0x86(%rsp)
movb %al, 0x85(%rsp)
movzbl 0x87(%rsp), %eax
cmpl $0x8, %eax
jne 0x1b175
leaq 0x84(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rdx
leaq 0x70af(%rip), %rsi      # 0x221eb
callq 0x53d0
jmp 0x1b143
leaq 0x84(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x84(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0xc, %eax
jne 0x1b1d5
leaq 0x73(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x38(%rsp), %rdx
leaq 0x704c(%rip), %rsi      # 0x221ee
callq 0x53d0
jmp 0x1b1a9
leaq 0x73(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x73(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0xa, %eax
jne 0x1b235
leaq 0x72(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rdx
leaq 0x6fef(%rip), %rsi      # 0x221f1
callq 0x53d0
jmp 0x1b209
leaq 0x72(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x72(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0xd, %eax
jne 0x1b295
leaq 0x71(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rdx
leaq 0x6f92(%rip), %rsi      # 0x221f4
callq 0x53d0
jmp 0x1b269
leaq 0x71(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x71(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0x9, %eax
jne 0x1b2f5
leaq 0x70(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rdx
leaq 0x6f35(%rip), %rsi      # 0x221f7
callq 0x53d0
jmp 0x1b2c9
leaq 0x70(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0x5c, %eax
jne 0x1b355
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rdx
leaq 0x6edb(%rip), %rsi      # 0x221fd
callq 0x53d0
jmp 0x1b329
leaq 0x6f(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x6f(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0x22, %eax
jne 0x1b3b5
leaq 0x6e(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rdx
leaq 0x6e7e(%rip), %rsi      # 0x22200
callq 0x53d0
jmp 0x1b389
leaq 0x6e(%rsp), %rdi
callq 0x5300
jmp 0x1b5c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x6e(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0x20, %eax
jl 0x1b42c
movzbl 0x87(%rsp), %eax
cmpl $0x7f, %eax
jge 0x1b42c
movq 0x48(%rsp), %rdi
movb $0x0, 0x6d(%rsp)
callq 0x5400
movq 0x48(%rsp), %rdi
movsbl 0x87(%rsp), %esi
callq 0x51d0
jmp 0x1b3f2
movb $0x1, 0x6d(%rsp)
testb $0x1, 0x6d(%rsp)
jne 0x1b427
jmp 0x1b41d
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x5558
jmp 0x1b5d5
movq 0x48(%rsp), %rdi
callq 0x5558
jmp 0x1b5c8
movzbl 0x85(%rsp), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, 0xf(%rsp)
jl 0x1b451
movzbl 0x85(%rsp), %eax
cmpl $0x37, %eax
setle %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x6c(%rsp)
movzbl 0x87(%rsp), %eax
shrl $0x6, %eax
movl %eax, 0x68(%rsp)
movzbl 0x87(%rsp), %eax
shrl $0x3, %eax
andl $0x7, %eax
movl %eax, 0x64(%rsp)
movzbl 0x87(%rsp), %eax
andl $0x7, %eax
movl %eax, 0x60(%rsp)
movb $0x0, 0x5f(%rsp)
leaq 0x5e(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x54f0
movq 0x48(%rsp), %rdi
movq (%rsp), %rdx
leaq 0x6d50(%rip), %rsi      # 0x221fe
callq 0x53d0
jmp 0x1b4b5
leaq 0x5e(%rsp), %rdi
callq 0x5300
movzbl 0x87(%rsp), %eax
cmpl $0x8, %eax
jge 0x1b528
testb $0x1, 0x6c(%rsp)
jne 0x1b528
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b4e9
jmp 0x1b5b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
leaq 0x5e(%rsp), %rdi
callq 0x5300
jmp 0x1b5d5
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x78(%rsp)
movl %eax, 0x74(%rsp)
callq 0x5558
jmp 0x1b5d5
movzbl 0x87(%rsp), %eax
cmpl $0x40, %eax
jge 0x1b56a
testb $0x1, 0x6c(%rsp)
jne 0x1b56a
movq 0x48(%rsp), %rdi
movl 0x64(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b552
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b568
jmp 0x1b5ae
movq 0x48(%rsp), %rdi
movl 0x68(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b580
movq 0x48(%rsp), %rdi
movl 0x64(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b596
movq 0x48(%rsp), %rdi
movl 0x60(%rsp), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x51d0
jmp 0x1b5ac
jmp 0x1b5ae
jmp 0x1b5b0
movb $0x1, 0x5f(%rsp)
testb $0x1, 0x5f(%rsp)
jne 0x1b5c6
movq 0x48(%rsp), %rdi
callq 0x5558
jmp 0x1b5c8
movq 0x50(%rsp), %rax
addq $0x98, %rsp
retq
movq 0x78(%rsp), %rdi
callq 0x54e0
nop