// File: /workspace/github_c_makefile_star2_O0/cglindkamp[P]dfm/src/listview.c
// Function: listview_setindex_internal
static void listview_setindex_internal(struct listview *view, size_t index, int direction, bool keep_distance)
{
	size_t listcount = listmodel_count(view->model);
	unsigned int rowcount = getmaxy(view->window);
	size_t distance = view->index - view->first;

	/* check index for over- and underflow */
	if(direction == 0 && index > listcount - 1)
		view->index = listcount - 1;
	else if(direction < 0 && index > view->index)
		view->index = 0;
	else if(direction > 0 && (index < view->index || index > listcount - 1))
		view->index = listcount - 1;
	else
		view->index = index;

	/* try to restore distance between first and index
	 * may underflow, but this is checked later */
	if(keep_distance)
		view->first = view->index - distance;

	/* make sure, first has a sane value relative to index */
	if(view->index < view->first)
		view->first = view->index;
	else if(view->index - view->first >= rowcount)
		view->first = view->index - rowcount + 1;

	/* make sure, view is always filled to the bottom with entries,
	 * or in case there aren't enough, scrolled to the first entry */
	if(listcount <= rowcount)
		view->first = 0;
	else if(listcount - view->first <= rowcount)
		view->first = listcount - rowcount;

	view->needs_refresh = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xa660
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq (%rcx), %rax
je 0xac89
movq -0x8(%rbp), %rax
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xac93
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x34(%rbp)
jmp 0xac93
movl -0x34(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0x10(%rcx), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0xacd6
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xacd6
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xad3f
cmpl $0x0, -0x14(%rbp)
jge 0xacf8
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jbe 0xacf8
movq -0x8(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0xad3d
cmpl $0x0, -0x14(%rbp)
jle 0xad2f
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jb 0xad1d
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xad2f
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xad3b
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xad3d
jmp 0xad3f
testb $0x1, -0x15(%rbp)
je 0xad59
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
subq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0xad7d
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0xadb1
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
subq 0x10(%rcx), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
jb 0xadaf
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x24(%rbp), %eax
subq %rax, %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0xadb1
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
ja 0xadcb
movq -0x8(%rbp), %rax
movq $0x0, 0x10(%rax)
jmp 0xadf3
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
subq 0x10(%rcx), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
ja 0xadf1
movq -0x20(%rbp), %rcx
movl -0x24(%rbp), %eax
subq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0xadf3
movq -0x8(%rbp), %rax
movb $0x1, 0x20(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)