// File: /workspace/github_c_makefile_star2_O2/cglindkamp[P]dfm/src/commandline.c
// Function: commandline_updateview
static void commandline_updateview(struct commandline *commandline)
{
	size_t length = wcslen(commandline->buffer);
	int promptlength = 1;
	int windowwidth = getmaxx(commandline->window);

	if(wcswidth(commandline->buffer, -1) < windowwidth - promptlength)
		commandline->first = 0;
	else if(commandline->cursor_pos < commandline->first)
		commandline->first = commandline->cursor_pos;
	else if(wcswidth(commandline->buffer + commandline->first, commandline->cursor_pos - commandline->first) >= windowwidth - promptlength) {
		while(wcwidth(*(commandline->buffer + commandline->first)) < 1 ||
		      wcswidth(commandline->buffer + commandline->first, commandline->cursor_pos - commandline->first) >= windowwidth - promptlength) {
			commandline->first++;
		}
	} else {
		int currentwidth = wcswidth(commandline->buffer + commandline->first, commandline->cursor_pos - commandline->first + 1);
		int targetwidth = windowwidth - promptlength - (commandline->cursor_pos == length ? 1 : 0);
		int first = commandline->first;
		int firstwidth = 0;

		while(first > 0 && currentwidth + firstwidth < targetwidth) {
			currentwidth += firstwidth;

			do {
				first--;
				firstwidth = wcwidth(commandline->buffer[first]);
			} while(first > 0 && firstwidth < 1);

			if(currentwidth + firstwidth <= targetwidth)
				commandline->first = first;
		}
	}

	size_t distance = 0;
	int width = 0;
	int currentwidth = 0;
	while(commandline->first + distance < length && width + currentwidth <= windowwidth - promptlength) {
		width += currentwidth;
		currentwidth = wcwidth(*(commandline->buffer + commandline->first + distance));
		distance++;
	}

	werase(commandline->window);
	mvwaddwstr(commandline->window, 0, 0, commandline->prompt);
	waddnwstr(commandline->window, commandline->buffer + commandline->first, distance);
	wrefresh(commandline->window);
	commandline_updatecursor(commandline);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x18(%rdi), %r15
movq %r15, %rdi
callq 0x3280
movq %rax, %r14
movq (%rbx), %rax
testq %rax, %rax
je 0x55f4
movswl 0x6(%rax), %r12d
jmp 0x55f8
pushq $-0x2
popq %r12
pushq $-0x1
popq %rsi
movq %r15, %rdi
callq 0x3180
cmpl %r12d, %eax
jge 0x560f
andq $0x0, 0x40(%rbx)
jmp 0x5627
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rdi
movq %rax, %rsi
subq %rdi, %rsi
jae 0x56b5
movq %rax, 0x40(%rbx)
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %eax, %eax
movq 0x40(%rbx), %rcx
leaq (%r15,%rcx), %rdx
cmpq %r14, %rdx
jae 0x5658
addl %eax, %ebp
cmpl %r12d, %ebp
jg 0x5658
shlq $0x2, %rcx
addq 0x18(%rbx), %rcx
movl (%rcx,%r15,4), %edi
callq 0x3480
incq %r15
jmp 0x562e
movq (%rbx), %rdi
callq 0x30e0
movq (%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3090
cmpl $-0x1, %eax
je 0x5680
movq (%rbx), %rdi
leaq 0x30(%rbx), %rsi
pushq $-0x1
popq %rdx
callq 0x32d0
movq (%rbx), %rdi
movq 0x40(%rbx), %rsi
shlq $0x2, %rsi
addq 0x18(%rbx), %rsi
movl %r15d, %edx
callq 0x32d0
movq (%rbx), %rdi
callq 0x3390
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5538
shlq $0x2, %rdi
addq 0x18(%rbx), %rdi
callq 0x3180
cmpl %r12d, %eax
jge 0x5750
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rax
leaq (,%rax,4), %rdi
addq 0x18(%rbx), %rdi
subq %rax, %rsi
incq %rsi
callq 0x3180
movl %eax, %ebp
movq 0x40(%rbx), %r13
xorl %eax, %eax
cmpq %r14, 0x38(%rbx)
sete %al
movl %r12d, %ecx
subl %eax, %ecx
xorl %eax, %eax
movl %ecx, 0x4(%rsp)
testl %r13d, %r13d
jle 0x5627
addl %eax, %ebp
cmpl %ecx, %ebp
jge 0x5627
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %r13, %r15
decq %r13
movq 0x18(%rbx), %rax
movl -0x4(%rax,%r15,4), %edi
callq 0x3480
cmpq $0x2, %r15
jb 0x573c
testl %eax, %eax
jle 0x571e
movl %eax, %ecx
addl %ebp, %ecx
movl 0x4(%rsp), %edx
cmpl %edx, %ecx
movl %edx, %ecx
jg 0x5704
movq %r13, 0x40(%rbx)
jmp 0x5704
movq 0x40(%rbx), %rax
movq 0x18(%rbx), %rcx
movl (%rcx,%rax,4), %edi
callq 0x3480
testl %eax, %eax
jle 0x5789
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rax
leaq (,%rax,4), %rdi
addq 0x18(%rbx), %rdi
subq %rax, %rsi
callq 0x3180
cmpl %r12d, %eax
jl 0x5627
movq 0x40(%rbx), %rax
incq %rax
movq %rax, 0x40(%rbx)
jmp 0x5754