// File: /workspace/github_c_makefile_star2_O2/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
movq %rdx, %rbx
movq %rsi, -0x60(%rbp)
movq %rdi, -0x58(%rbp)
movq %rcx, -0x38(%rbp)
leal 0x2(%rcx), %edx
leaq -0x3c88(%rbp), %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
callq 0x30ec
movq %r14, %rdi
callq 0x3077
movl $0x0, -0x2c(%rbp)
movq %rbx, -0x50(%rbp)
movq %rbx, %rax
cmpb $0x40, (%rax)
je 0x295f
incl -0x2c(%rbp)
movq %rax, %rdi
callq 0x2b15
jmp 0x294d
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %rax
subl %eax, %ecx
movl %ecx, -0x3c(%rbp)
cvtsi2ss %ecx, %xmm0
movss %xmm0, -0x44(%rbp)
addl $-0x3, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x40(%rbp)
xorl %eax, %eax
movq -0x50(%rbp), %r15
xorl %r13d, %r13d
cmpl $0x141, %eax            # imm = 0x141
je 0x29ad
cmpl $0x142, %eax            # imm = 0x142
jne 0x29d5
cmpl -0x3c(%rbp), %r13d
jge 0x29d5
incl %r13d
movq %r15, %rdi
callq 0x2b15
movq %rax, %r15
jmp 0x29d5
cmpl $0x2, %r13d
jl 0x29c3
cmpb $0xa, -0x2(%r15)
leaq -0x1(%r15), %r15
jne 0x29b3
decl %r13d
jmp 0x29d5
cmpl $0x1, %r13d
cmoveq -0x50(%rbp), %r15
movl $0x0, %eax
cmovel %eax, %r13d
leaq -0x3c88(%rbp), %rbx
movq %rbx, %rdi
movl $0x10007, %esi          # imm = 0x10007
pushq $0x20
popq %rdx
callq 0x3122
movq %rbx, %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x3629
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x2a5e
movq %rbx, %rdi
pushq $0x3f
popq %r14
movl %r14d, %esi
pushq $0x1
popq %rdx
leaq 0x37ef(%rip), %rcx      # 0x6204
xorl %eax, %eax
callq 0x32c4
cvtsi2ss %r13d, %xmm0
divss -0x44(%rbp), %xmm0
mulss -0x40(%rbp), %xmm0
cvttss2si %xmm0, %edx
addl $0x2, %edx
movq %rbx, %rdi
movl %r14d, %esi
leaq 0x37cd(%rip), %rcx      # 0x620c
xorl %eax, %eax
callq 0x32c4
movq %rbx, %rdi
movl %r14d, %esi
movq -0x38(%rbp), %rdx
leaq 0x37bb(%rip), %rcx      # 0x6212
xorl %eax, %eax
callq 0x32c4
xorl %r12d, %r12d
movq %r15, -0x68(%rbp)
movq %r13, -0x70(%rbp)
cmpl -0x38(%rbp), %r12d
jge 0x2add
leal (%r12,%r13), %eax
cmpl -0x2c(%rbp), %eax
jge 0x2add
xorl %r13d, %r13d
cmpb $0xa, (%r15,%r13)
je 0x2a87
incq %r13
jmp 0x2a7b
movq %rsp, %rbx
movq %rsp, %r14
leaq 0x10(%r13), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1180
movb $0x0, (%r13,%r14)
incl %r12d
leaq -0x3c88(%rbp), %rdi
pushq $0x2
popq %rsi
movl %r12d, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x32c4
movq %r15, %rdi
callq 0x2b15
movq %rax, %r15
movq %rbx, %rsp
movq -0x70(%rbp), %r13
jmp 0x2a69
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2b22
cmpl $0x1b, %eax
movq -0x68(%rbp), %r15
je 0x2b01
cmpl $0x51, %eax
je 0x2b01
cmpl $0x71, %eax
jne 0x2989
callq 0x30ab
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq