// File: /workspace/github_c_makefile_star2_O3/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 0xacda(%rip), %rbx      # 0xdaf8
movq 0x8(%rbx), %r14
cmpq 0x10(%rbx), %r14
jge 0x2e84
movq 0x20(%rbx), %rax
leaq -0x1(%rax), %rcx
xorl %esi, %esi
xorl %edx, %edx
leaq (%r14,%rdx), %rdi
testq %rdi, %rdi
jle 0x2e75
leaq (%rcx,%r14), %rdi
movq 0x30(%rbx), %r8
cmpq %r8, %rdi
jae 0x2e4e
xorl %edi, %edi
jmp 0x2e55
movq 0x38(%rbx), %rdi
subq %r8, %rdi
addq %r14, %rdi
leaq (%rdi,%rcx), %r8
cmpq %r8, %rax
jae 0x2e75
decq %rdx
cmpb $0xa, (%rcx,%rdi)
leaq -0x1(%rcx), %rcx
jne 0x2e34
leaq (%r14,%rdx), %rsi
incq %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2a45
movq %rax, 0x10(%rbx)
cmpq %r14, 0x18(%rbx)
jg 0x2f03
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2c43
movq %rax, %rcx
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rax
movq 0x38(%rbx), %rsi
cmpq %rax, %rsi
jbe 0x2eb9
subq %rdi, %rax
cmpq %rcx, %rax
jg 0x2ece
xorl %edx, %edx
jmp 0x2eda
movq 0x30(%rbx), %rdx
subq %rdi, %rax
movq %rax, %rdi
subq %rsi, %rdi
addq %rdx, %rdi
cmpq %rcx, %rdi
jle 0x2ed7
movsbl 0x41(%rbx), %ebp
movq %rcx, %rax
jmp 0x2ee7
subq %rsi, %rdx
addq %rdx, %rax
movq %rax, 0x10(%rbx)
movsbl 0x41(%rbx), %ebp
decl %ebp
testl %ebp, %ebp
jle 0x2f03
incl %ebp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2b79
movq %rax, 0x10(%rbx)
decl %ebp
cmpl $0x1, %ebp
ja 0x2eed
movq 0xa0c6(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movsbl 0x40(%rbx), %esi
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x2280
movsbl 0x40(%rbx), %ebp
movq 0x10(%rbx), %rax
movq 0xa0b6(%rip), %r12      # 0xcfe0
movq %rax, 0x18(%rbx)
cmpq %rax, 0x8(%rbx)
jne 0x2f3b
movl %ebp, 0x44(%rbx)
movl %r14d, 0x48(%rbx)
movq 0x20(%rbx), %r13
testq %rax, %rax
js 0x2f5e
addq %rax, %r13
movq 0x30(%rbx), %rcx
cmpq %rcx, %r13
jae 0x2f54
xorl %eax, %eax
jmp 0x2f5b
movq 0x38(%rbx), %rax
subq %rcx, %rax
addq %rax, %r13
movsbl 0x40(%rbx), %eax
movsbl 0x41(%rbx), %ecx
addl %eax, %ecx
cmpl %ebp, %ecx
jle 0x3057
cmpq %r13, 0x28(%rbx)
jbe 0x3028
movzbl (%r13), %r15d
cmpl $0xd, %r15d
je 0x2fff
callq 0x2340
leal -0x9(%r15), %ecx
cmpb $0x2, %cl
jb 0x2fd1
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
andl $0x4000, %eax           # imm = 0x4000
jne 0x2fd1
movl %r15d, %edi
callq 0x2250
movq %rax, %r15
movq %rax, %rdi
callq 0x20e0
addl %eax, %r14d
movq 0xa011(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2310
jmp 0x2fff
movl %r14d, %eax
andl $0x7, %eax
movl $0x8, %ecx
subl %eax, %ecx
cmpl $0x9, %r15d
movl $0x1, %eax
cmovnel %eax, %ecx
addl %ecx, %r14d
movq 0x9fdc(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movl %r15d, %esi
callq 0x22a0
cmpb $0xa, (%r13)
movl (%r12), %eax
je 0x300f
cmpl %eax, %r14d
jl 0x301c
subl %eax, %r14d
testl %r14d, %r14d
jg 0x301a
xorl %r14d, %r14d
incl %ebp
movq 0x18(%rbx), %rax
incq %rax
jmp 0x2f2a
movq 0x9fa1(%rip), %r15      # 0xcfd0
movq (%r15), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2280
movq (%r15), %rdi
callq 0x2290
incl %ebp
movsbl 0x40(%rbx), %eax
movsbl 0x41(%rbx), %ecx
addl %eax, %ecx
xorl %r14d, %r14d
cmpl %ecx, %ebp
jl 0x3028
movq %rbx, %rdi
callq 0x2d13
callq 0x2dbf
movq 0x9f65(%rip), %r14      # 0xcfd0
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