// File: /workspace/github_c_makefile_star2_O1/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 0x6c6d8(%rip), %rbp     # 0x112aa1
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7dce
testq %r14, %r14
je 0xa664d
movl $0x5, %edx
movq %r15, %rdi
leaq 0x6c665(%rip), %rsi     # 0x112a50
callq 0x55b90
testl %eax, %eax
je 0xa6525
movl $0x5, %edx
movq %r15, %rdi
leaq 0x6c659(%rip), %rsi     # 0x112a60
callq 0x55b90
testl %eax, %eax
je 0xa652f
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c60e(%rip), %rsi     # 0x112a31
callq 0x55b90
testl %eax, %eax
je 0xa6525
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c5f9(%rip), %rsi     # 0x112a38
callq 0x55b90
testl %eax, %eax
je 0xa652f
movl $0x6, %edx
movq %r15, %rdi
leaq 0x6c5e4(%rip), %rsi     # 0x112a3f
callq 0x55b90
movb $0x1, %r13b
testl %eax, %eax
je 0xa6528
movl $0xf, %edx
movq %r15, %rdi
leaq 0x6c5cc(%rip), %rsi     # 0x112a46
callq 0x55b90
testl %eax, %eax
je 0xa6528
movl $0xf, %edx
movq %r15, %rdi
leaq 0x6c5c0(%rip), %rsi     # 0x112a56
callq 0x55b90
movb $0x1, %r12b
testl %eax, %eax
je 0xa6532
movl $0xd, %edx
movq %r15, %rdi
leaq 0x6c5b1(%rip), %rsi     # 0x112a66
callq 0x55b90
testl %eax, %eax
je 0xa6532
movl $0xa, %edx
movq %r15, %rdi
leaq 0x6c5a7(%rip), %rsi     # 0x112a74
callq 0x55b90
testl %eax, %eax
je 0xa6532
movl $0x9, %edx
movq %r15, %rdi
leaq 0x6c59a(%rip), %rsi     # 0x112a7f
callq 0x55b90
testl %eax, %eax
je 0xa6532
movl $0xb, %edx
movq %r15, %rdi
leaq 0x6c58c(%rip), %rsi     # 0x112a89
callq 0x55b90
testl %eax, %eax
je 0xa6532
movl $0xb, %edx
movq %r15, %rdi
leaq 0x6c580(%rip), %rsi     # 0x112a95
callq 0x55b90
testl %eax, %eax
sete %r12b
setne %al
jmp 0xa6534
movb $0x1, %r13b
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0xa6537
movb $0x1, %r12b
xorl %eax, %eax
xorl %r13d, %r13d
testb %al, %al
je 0xa6552
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %r14, %rax
incl %r12d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0xa6544
jmp 0xa6591
testb %r12b, %r12b
je 0xa6570
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movq %r14, %rax
addl $0x2, %r12d
cmpw $0x0, (%rax)
leaq 0x2(%rax), %rax
jne 0xa6560
jmp 0xa6591
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testb %r13b, %r13b
je 0xa6591
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
movq %r14, %rax
addl $0x4, %r12d
cmpl $0x0, (%rax)
leaq 0x4(%rax), %rax
jne 0xa6584
cmpq $0x0, 0xc987f(%rip)     # 0x16fe18
jne 0xa65a9
leaq 0x6c486(%rip), %rax     # 0x112a28
movq %rax, 0xc986f(%rip)     # 0x16fe18
movq 0xc9868(%rip), %r9      # 0x16fe18
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xa68d0
testl %eax, %eax
jns 0xa65e4
movq %r15, %rdi
movq %rbp, %rsi
callq 0x57bc0
movq %rbp, %r15
testl %eax, %eax
jne 0xa63c9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xa664f
movl %eax, %r13d
shrl $0x2, %r13d
leal 0x1(%r13), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa7dce
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0xa6607
movq (%rax), %rcx
jmp 0xa6609
xorl %ecx, %ecx
shll $0x2, %ebp
cmpq $0x0, 0xc9804(%rip)     # 0x16fe18
jne 0xa6624
leaq 0x6c40b(%rip), %rax     # 0x112a28
movq %rax, 0xc97f4(%rip)     # 0x16fe18
movq 0xc97ed(%rip), %r9      # 0x16fe18
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movl %ebp, %r8d
callq 0xa68d0
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