// File: ticky[P]ps2iconsys/src/ps2_iconsys.cpp
// Function: IconSys::EncodeTitle(char const*, unsigned char*)
void IconSys::EncodeTitle(char const* str_in, unsigned char* str_out) {
	int sjis_count = 0;
	for(size_t i=0; i<strlen(str_in); i++) {
		switch(str_in[i]) {
			case ' ':
				str_out[sjis_count++] = 0x82;
				str_out[sjis_count++] = 0x3F;
				break;
			case ':':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x46;
				break;
			case '/':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x5E;
				break;
			case '(':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x69;
				break;
			case ')':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x6A;
				break;
			case '[':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x6D;
				break;
			case ']':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x6E;
				break;
			case '{':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x6F;
				break;
			case '}':
				str_out[sjis_count++] = 0x81;
				str_out[sjis_count++] = 0x70;
				break;
			default:
				if((str_in[i] >= 48) && (str_in[i] <= 90)) {
					//digits (0-9), capital letters (A-Z)
					str_out[sjis_count++] = 0x82;
					str_out[sjis_count++] = str_in[i] + 31;
				} else if((str_in[i] >= 97) && (str_in[i] <= 122)) {
					//lowercase letters (a-z)
					str_out[sjis_count++] = 0x82;
					str_out[sjis_count++] = str_in[i] + 32;
				}
				break;
		}
	}
	for(; sjis_count < 68; sjis_count++) {
		str_out[sjis_count] = 0;
	}	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20e0
movq %rax, %rcx
movq -0x28(%rbp), %rax
cmpq %rcx, %rax
jae 0x7f03
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
subl $0x20, %eax
je 0x7c75
jmp 0x7c06
movl -0x2c(%rbp), %eax
subl $0x28, %eax
je 0x7d08
jmp 0x7c14
movl -0x2c(%rbp), %eax
subl $0x29, %eax
je 0x7d39
jmp 0x7c22
movl -0x2c(%rbp), %eax
subl $0x2f, %eax
je 0x7cd7
jmp 0x7c30
movl -0x2c(%rbp), %eax
subl $0x3a, %eax
je 0x7ca6
jmp 0x7c3a
movl -0x2c(%rbp), %eax
subl $0x5b, %eax
je 0x7d6a
jmp 0x7c48
movl -0x2c(%rbp), %eax
subl $0x5d, %eax
je 0x7d9b
jmp 0x7c56
movl -0x2c(%rbp), %eax
subl $0x7b, %eax
je 0x7dcc
jmp 0x7c64
movl -0x2c(%rbp), %eax
subl $0x7d, %eax
je 0x7dfd
jmp 0x7e2e
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7e, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x3f, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x46, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x5e, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x69, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x6a, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x6d, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x6e, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x6f, (%rax,%rcx)
jmp 0x7ef0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $0x70, (%rax,%rcx)
jmp 0x7ef0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jl 0x7e8e
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5a, %eax
jg 0x7e8e
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7e, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $0x1f, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x7eee
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x61, %eax
jl 0x7eec
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7a, %eax
jg 0x7eec
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movb $-0x7e, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
addl $0x20, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x7eee
jmp 0x7ef0
jmp 0x7ef2
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x7bcf
jmp 0x7f05
cmpl $0x44, -0x14(%rbp)
jge 0x7f22
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7f05
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)