// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/misc/string.cpp
// Function: smooth::String::ConvertTo(char const*) const
char *S::String::ConvertTo(const char *encoding) const
{
	Int	 size = Length() + 1;

	if (size == 1) return NIL;

	Int	 bufferSize = ConvertString((char *) (wchar_t *) wString, size * sizeof(wchar_t), GetInternalFormat(), NIL, 0, encoding);

	if (bufferSize == -1) bufferSize = ConvertString((char *) (wchar_t *) wString, size * sizeof(wchar_t), GetInternalFormat(), NIL, 0, "ISO-8859-1");

	char	*buffer = NIL;

	if (bufferSize <= 0)
	{
		Int	 length = Length();

		buffer = new char [length + 1];

		ConvertString((char *) (wchar_t *) wString, size * sizeof(wchar_t), GetInternalFormat(), buffer, length + 1, encoding);

		for (Int i = -bufferSize; i < length; i++) buffer[i] = '?';

		buffer[length] = 0;
	}
	else
	{
		buffer = new char [bufferSize + 1];

		ConvertString((char *) (wchar_t *) wString, size * sizeof(wchar_t), GetInternalFormat(), buffer, bufferSize + 1, encoding);
	}

	AddTemporaryBuffer(buffer);

	return buffer;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, 0x10(%rdi)
je 0xa6121
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa6125
movq (%rax), %rdi
jmp 0xa6127
xorl %eax, %eax
jmp 0xa612c
xorl %edi, %edi
callq 0x57220
testl %eax, %eax
je 0xa613e
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0xa6146
movq (%rcx), %rdi
jmp 0xa6148
xorl %r12d, %r12d
jmp 0xa62cd
xorl %edi, %edi
leal 0x4(,%rax,4), %ebp
cmpq $0x0, 0xc9cc1(%rip)     # 0x16fe18
jne 0xa6167
leaq 0x6c8c8(%rip), %rax     # 0x112a28
movq %rax, 0xc9cb1(%rip)     # 0x16fe18
movq 0xc9caa(%rip), %rdx     # 0x16fe18
movl %ebp, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0xa68d0
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0xa61ca
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa6193
movq (%rax), %rdi
jmp 0xa6195
xorl %edi, %edi
cmpq $0x0, 0xc9c7b(%rip)     # 0x16fe18
jne 0xa61ad
leaq 0x6c882(%rip), %rax     # 0x112a28
movq %rax, 0xc9c6b(%rip)     # 0x16fe18
movq 0xc9c64(%rip), %rdx     # 0x16fe18
leaq 0x6c8e6(%rip), %r9      # 0x112aa1
movl %ebp, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xa68d0
movl %eax, %r15d
testl %r15d, %r15d
jle 0xa61eb
incl %r15d
movq %r15, %rdi
callq 0x56670
movq %rax, %r12
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa6204
movq (%rax), %rdi
jmp 0xa6206
cmpl $0x0, 0x10(%r14)
movq %rbx, (%rsp)
je 0xa623a
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa623f
movq (%rax), %rdi
jmp 0xa6241
xorl %edi, %edi
cmpq $0x0, 0xc9c0a(%rip)     # 0x16fe18
jne 0xa621e
leaq 0x6c811(%rip), %rax     # 0x112a28
movq %rax, 0xc9bfa(%rip)     # 0x16fe18
movq 0xc9bf3(%rip), %rdx     # 0x16fe18
movl %ebp, %esi
movq %r12, %rcx
movl %r15d, %r8d
movq %rbx, %r9
callq 0xa68d0
jmp 0xa62c5
xorl %r13d, %r13d
jmp 0xa6249
xorl %edi, %edi
callq 0x57220
movq %rax, %r13
leal 0x1(%r13), %ebx
movslq %ebx, %rdi
callq 0x56670
movq %rax, %r12
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa6266
movq (%rax), %rdi
jmp 0xa6268
xorl %edi, %edi
cmpq $0x0, 0xc9ba8(%rip)     # 0x16fe18
jne 0xa6280
leaq 0x6c7af(%rip), %rax     # 0x112a28
movq %rax, 0xc9b98(%rip)     # 0x16fe18
movq 0xc9b91(%rip), %rdx     # 0x16fe18
movl %ebp, %esi
movq %r12, %rcx
movl %ebx, %r8d
movq (%rsp), %r9
callq 0xa68d0
movl %r15d, %eax
negl %eax
cmpl %eax, %r13d
jle 0xa62bd
cltq
movq %r12, %rdi
addq %rax, %rdi
leal (%r15,%r13), %edx
decl %edx
incq %rdx
movl $0x3f, %esi
callq 0x55f20
movslq %r13d, %rax
movb $0x0, (%r12,%rax)
movq %r12, %rdi
callq 0x588c0
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop