// File: /workspace/github_c_makefile_star2_O3/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, 0x48(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x57180
testl %eax, %eax
je 0x93e5d
movl %eax, %r15d
movq 0x190(%r14), %rax
movl 0x30(%rax), %edi
movl $0x2, %esi
callq 0x583f0
testb %al, %al
je 0x93e64
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58e20
movq %rbx, %rdi
movl $0x2a, %esi
movq 0x48(%rsp), %rdx
callq 0x57bf0
leaq 0x140(%r14), %rdi
movq %rax, %rsi
callq 0x56730
movl %eax, %ebx
subl 0x5d0(%r14), %ebx
jmp 0x940c6
xorl %ebx, %ebx
jmp 0x940d0
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x570b0
movq 0xd74e8(%rip), %rax     # 0x16b360
cmpb $0x1, (%rax)
jne 0x93f20
movq %rbx, %rdi
callq 0x57460
testb %al, %al
je 0x93f20
leal 0x1(%r15), %eax
shlq $0x2, %rax
cmpl $-0x1, %r15d
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x56670
movq %rax, %rbx
movq (%r14), %rax
movq %r14, %rdi
callq *0x160(%rax)
movzbl %al, %eax
orl $0x110, %eax            # imm = 0x110
movl %eax, 0x18(%rsp)
leaq 0x62f3e(%rip), %rsi     # 0xf6e0d
leaq 0x30(%rsp), %rdi
callq 0x57940
movq $0x0, (%rsp)
leaq 0x18(%rsp), %rdx
movq %rax, %rdi
movl %r15d, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x56040
movslq %r15d, %rax
movl $0x0, (%rbx,%rax,4)
leaq 0x62f02(%rip), %rsi     # 0xf6e0d
leaq 0x30(%rsp), %rdi
movq %rbx, %rdx
callq 0x56950
movq %rbx, %rdi
callq 0x561e0
movq %r15, 0x8(%rsp)
testl %r15d, %r15d
jle 0x94046
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x70(%rsp), %r12
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
movq %r14, 0x50(%rsp)
leaq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0x58990
cmpl $0x9, (%rax)
jne 0x9402d
movl 0x5e4(%r14), %r14d
movl %ebp, %eax
cltd
idivl %r14d
movl %edx, %ebx
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
callq 0x58b00
leaq 0x58(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x58e20
subl %ebx, %r14d
movq %r15, %rdi
movl $0x20, %esi
movl %r14d, %edx
callq 0x57bf0
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x562f0
movq %rax, %rbx
movq 0x8(%rsp), %rax
leal (%rax,%r13), %edx
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x57f90
movq %rbx, %rdi
movq %r12, %rsi
callq 0x562f0
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x555f0
movq %r12, %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
movl %r14d, %eax
decl %eax
movq 0x8(%rsp), %rsi
addl %r14d, %esi
decl %esi
movq 0x48(%rsp), %rcx
movq 0x10(%rsp), %rdx
addl %edx, %ecx
cmpl %ecx, %ebp
movl $0x0, %ecx
cmovgel %ecx, %eax
addl %edx, %eax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %r14
jmp 0x94032
movq 0x8(%rsp), %rsi
incl %ebp
decl %r13d
movq %rsi, 0x8(%rsp)
cmpl %esi, %ebp
jl 0x93f49
jmp 0x9404f
movq $0x0, 0x10(%rsp)
movq (%r14), %rax
movq %r14, %rdi
callq *0x160(%rax)
movq 0x10(%rsp), %rdx
addl 0x48(%rsp), %edx
testb %al, %al
movq 0x8(%rsp), %rax
je 0x94093
subl %edx, %eax
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl %eax, %edx
callq 0x57f90
leaq 0x140(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0x56730
jmp 0x940b3
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x58b00
leaq 0x140(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0x56730
movl %eax, %ebx
subl 0x5d0(%r14), %ebx
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x940ff
jmp 0x940f6
jmp 0x940f6
jmp 0x940ff
jmp 0x940ff
jmp 0x940ff
jmp 0x940ff
jmp 0x940ff
jmp 0x940ff
movq %rax, %rbx
jmp 0x94120
jmp 0x940ff
jmp 0x94104
movq %rax, %rbx
jmp 0x9412a
movq %rax, %rbx
jmp 0x94116
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0x18(%rsp), %rdi
callq 0x59200
leaq 0x30(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090