// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/misc/encoding/urlencode.cpp
// Function: smooth::Encoding::URLEncode::Encode(smooth::String const&, bool)
S::String S::Encoding::URLEncode::Encode(const String &string, Bool encodeReserved)
{
	/* Convert input string to UTF-8.
	 */
	String	 utf8;

	utf8.ImportFrom("ISO-8859-1", string.ConvertTo("UTF-8"));

	/* Encode UTF-8 string using URL encode.
	 */
	String	 encoded;
	Int	 length = utf8.Length();

	for (Int i = 0, e = 0; i < length; i++)
	{
		wchar_t	 value = utf8[i];

		if ((value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z') || (value >= '0' && value <= '9') ||
		    (value == '-' || value == '_' || value == '.' || value == '~') ||
		    (!encodeReserved && (value == '!' || value == '*' || value == '\'' || value == '(' || value == ')' || value == ';' ||
					 value == ':' || value == '@' || value == '&'  || value == '=' || value == '+' || value == '$' ||
					 value == ',' || value == '/' || value == '?'  || value == '#' || value == '[' || value == ']')))
		{
			encoded[e++] = value;
		}
		else
		{
			String	 hex = Number((Int64) value).ToHexString(2).ToUpper();

			encoded[e++] = '%';
			encoded[e++] = hex[0];
			encoded[e++] = hex[1];
		}
	}

	return encoded;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0x67427(%rip), %rsi     # 0x1122d6
movq %r14, %rdi
callq 0x57940
leaq 0x66d83(%rip), %rsi     # 0x111c41
leaq 0x10(%rsp), %rdi
movq %rax, %rdx
callq 0x56950
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
leaq 0x10(%rsp), %rdi
callq 0x57180
movl %eax, %r14d
testl %eax, %eax
jle 0xab02a
xorl %r15d, %r15d
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x58990
movl (%rax), %r13d
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0xab00e
movl %r13d, %eax
andl $-0x21, %eax
addl $-0x41, %eax
cmpl $0x1a, %eax
jb 0xab00e
leal -0x2d(%r13), %eax
cmpl $0x2, %eax
jb 0xab00e
cmpl $0x5f, %r13d
je 0xab00e
cmpl $0x7e, %r13d
je 0xab00e
cmpb $0x0, 0xc(%rsp)
je 0xaafed
movslq %r13d, %rsi
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0x59050
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl $0x2, %edx
callq 0x57780
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x55dc0
movq %r12, %rdi
callq 0x59200
leaq 0x40(%rsp), %rdi
callq 0x58d60
movq %rbx, %rdi
movl %r15d, %esi
callq 0x58990
movl $0x25, (%rax)
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x58990
leal 0x1(%r15), %esi
movl (%rax), %r13d
movq %rbx, %rdi
callq 0x58990
movl %r13d, (%rax)
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x58990
leal 0x2(%r15), %esi
movl (%rax), %r13d
movq %rbx, %rdi
callq 0x58990
addl $0x3, %r15d
movl %r13d, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x59200
jmp 0xab01f
leal -0x21(%r13), %eax
cmpl $0x3c, %eax
ja 0xaaf49
movabsq $0x14000000d6004fed, %rcx # imm = 0x14000000D6004FED
btq %rax, %rcx
jae 0xaaf49
movq %rbx, %rdi
movl %r15d, %esi
callq 0x58990
incl %r15d
movl %r13d, (%rax)
incl %ebp
cmpl %ebp, %r14d
jne 0xaaeef
leaq 0x10(%rsp), %rdi
callq 0x59200
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xab07c
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x59200
jmp 0xab05a
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x58d60
jmp 0xab07f
jmp 0xab07c
movq %rax, %r14
jmp 0xab087
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x59200
jmp 0xab07f
movq %rax, %r14
movq %rbx, %rdi
callq 0x59200
leaq 0x10(%rsp), %rdi
callq 0x59200
movq %r14, %rdi
callq 0x57090
nop