// File: /workspace/github_c_makefile_star2_O3/skeeto[P]goblin-com/src/main.c
// Function: text_page
static void
text_page(game_t *game, panel_t *terrain, const char *p, int w, int h)
{
    panel_t page;
    panel_center_init(&page, w + 4, h + 2);
    display_push(&page);
    font_t border = FONT(K, k);
    int numlines = text_numlines(p);
    int topline = 0;
    const char *top = p;

    int key = 0;
    do {
        switch (key) {
        case ARROW_D:
            if (topline < numlines - h) {
                topline++;
                top = text_next_line(top);
            }
            break;
        case ARROW_U:
            if (topline > 1) {
                topline--;
                top = text_prev_line(top);
            } else if (topline == 1) {
                topline = 0;
                top = p;
            }
            break;
        }
        panel_fill(&page, FONT_DEFAULT, ' ');
        panel_border(&page, border);
        if (numlines > h) {
            panel_printf(&page, w + 3, 1, "Rk{↑}");
            int o = (topline / (float)(numlines - h)) * (h - 3);
            panel_printf(&page, w + 3, o + 2, "wk{o}");
            panel_printf(&page, w + 3, h, "Rk{↓}");
        }
        const char *line = top;
        for (int y = 0; y < h && topline + y < numlines; y++) {
            int length = text_linelen(line);
            char copy[length + 1];
            memcpy(copy, line, length);
            copy[length] = '\0';
            panel_printf(&page, 2, y + 1, copy);
            line = text_next_line(line);
        }
    } while (!is_exit_key(key = game_getch(game, terrain)));

    display_pop_free();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c68, %rsp           # imm = 0x3C68
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, -0x60(%rbp)
movq %rdi, -0x58(%rbp)
leal 0x2(%rbx), %edx
leaq -0x3c88(%rbp), %r14
movq %r14, %rdi
movl $0x40, %esi
callq 0x341b
movq %r14, %rdi
callq 0x33a4
movq %r15, -0x40(%rbp)
movb (%r15), %al
movl $0x0, -0x2c(%rbp)
cmpb $0x40, %al
je 0x2c70
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rcx
incq %rcx
cmpb $0xa, %al
jne 0x2c58
movq %rcx, %rdx
jmp 0x2c64
leaq 0x1(%rcx), %rdx
cmpb $0xa, (%rcx)
movq %rdx, %rcx
jne 0x2c58
incl -0x2c(%rbp)
movb (%rdx), %al
movq %rdx, %rcx
cmpb $0x40, %al
jne 0x2c4c
movl -0x2c(%rbp), %eax
subl %ebx, %eax
movl %eax, -0x44(%rbp)
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x4c(%rbp)
leal -0x3(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x48(%rbp)
xorl %eax, %eax
movq -0x40(%rbp), %rcx
movq %rcx, -0x38(%rbp)
xorl %r12d, %r12d
movq %rbx, -0x68(%rbp)
cmpl $0x141, %eax            # imm = 0x141
je 0x2ccb
cmpl $0x142, %eax            # imm = 0x142
jne 0x2d02
cmpl -0x44(%rbp), %r12d
jge 0x2d02
movq -0x38(%rbp), %rax
cmpb $0xa, (%rax)
leaq 0x1(%rax), %rax
jne 0x2cb9
movq %rax, -0x38(%rbp)
incl %r12d
jmp 0x2d02
cmpl $0x2, %r12d
jl 0x2ce8
movq -0x38(%rbp), %rax
cmpb $0xa, -0x2(%rax)
leaq -0x1(%rax), %rax
jne 0x2cd5
movq %rax, -0x38(%rbp)
decl %r12d
jmp 0x2d02
cmpl $0x1, %r12d
movq -0x38(%rbp), %rax
cmoveq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, %eax
cmovel %eax, %r12d
leaq -0x3c88(%rbp), %r14
movq %r14, %rdi
movl $0x10007, %esi          # imm = 0x10007
movl $0x20, %edx
callq 0x345c
movq %r14, %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x418c
cmpl %ebx, -0x2c(%rbp)
jle 0x2d8f
movq %r14, %rdi
movl $0x3f, %esi
movl $0x1, %edx
leaq 0x44c3(%rip), %rcx      # 0x7204
xorl %eax, %eax
callq 0x36ec
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
divss -0x4c(%rbp), %xmm0
mulss -0x48(%rbp), %xmm0
cvttss2si %xmm0, %edx
addl $0x2, %edx
movq %r14, %rdi
movl $0x3f, %esi
leaq 0x449c(%rip), %rcx      # 0x720c
xorl %eax, %eax
callq 0x36ec
movq %r14, %rdi
movl $0x3f, %esi
movl %ebx, %edx
leaq 0x448a(%rip), %rcx      # 0x7212
xorl %eax, %eax
callq 0x36ec
testl %ebx, %ebx
setg %al
cmpl -0x2c(%rbp), %r12d
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2e3b
xorl %r14d, %r14d
movq -0x38(%rbp), %r15
movq %r12, -0x70(%rbp)
cmpb $0xa, (%r15)
movl $0x0, %eax
je 0x2dca
xorl %eax, %eax
cmpb $0xa, 0x1(%r15,%rax)
leaq 0x1(%rax), %rax
jne 0x2dbe
movq %rsp, %rbx
leal 0x1(%rax), %ecx
movq %rsp, %r12
addq $0xf, %rcx
andq $-0x10, %rcx
subq %rcx, %r12
movq %r12, %rsp
movslq %eax, %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1180
movb $0x0, (%r13,%r12)
incl %r14d
leaq -0x3c88(%rbp), %rdi
movl $0x2, %esi
movl %r14d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x36ec
cmpb $0xa, (%r15)
leaq 0x1(%r15), %r15
jne 0x2e14
movq %rbx, %rsp
movq -0x68(%rbp), %rbx
cmpl %ebx, %r14d
movq -0x70(%rbp), %r12
jge 0x2e3b
leal (%r14,%r12), %eax
cmpl -0x2c(%rbp), %eax
jl 0x2db1
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2e6f
cmpl $0x1b, %eax
je 0x2e5b
cmpl $0x51, %eax
je 0x2e5b
cmpl $0x71, %eax
jne 0x2ca1
callq 0x33db
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq