// File: /workspace/github_c_makefile_star2_O1/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 0x944c5
movl %eax, %r15d
movq 0x190(%r14), %rax
movl 0x30(%rax), %edi
movl $0x2, %esi
callq 0x583f0
testb %al, %al
je 0x944cc
leaq 0x28(%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 0x9472f
xorl %ebx, %ebx
jmp 0x94739
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x570b0
movq 0xd7e80(%rip), %rax     # 0x16c360
cmpb $0x1, (%rax)
movq %r14, 0x40(%rsp)
jne 0x94595
movq %rbx, %rdi
callq 0x57460
testb %al, %al
je 0x94595
movslq %r15d, %r14
leaq 0x4(,%r14,4), %rax
cmpl $-0x1, %r15d
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x56670
movq %rax, %rbx
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
callq *0x160(%rax)
movzbl %al, %eax
orl $0x110, %eax            # imm = 0x110
movl %eax, 0x10(%rsp)
leaq 0x63728(%rip), %rsi     # 0xf7c69
leaq 0x28(%rsp), %rdi
callq 0x57940
movq $0x0, (%rsp)
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
movl %r15d, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x56040
movl $0x0, (%rbx,%r14,4)
leaq 0x636ee(%rip), %rsi     # 0xf7c69
leaq 0x28(%rsp), %rdi
movq %rbx, %rdx
callq 0x56950
movq %rbx, %rdi
callq 0x561e0
movq 0x40(%rsp), %r14
testl %r15d, %r15d
jle 0x946b2
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x70(%rsp), %r12
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
callq 0x58990
cmpl $0x9, (%rax)
jne 0x946a2
movq %r15, 0x50(%rsp)
movq %r12, %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 0x58b00
leaq 0x58(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x58e20
subl %ebx, %r14d
movq %r12, %rdi
movl $0x20, %esi
movl %r14d, %edx
callq 0x57bf0
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x562f0
movq %rax, %rbx
movq 0x50(%rsp), %rax
leal (%rax,%r13), %edx
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x57f90
movq %rbx, %rdi
movq %r15, %rsi
callq 0x562f0
movq %r15, %r12
leaq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x555f0
movq %r12, %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0x10(%rsp), %rdi
callq 0x59200
movl %r14d, %eax
decl %eax
movq 0x50(%rsp), %r15
addl %r14d, %r15d
decl %r15d
movq 0x48(%rsp), %rcx
movq 0x8(%rsp), %rdx
addl %edx, %ecx
cmpl %ecx, %ebp
movl $0x0, %ecx
cmovgel %ecx, %eax
addl %edx, %eax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %r14
incl %ebp
decl %r13d
cmpl %r15d, %ebp
jl 0x945b4
jmp 0x946bb
movq $0x0, 0x8(%rsp)
movq (%r14), %rax
movq %r14, %rdi
callq *0x160(%rax)
movq 0x8(%rsp), %rdx
addl 0x48(%rsp), %edx
testb %al, %al
je 0x946fc
subl %edx, %r15d
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl %r15d, %edx
callq 0x57f90
leaq 0x140(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x56730
jmp 0x9471c
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x58b00
leaq 0x140(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x56730
movl %eax, %ebx
subl 0x5d0(%r14), %ebx
leaq 0x10(%rsp), %rdi
callq 0x59200
leaq 0x28(%rsp), %rdi
callq 0x59200
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x94768
jmp 0x9475f
jmp 0x9475f
jmp 0x94768
jmp 0x94768
jmp 0x94768
jmp 0x94768
jmp 0x94768
jmp 0x94768
movq %rax, %rbx
jmp 0x94789
jmp 0x94768
jmp 0x9476d
movq %rax, %rbx
jmp 0x94793
movq %rax, %rbx
jmp 0x9477f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59200
leaq 0x58(%rsp), %rdi
callq 0x59200
leaq 0x10(%rsp), %rdi
callq 0x59200
leaq 0x28(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090
nop