// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/gui/widgets/special/cursor.cpp
// Function: smooth::GUI::Cursor::GetDisplayCursorPositionFromVisual(smooth::String const&, int) const
S::Int S::GUI::Cursor::GetDisplayCursorPositionFromVisual(const String &line, Int promptPos) const
{
	FriBidiStrIndex	 length = line.Length();

	if (length == 0) return 0;

	Int		 position = 0;

	if (!Binary::IsFlagSet(container->GetFlags(), EDB_ASTERISK))
	{
		String	 string = line;

		if (Setup::useIconv && ContainsRTLCharacters(line))
		{
			FriBidiChar	*visual = new FriBidiChar [length + 1];
			FriBidiParType	 type = (IsRightToLeft() ? FRIBIDI_PAR_RTL : FRIBIDI_PAR_LTR);

			fribidi_log2vis((FriBidiChar *) string.ConvertTo("UCS-4LE"), length, &type, visual, NIL, NIL, NIL);

			visual[length] = 0;

			string.ImportFrom("UCS-4LE", (char *) visual);

			delete [] visual;
		}

		/* Convert tabs.
		 */
		Int	 offset = 0;

		for (Int i = 0; i < length; i++)
		{
			if (string[i] != '\t') continue;

			Int	 spaces = tabSize - i % tabSize;

			string  = string.Head(i).Append(String().FillN(' ', spaces)).Append(string.Tail(length - i - 1));
			length += spaces - 1;

			if (i < promptPos + offset) offset += spaces - 1;
		}

		if (!IsRightToLeft()) position += font.GetScaledTextSizeX(string.Head(	       promptPos + offset)) - visibleOffset;
		else		      position += font.GetScaledTextSizeX(string.Tail(length - promptPos - offset)) - visibleOffset;
	}
	else
	{
		position += font.GetScaledTextSizeX(String().FillN('*', promptPos)) - visibleOffset;
	}

	return position;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x58370
movq %rax, 0x8(%rsp)
testl %eax, %eax
je 0x905df
movq 0x190(%r14), %rax
movl 0x30(%rax), %edi
pushq $0x2
popq %rsi
callq 0x596b0
testb %al, %al
je 0x905e6
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5a180
pushq $0x2a
popq %rsi
movq %rbx, %rdi
movq 0x40(%rsp), %rdx
callq 0x58e70
leaq 0x140(%r14), %rdi
movq %rax, %rsi
callq 0x57870
movl %eax, %ebx
subl 0x5d0(%r14), %ebx
jmp 0x90828
xorl %ebx, %ebx
jmp 0x90832
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x58280
movq 0xd0d66(%rip), %rax     # 0x161360
cmpb $0x1, (%rax)
jne 0x9069f
movq %rbx, %rdi
callq 0x58660
testb %al, %al
je 0x9069f
movq 0x8(%rsp), %rcx
leal 0x1(%rcx), %eax
shlq $0x2, %rax
cmpl $-0x1, %ecx
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x577a0
movq %rax, %rbx
movq (%r14), %rax
movq %r14, %rdi
callq *0x160(%rax)
movzbl %al, %eax
orl $0x110, %eax            # imm = 0x110
movl %eax, 0x10(%rsp)
leaq 0x566bd(%rip), %rsi     # 0xe6d0d
leaq 0x28(%rsp), %rdi
callq 0x58b90
andq $0x0, (%rsp)
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x57120
movslq 0x8(%rsp), %rax
andl $0x0, (%rbx,%rax,4)
leaq 0x56683(%rip), %rsi     # 0xe6d0d
leaq 0x28(%rsp), %rdi
movq %rbx, %rdx
callq 0x57ab0
movq %rbx, %rdi
callq 0x572d0
pushq $-0x1
popq %r15
leaq 0x70(%rsp), %r12
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r14, 0x50(%rsp)
cmpl 0x8(%rsp), %ebp
jge 0x907b6
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x59cc0
cmpl $0x9, (%rax)
jne 0x907ac
movq %r15, 0x48(%rsp)
movq %rbx, %r15
movl 0x5e4(%r14), %r14d
movl %ebp, %eax
cltd
idivl %r14d
movl %edx, %ebx
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0x59e40
movq %r12, %r13
movq %r12, %rdi
xorl %esi, %esi
callq 0x5a180
subl %ebx, %r14d
movq %r13, %rdi
pushq $0x20
popq %rsi
movl %r14d, %edx
callq 0x58e70
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x573e0
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x48(%rsp), %rcx
leal (%rax,%rcx), %edx
leaq 0x58(%rsp), %r13
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x59220
movq %rbx, %rdi
movq %r13, %rsi
callq 0x573e0
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x56630
movq %r13, %rdi
callq 0x5a588
movq %r12, %rdi
callq 0x5a588
leaq 0x10(%rsp), %rdi
callq 0x5a588
movl %r14d, %eax
decl %eax
movq 0x8(%rsp), %rcx
addl %r14d, %ecx
decl %ecx
movq %rcx, 0x8(%rsp)
movq 0x40(%rsp), %rcx
addl %r15d, %ecx
cmpl %ecx, %ebp
movl $0x0, %ecx
cmovgel %ecx, %eax
addl %r15d, %eax
movl %eax, %ebx
movq 0x50(%rsp), %r14
movq 0x48(%rsp), %r15
incl %ebp
decl %r15d
jmp 0x906b1
movq (%r14), %rax
movq %r14, %rdi
callq *0x160(%rax)
addl 0x40(%rsp), %ebx
testb %al, %al
je 0x907f3
movq 0x8(%rsp), %rdx
subl %ebx, %edx
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x59220
leaq 0x140(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x57870
jmp 0x90815
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl %ebx, %edx
callq 0x59e40
leaq 0x140(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x57870
movl %eax, %ebx
subl 0x5d0(%r14), %ebx
leaq 0x10(%rsp), %rdi
callq 0x5a588
leaq 0x28(%rsp), %rdi
callq 0x5a588
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x90861
jmp 0x9085a
jmp 0x9085a
jmp 0x90861
jmp 0x90861
jmp 0x90861
jmp 0x90861
jmp 0x90861
jmp 0x90861
jmp 0x90861
movq %rax, %rbx
jmp 0x90882
jmp 0x90866
movq %rax, %rbx
jmp 0x9088c
movq %rax, %rbx
jmp 0x90878
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5a588
leaq 0x70(%rsp), %rdi
callq 0x5a588
leaq 0x10(%rsp), %rdi
callq 0x5a588
leaq 0x28(%rsp), %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x58260