// File: /workspace/github_c_makefile_star2_O2/hughbarney[P]zepl/zepl.c
// Function: display
void display()
{
	char_t *p;
	int i, j, k;
	buffer_t *bp = curbp;
	
	/* find start of screen, handle scroll up off page or top of file  */
	/* point is always within b_page and b_epage */
	if (bp->b_point < bp->b_page)
		bp->b_page = segstart(bp, lnstart(bp,bp->b_point), bp->b_point);

	/* reframe when scrolled off bottom */
	if (bp->b_epage <= bp->b_point) {
		/* Find end of screen plus one. */
		bp->b_page = dndn(bp, bp->b_point);
		/* if we scoll to EOF we show 1 blank line at bottom of screen */
		if (pos(bp, bp->b_ebuf) <= bp->b_page) {
			bp->b_page = pos(bp, bp->b_ebuf);
			i = bp->w_rows - 1;
		} else {
			i = bp->w_rows - 0;
		}
		/* Scan backwards the required number of lines. */
		while (0 < i--)
			bp->b_page = upup(bp, bp->b_page);
	}

	move(bp->w_top, 0); /* start from top of window */
	i = bp->w_top;
	j = 0;
	bp->b_epage = bp->b_page;
	
	/* paint screen from top of page until we hit maxline */ 
	while (1) {
		/* reached point - store the cursor position */
		if (bp->b_point == bp->b_epage) {
			bp->b_row = i;
			bp->b_col = j;
		}
		p = ptr(bp, bp->b_epage);
		if (bp->w_top + bp->w_rows <= i || bp->b_ebuf <= p) /* maxline */
			break;
		if (*p != '\r') {
			if (isprint(*p) || *p == '\t' || *p == '\n') {
				j += *p == '\t' ? 8-(j&7) : 1;
				addch(*p);
			} else {
				const char *ctrl = unctrl(*p);
				j += (int) strlen(ctrl);
				addstr(ctrl);
			}
		}
		if (*p == '\n' || COLS <= j) {
			j -= COLS;
			if (j < 0)
				j = 0;
			++i;
		}
		++bp->b_epage;
	}

	/* replacement for clrtobot() to bottom of window */
	for (k=i; k < bp->w_top + bp->w_rows; k++) {
		move(k, j); /* clear from very last char not start of line */
		clrtoeol();
		j = 0; /* thereafter start of line */
	}

	modeline(bp);
	dispmsg();
	move(bp->b_row, bp->b_col); /* set cursor */
	refresh();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x9dc4(%rip), %rbx      # 0xcaf8
movq 0x8(%rbx), %r14
cmpq 0x10(%rbx), %r14
jge 0x2d5b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29bc
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x2a08
movq %rax, 0x10(%rbx)
cmpq %r14, 0x18(%rbx)
jg 0x2dd5
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2b90
movq %rax, %rcx
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rsi
cmpq %rax, %rsi
jbe 0x2d90
subq %rdi, %rax
cmpq %rcx, %rax
jg 0x2da5
xorl %edx, %edx
jmp 0x2db1
movq 0x30(%rbx), %rdx
subq %rdi, %rax
movq %rax, %rdi
subq %rsi, %rdi
addq %rdx, %rdi
cmpq %rcx, %rdi
jle 0x2dae
movsbl 0x41(%rbx), %ebp
movq %rcx, %rax
jmp 0x2dd1
subq %rsi, %rdx
addq %rdx, %rax
movq %rax, 0x10(%rbx)
movsbl 0x41(%rbx), %ebp
decl %ebp
jmp 0x2dd1
decl %ebp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2b3b
movq %rax, 0x10(%rbx)
testl %ebp, %ebp
jg 0x2dc0
movq 0x91f4(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
movsbl 0x40(%rbx), %esi
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x2280
movsbl 0x40(%rbx), %ebp
movq 0x10(%rbx), %rax
movq 0x91e4(%rip), %r13      # 0xbfe0
movq %rax, 0x18(%rbx)
cmpq %rax, 0x8(%rbx)
jne 0x2e0d
movl %ebp, 0x44(%rbx)
movl %r14d, 0x48(%rbx)
movq 0x20(%rbx), %r15
testq %rax, %rax
js 0x2e30
addq %rax, %r15
movq 0x30(%rbx), %rcx
cmpq %rcx, %r15
jae 0x2e26
xorl %eax, %eax
jmp 0x2e2d
movq 0x38(%rbx), %rax
subq %rcx, %rax
addq %rax, %r15
movsbl 0x40(%rbx), %eax
movsbl 0x41(%rbx), %ecx
movl %ecx, %edx
addl %eax, %edx
cmpl %ebp, %edx
jle 0x2f1c
cmpq %r15, 0x28(%rbx)
jbe 0x2f1c
movzbl (%r15), %r12d
cmpl $0xd, %r12d
je 0x2ecd
callq 0x2340
leal -0x9(%r12), %ecx
cmpb $0x2, %cl
jb 0x2ea3
movq (%rax), %rax
movzwl (%rax,%r12,2), %eax
andl $0x4000, %eax           # imm = 0x4000
jne 0x2ea3
movl %r12d, %edi
callq 0x2250
movq %rax, %r12
movq %rax, %rdi
callq 0x20e0
addl %eax, %r14d
movq 0x913d(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
movq %r12, %rsi
pushq $-0x1
popq %rdx
callq 0x2310
jmp 0x2ecd
movl %r14d, %eax
andl $0x7, %eax
pushq $0x8
popq %rcx
subl %eax, %ecx
cmpl $0x9, %r12d
pushq $0x1
popq %rax
cmovnel %eax, %ecx
addl %ecx, %r14d
movq 0x910e(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
movl %r12d, %esi
callq 0x22a0
cmpb $0xa, (%r15)
movl (%r13), %eax
je 0x2edc
cmpl %eax, %r14d
jl 0x2ee9
subl %eax, %r14d
testl %r14d, %r14d
jg 0x2ee7
xorl %r14d, %r14d
incl %ebp
movq 0x18(%rbx), %rax
incq %rax
jmp 0x2dfc
movq 0x90d4(%rip), %r15      # 0xbfd0
movq (%r15), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2280
movq (%r15), %rdi
callq 0x2290
incl %ebp
movb 0x40(%rbx), %al
movb 0x41(%rbx), %cl
xorl %r14d, %r14d
movsbl %al, %eax
movsbl %cl, %ecx
addl %eax, %ecx
cmpl %ecx, %ebp
jl 0x2ef5
movq %rbx, %rdi
callq 0x2c28
callq 0x2cda
movq 0x9094(%rip), %r14      # 0xbfd0
movq (%r14), %rdi
movl 0x44(%rbx), %esi
movl 0x48(%rbx), %edx
callq 0x2280
movq (%r14), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140