// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/misc/string.cpp
// Function: smooth::String::Replace(smooth::String const&, smooth::String const&)
S::String &S::String::Replace(const String &str1, const String &str2)
{
	if (str1 == NIL) return *this;

	Int	 len1 = Length();
	Int	 len2 = str1.Length();
	Int	 len3 = str2.Length();

	for (Int i = 0; i <= len1 - len2; i++)
	{
		if (wcsncmp(wString + i, str1.wString, len2) == 0)
		{
			if (len2 != len3)
			{
				if (len3 > len2) wString.Resize(len1 + 1 + (len3 - len2));

				wmemmove(wString + i + len3, wString + i + len2, len1 - i - len2 + 1);

				len1 += (len3 - len2);
			}

			if (len3 > 0) wcsncpy(wString + i, str2.wString, len3);

			i += len3 - 1;
		}
	}

	return *this;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x20(%rsp)
movq %rdi, %r14
movq %rsi, 0x10(%rsp)
movl 0x10(%rsi), %ebx
testl %ebx, %ebx
je 0xa7482
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpl $0x0, (%rax)
je 0xa7482
xorl %r12d, %r12d
cmpl $0x0, 0x10(%r14)
movl $0x0, %r13d
je 0xa7307
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa72fd
movq (%rax), %rdi
jmp 0xa72ff
xorl %edi, %edi
callq 0x57220
movq %rax, %r13
testl %ebx, %ebx
je 0xa7328
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xa731e
movq (%rax), %rdi
jmp 0xa7320
xorl %edi, %edi
callq 0x57220
movq %rax, %r12
movq 0x20(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0xa7341
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xa734c
movq (%rax), %rdi
jmp 0xa734e
movq $0x0, 0x8(%rsp)
jmp 0xa7358
xorl %edi, %edi
callq 0x57220
movq %rax, 0x8(%rsp)
cmpl %r12d, %r13d
jl 0xa7482
movslq %r12d, %rbx
movq 0x8(%rsp), %rax
movl %eax, %ecx
subl %r12d, %ecx
movq %rcx, 0x38(%rsp)
incl %ecx
movq %rcx, 0x28(%rsp)
movslq %eax, %rcx
movl %ecx, %eax
movq %rax, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
leal -0x1(%rcx), %eax
movl %eax, 0x1c(%rsp)
xorl %ebp, %ebp
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa73a0
movq (%rax), %rax
jmp 0xa73a2
xorl %eax, %eax
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
je 0xa73b5
movq (%rcx), %rsi
jmp 0xa73b7
xorl %esi, %esi
movslq %ebp, %r15
leaq (%rax,%r15,4), %rdi
movq %rbx, %rdx
callq 0x572f0
testl %eax, %eax
jne 0xa746f
cmpl %r12d, 0x8(%rsp)
je 0xa7431
jle 0xa73e8
movq 0x28(%rsp), %rax
leal (%rax,%r13), %esi
movq %r14, %rdi
callq 0xa7dce
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0xa73f6
movq (%rcx), %rax
jmp 0xa73f8
xorl %eax, %eax
testq %rcx, %rcx
je 0xa7402
movq (%rcx), %rcx
jmp 0xa7404
xorl %ecx, %ecx
leaq (%rax,%r15,4), %rax
movq 0x30(%rsp), %rdx
leaq (%rax,%rdx,4), %rdi
leaq (%rcx,%r15,4), %rax
leaq (%rax,%rbx,4), %rsi
leal (%r12,%r15), %eax
negl %eax
addl %r13d, %eax
incl %eax
movslq %eax, %rdx
callq 0x56c80
addl 0x38(%rsp), %r13d
cmpl $0x0, 0x8(%rsp)
jle 0xa746b
movq 0x8(%r14), %rax
testq %rax, %rax
je 0xa7446
movq (%rax), %rax
jmp 0xa7448
xorl %eax, %eax
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
je 0xa745b
movq (%rcx), %rsi
jmp 0xa745d
xorl %esi, %esi
leaq (%rax,%r15,4), %rdi
movq 0x40(%rsp), %rdx
callq 0x58ce0
addl 0x1c(%rsp), %ebp
leal 0x1(%rbp), %eax
movl %r13d, %ecx
subl %r12d, %ecx
cmpl %ecx, %ebp
movl %eax, %ebp
jl 0xa7392
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq