// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/misc/string.cpp
// Function: smooth::String::ImportFrom(char const*, char const*)
S::Int S::String::ImportFrom(const char *format, const char *str)
{
	Clean();

	if (str == NIL) return Success();

	Int	 width = 1;

	if	(strncmp(format, "UCS-4", 5)		== 0) width = 4;
	else if	(strncmp(format, "UCS-2", 5)		== 0) width = 2;
	else if	(strncmp(format, "UTF-32", 6)		== 0) width = 4;
	else if	(strncmp(format, "UTF-16", 6)		== 0) width = 2;
	else if	(strncmp(format, "CSUCS4", 6)		== 0) width = 4;
	else if	(strncmp(format, "ISO-10646-UCS-4", 15)	== 0) width = 4;
	else if	(strncmp(format, "ISO-10646-UCS-2", 15)	== 0) width = 2;
	else if	(strncmp(format, "UNICODELITTLE", 13)	== 0) width = 2;
	else if	(strncmp(format, "UNICODEBIG", 10)	== 0) width = 2;
	else if	(strncmp(format, "CSUNICODE", 9)	== 0) width = 2;
	else if	(strncmp(format, "UNICODE-1-1", 11)	== 0) width = 2;
	else if	(strncmp(format, "CSUNICODE11", 11)	== 0) width = 2;

	Int	 length = -1;

	if	(width == 1) while (true) { if (((char  *) str)[++length] == 0) { length *= 1; break; } }
	else if (width == 2) while (true) { if (((short *) str)[++length] == 0) { length *= 2; break; } }
	else if (width == 4) while (true) { if (((int   *) str)[++length] == 0) { length *= 4; break; } }

	Int	 size = ConvertString(str, length, format, NIL, 0, GetInternalFormat());

	if	(size < 0 && strcmp(format, "ISO-8859-1") != 0) return ImportFrom("ISO-8859-1", str);
	else if (size < 0)					return Error();

	size = size / sizeof(wchar_t) + 1;

	wString.Resize(size);

	ConvertString(str, length, format, (char *) (wchar_t *) wString, size * sizeof(wchar_t), GetInternalFormat());

	wString[size - 1] = 0;

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x6c3c8(%rip), %rbp     # 0x111c41
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7094
testq %r14, %r14
je 0xa5ac4
movl $0x5, %edx
movq %r15, %rdi
leaq 0x6c355(%rip), %rsi     # 0x111bf0
callq 0x55b90
testl %eax, %eax
je 0xa59e3
movl $0x5, %edx
movq %r15, %rdi
leaq 0x6c349(%rip), %rsi     # 0x111c00
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c2fe(%rip), %rsi     # 0x111bd1
callq 0x55b90
testl %eax, %eax
je 0xa59e3
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c2e9(%rip), %rsi     # 0x111bd8
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c2d4(%rip), %rsi     # 0x111bdf
callq 0x55b90
testl %eax, %eax
je 0xa59e3
movl $0xf, %edx
movq %r15, %rdi
leaq 0x6c2bf(%rip), %rsi     # 0x111be6
callq 0x55b90
testl %eax, %eax
je 0xa59e3
movl $0xf, %edx
movq %r15, %rdi
leaq 0x6c2b3(%rip), %rsi     # 0x111bf6
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0xd, %edx
movq %r15, %rdi
leaq 0x6c2a7(%rip), %rsi     # 0x111c06
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0xa, %edx
movq %r15, %rdi
leaq 0x6c299(%rip), %rsi     # 0x111c14
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0x9, %edx
movq %r15, %rdi
leaq 0x6c28c(%rip), %rsi     # 0x111c1f
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0xb, %edx
movq %r15, %rdi
leaq 0x6c27e(%rip), %rsi     # 0x111c29
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0xb, %edx
movq %r15, %rdi
leaq 0x6c272(%rip), %rsi     # 0x111c35
callq 0x55b90
testl %eax, %eax
je 0xa59fb
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %r14, %rax
incl %r12d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0xa59d5
jmp 0xa5a12
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
movq %r14, %rax
addl $0x4, %r12d
cmpl $0x0, (%rax)
leaq 0x4(%rax), %rax
jne 0xa59ec
jmp 0xa5a12
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movq %r14, %rax
addl $0x2, %r12d
cmpw $0x0, (%rax)
leaq 0x2(%rax), %rax
jne 0xa5a04
movq 0xc93ff(%rip), %r9      # 0x16ee18
testq %r9, %r9
jne 0xa5a2c
leaq 0x6c1a3(%rip), %r9      # 0x111bc8
movq %r9, 0xc93ec(%rip)      # 0x16ee18
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xa5d42
testl %eax, %eax
jns 0xa5a60
movq %r15, %rdi
movq %rbp, %rsi
callq 0x57bc0
movq %rbp, %r15
testl %eax, %eax
jne 0xa5879
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xa5ac6
movl %eax, %r13d
shrl $0x2, %r13d
leal 0x1(%r13), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa7094
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0xa5a83
movq (%rax), %rcx
jmp 0xa5a85
xorl %ecx, %ecx
shll $0x2, %ebp
movq 0xc9389(%rip), %r9      # 0x16ee18
testq %r9, %r9
jne 0xa5aa2
leaq 0x6c12d(%rip), %r9      # 0x111bc8
movq %r9, 0xc9376(%rip)      # 0x16ee18
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movl %ebp, %r8d
callq 0xa5d42
movq 0x8(%rbx), %rax
movq (%rax), %rax
movl %r13d, %ecx
movl $0x0, (%rax,%rcx,4)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop