// File: /workspace/github_c_makefile_star2_O1/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 0xacc2(%rip), %rbx      # 0xdaf8
movq 0x8(%rbx), %r14
cmpq 0x10(%rbx), %r14
jge 0x2e95
movq 0x20(%rbx), %rcx
leaq -0x1(%rcx), %rdx
xorl %esi, %esi
movq %r14, %rax
movq %rcx, %rdi
testq %rax, %rax
jle 0x2e73
leaq (%rdx,%rax), %rdi
movq 0x30(%rbx), %r8
cmpq %r8, %rdi
jae 0x2e66
xorl %edi, %edi
jmp 0x2e6d
movq 0x38(%rbx), %rdi
subq %r8, %rdi
addq %rax, %rdi
addq %rdx, %rdi
cmpq %rdi, %rcx
jae 0x2e86
decq %rax
cmpb $0xa, (%rdi)
jne 0x2e4d
incq %rax
movq %rax, %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2a5c
movq %rax, 0x10(%rbx)
cmpq %r14, 0x18(%rbx)
jg 0x2f18
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2c67
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rdx
movq 0x38(%rbx), %rcx
cmpq %rdx, %rcx
jbe 0x2ec0
xorl %r8d, %r8d
jmp 0x2ec7
movq 0x30(%rbx), %r8
subq %rcx, %r8
movq %rdx, %rsi
subq %rdi, %rsi
addq %rsi, %r8
cmpq %rax, %r8
jle 0x2edb
movsbl 0x41(%rbx), %ebp
jmp 0x2ef8
cmpq %rdx, %rcx
jbe 0x2ee4
xorl %eax, %eax
jmp 0x2eeb
movq 0x30(%rbx), %rax
subq %rcx, %rax
addq %rsi, %rax
movq %rax, 0x10(%rbx)
movsbl 0x41(%rbx), %ebp
decl %ebp
testl %ebp, %ebp
jle 0x2f18
movq 0x10(%rbx), %rax
incl %ebp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2ba7
movq %rax, 0x10(%rbx)
decl %ebp
cmpl $0x1, %ebp
jg 0x2f02
movq 0xa0b1(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movsbl 0x40(%rbx), %esi
xorl %edx, %edx
callq 0x2280
movsbl 0x40(%rbx), %ebp
movq 0x10(%rbx), %r13
movq 0xa0a4(%rip), %r12      # 0xcfe0
xorl %r14d, %r14d
movq %r13, 0x18(%rbx)
cmpq %r13, 0x8(%rbx)
jne 0x2f50
movl %ebp, 0x44(%rbx)
movl %r14d, 0x48(%rbx)
testq %r13, %r13
js 0x2f66
addq 0x20(%rbx), %r13
movq 0x30(%rbx), %rcx
cmpq %rcx, %r13
jae 0x2f6c
xorl %eax, %eax
jmp 0x2f73
movq 0x20(%rbx), %r13
jmp 0x2f76
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 0x3044
cmpq %r13, 0x28(%rbx)
jbe 0x3044
movzbl (%r13), %r15d
cmpl $0xd, %r15d
je 0x3017
callq 0x2340
leal -0x9(%r15), %ecx
cmpb $0x2, %cl
jb 0x2fe9
movq (%rax), %rax
movzwl (%rax,%r15,2), %eax
andl $0x4000, %eax           # imm = 0x4000
jne 0x2fe9
movl %r15d, %edi
callq 0x2250
movq %rax, %r15
movq %rax, %rdi
callq 0x20e0
addl %eax, %r14d
movq 0x9ff9(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2310
jmp 0x3017
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 0x9fc4(%rip), %rax      # 0xcfd0
movq (%rax), %rdi
movl %r15d, %esi
callq 0x22a0
cmpb $0xa, (%r13)
movl (%r12), %eax
je 0x3027
cmpl %eax, %r14d
jl 0x3038
subl %eax, %r14d
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
incl %ebp
movq 0x18(%rbx), %r13
incq %r13
jmp 0x2f3f
movsbl 0x40(%rbx), %eax
movsbl 0x41(%rbx), %ecx
addl %eax, %ecx
cmpl %ecx, %ebp
movq 0x9f79(%rip), %r15      # 0xcfd0
jge 0x3081
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 0x3059
movq %rbx, %rdi
callq 0x2d2b
callq 0x2dd7
movq (%r15), %rdi
movl 0x44(%rbx), %esi
movl 0x48(%rbx), %edx
callq 0x2280
movq (%r15), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2140