// File: /workspace/github_c_makefile_star2_O2/TurkeyMcMac[P]ts3d/src/menu.c
// Function: menu_draw
void menu_draw(struct menu *menu)
{
	int i = 0;
	struct menu_item *current = menu->current;
	if (!menu->needs_redraw) return;
	menu->needs_redraw = false;
	move_clear_line(menu, 0, 0);
	attron(A_UNDERLINE);
	addstr(current->title);
	attroff(A_UNDERLINE);
	int height = menu->area->height - 1;
	if (current->kind == ITEM_LINKS) {
		for (int l = current->frame;
		     l < (int)current->n_items && ++i < height; ++l) {
			int reverse = l == current->place;
			move_clear_line(menu, i, 0);
			if (reverse) attron(A_REVERSE);
			printw("%2d. %s ", l + 1, current->items[l].title);
			if (reverse) attroff(A_REVERSE);
		}
	} else if (current->kind == ITEM_TEXT) {
		for (int l = current->place;
		     l < (int)menu->n_lines && ++i < height; ++l) {
			struct string *line = &menu->lines[l];
			mvprintw(i, 0, "%-*.*s",
				menu->area->width, (int)line->len, line->text);
		}
	}
	if (++i >= height) i = height;
	for (int j = i; j <= height; ++j) {
		move_clear_line(menu, j, 0);
	}
	mvaddstr(i, 0, menu->msg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpb $0x1, 0x38(%rdi)
jne 0x86a9
movq %rdi, %rbx
movq 0x8(%rdi), %rbp
movb $0x0, 0x38(%rdi)
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x86b8
movq 0x8aff(%rip), %r15      # 0x10fd8
movq (%r15), %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x2440
movq (%r15), %rdi
movq 0x8(%rbp), %rsi
pushq $-0x1
popq %rdx
callq 0x2380
movq (%r15), %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x20e0
movq 0x10(%rbx), %rax
movl 0xc(%rax), %r13d
leal -0x1(%r13), %eax
movl %eax, 0xc(%rsp)
movl 0x10(%rbp), %eax
cmpl $0x2, %eax
je 0x85f2
cmpl $0x1, %eax
jne 0x8656
movl 0x34(%rbp), %r15d
movslq %r15d, %rax
movq %rax, 0x20(%rsp)
imulq $0x38, %rax, %rax
addq $0x8, %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movq %r13, 0x18(%rsp)
movq 0x20(%rsp), %rax
addq %r14, %rax
movslq 0x28(%rbp), %rcx
cmpq %rcx, %rax
jge 0x864f
leaq 0x1(%r14), %r12
cmpl 0xc(%rsp), %r12d
jge 0x864c
movl 0x30(%rbp), %r14d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x86b8
cmpl %r14d, %r15d
jne 0x859a
movq 0x8a4d(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
movl $0x40000, %esi          # imm = 0x40000
xorl %edx, %edx
callq 0x2440
movq %rbp, %r13
movq 0x20(%rbp), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx), %rdx
leal 0x1(%r15), %ebp
leaq 0x3932(%rip), %rdi      # 0xbee7
movl %ebp, %esi
xorl %eax, %eax
callq 0x2030
cmpl %r14d, %r15d
jne 0x85d9
movq 0x8a0e(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
movl $0x40000, %esi          # imm = 0x40000
xorl %edx, %edx
callq 0x20e0
addq $0x38, 0x10(%rsp)
movq %r12, %r14
movl %ebp, %r15d
movq %r13, %rbp
movq 0x18(%rsp), %r13
jmp 0x854c
movslq 0x30(%rbp), %rbp
movq %rbp, %r15
shlq $0x4, %r15
orq $0x8, %r15
xorl %r14d, %r14d
leaq (%r14,%rbp), %rax
movslq 0x30(%rbx), %rcx
cmpq %rcx, %rax
jge 0x864f
leaq 0x1(%r14), %r12
cmpl 0xc(%rsp), %r12d
jge 0x864c
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %rdx
movl 0x8(%rax), %ecx
movl -0x8(%rdx,%r15), %r8d
movq (%rdx,%r15), %r9
movl %r12d, %edi
xorl %esi, %esi
leaq 0x38b4(%rip), %rdx      # 0xbef0
xorl %eax, %eax
callq 0x21e0
addq $0x10, %r15
movq %r12, %r14
jmp 0x8604
incl %r14d
movq 0x8982(%rip), %r15      # 0x10fd8
incl %r14d
movl 0xc(%rsp), %eax
cmpl %eax, %r14d
cmovgel %eax, %r14d
movl %r14d, %ebp
cmpl %r13d, %ebp
jge 0x867a
movq %rbx, %rdi
movl %ebp, %esi
callq 0x86b8
incl %ebp
jmp 0x8667
movq (%r15), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x2320
cmpl $-0x1, %eax
je 0x86a9
movq (%r15), %rdi
movq 0x20(%rbx), %rsi
pushq $-0x1
popq %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2380
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq