// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, (%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x5a180
leaq 0x5bdf2(%rip), %rsi     # 0x1021c6
movq %r14, %rdi
callq 0x58b90
leaq 0x5b75e(%rip), %rsi     # 0x101b41
leaq 0x10(%rsp), %rdi
movq %rax, %rdx
callq 0x57ab0
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x5a180
leaq 0x10(%rsp), %rdi
callq 0x58370
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %eax
movl %eax, 0xc(%rsp)
leaq 0x40(%rsp), %r12
leaq 0x50(%rsp), %rbx
xorl %ebp, %ebp
cmpl %r15d, 0xc(%rsp)
je 0xa6556
leaq 0x10(%rsp), %rdi
movl %r15d, %esi
callq 0x59cc0
movl (%rax), %r13d
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0xa653e
movl %r13d, %eax
andl $-0x21, %eax
addl $-0x41, %eax
cmpl $0x1a, %eax
jb 0xa653e
leal -0x2d(%r13), %eax
cmpl $0x2, %eax
jb 0xa653e
cmpl $0x5f, %r13d
je 0xa653e
cmpl $0x7e, %r13d
je 0xa653e
cmpb $0x0, 0x8(%rsp)
je 0xa651d
movslq %r13d, %rsi
movq %r12, %r13
movq %r12, %rdi
callq 0x5a3d0
movq %rbx, %r14
movq %rbx, %rdi
movq %r13, %rsi
pushq $0x2
popq %rdx
callq 0x589c0
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x56e80
movq %r14, %rdi
callq 0x5a588
movq %r13, %rdi
callq 0x5a0b0
movq (%rsp), %rdi
movl %ebp, %esi
callq 0x59cc0
movl $0x25, (%rax)
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x59cc0
leal 0x1(%rbp), %esi
movl (%rax), %r13d
movq (%rsp), %rdi
callq 0x59cc0
movl %r13d, (%rax)
leaq 0x28(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x59cc0
leal 0x2(%rbp), %esi
movl (%rax), %r13d
movq (%rsp), %rdi
callq 0x59cc0
addl $0x3, %ebp
movl %r13d, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x5a588
jmp 0xa654e
leal -0x21(%r13), %eax
cmpl $0x3c, %eax
ja 0xa6484
movabsq $0x14000000d6004fed, %rcx # imm = 0x14000000D6004FED
btq %rax, %rcx
jae 0xa6484
movq (%rsp), %rdi
movl %ebp, %esi
callq 0x59cc0
incl %ebp
movl %r13d, (%rax)
incl %r15d
jmp 0xa641e
leaq 0x10(%rsp), %rdi
callq 0x5a588
movq (%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa65a9
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x5a588
jmp 0xa6587
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x5a0b0
jmp 0xa65ac
jmp 0xa65a9
movq %rax, %r14
jmp 0xa65b5
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x5a588
jmp 0xa65ac
movq %rax, %r14
movq (%rsp), %rdi
callq 0x5a588
leaq 0x10(%rsp), %rdi
callq 0x5a588
movq %r14, %rdi
callq 0x58260
nop