// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3280
movq %rax, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
je 0x66c2
movq -0x8(%rbp), %rax
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x66cc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x3c(%rbp)
jmp 0x66cc
movl -0x3c(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq $-0x1, %rsi
callq 0x3180
movl -0x18(%rbp), %ecx
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6701
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
jmp 0x68d5
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6728
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x68d3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x8(%rbp), %rax
subq 0x40(%rax), %rsi
callq 0x3180
movl -0x18(%rbp), %ecx
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jl 0x67e2
jmp 0x6764
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movl (%rax,%rcx,4), %edi
callq 0x3480
movl %eax, %ecx
movb $0x1, %al
cmpl $0x1, %ecx
movb %al, -0x3d(%rbp)
jl 0x67c2
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x8(%rbp), %rax
subq 0x40(%rax), %rsi
callq 0x3180
movl -0x18(%rbp), %ecx
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
setge %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x67cb
jmp 0x67dd
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x40(%rax)
jmp 0x6764
jmp 0x68d1
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x8(%rbp), %rax
subq 0x40(%rax), %rsi
addq $0x1, %rsi
callq 0x3180
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
subl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x38(%rcx), %rsi
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq %rdi, %rsi
cmovel %edx, %ecx
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x3e(%rbp)
jle 0x6865
movl -0x1c(%rbp), %eax
addl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
setl %al
movb %al, -0x3e(%rbp)
movb -0x3e(%rbp), %al
testb $0x1, %al
jne 0x686e
jmp 0x68cf
movl -0x28(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x3480
movl %eax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x3f(%rbp)
jle 0x68ac
cmpl $0x1, -0x28(%rbp)
setl %al
movb %al, -0x3f(%rbp)
movb -0x3f(%rbp), %al
testb $0x1, %al
jne 0x6877
movl -0x1c(%rbp), %eax
addl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x68ca
movslq -0x24(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x684b
jmp 0x68d1
jmp 0x68d3
jmp 0x68d5
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rcx
addq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x10(%rbp), %rcx
movb %al, -0x40(%rbp)
jae 0x6916
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl -0x18(%rbp), %ecx
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
setle %al
movb %al, -0x40(%rbp)
movb -0x40(%rbp), %al
testb $0x1, %al
jne 0x691f
jmp 0x695c
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x3480
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x68eb
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x30e0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x3090
cmpl $-0x1, %eax
jne 0x697f
jmp 0x6998
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rsi
addq $0x30, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x32d0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
shlq $0x2, %rax
addq %rax, %rsi
movq -0x30(%rbp), %rax
movl %eax, %edx
callq 0x32d0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3390
movq -0x8(%rbp), %rdi
callq 0x6540
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)