// File: /workspace/github_cpp_makefile_star2_O3/havluj[P]spreadsheet/src/CTableController.cpp
// Function: CTableController::renderTable()
void CTableController::renderTable() {
    int maxY, maxX;
    getmaxyx(stdscr, maxY, maxX);

    init_pair(2, COLOR_RED, COLOR_BLACK);
    init_pair(3, COLOR_BLUE, COLOR_BLACK);

    int rowsCnt = (maxY - 10 - 3) / 2;
    if ((rowsCnt + m_rowStartingPosition) < m_rowPosition) {
	  m_rowStartingPosition = m_rowPosition - rowsCnt;
    } else if (m_rowPosition < m_rowStartingPosition) {
	  m_rowStartingPosition = m_rowPosition;
    }

    int colsCnt = (maxX - 6) / 10;
    if ((colsCnt + m_colStartingPosition) <= m_colPosition) {
	  m_colStartingPosition = m_colPosition - colsCnt + 1;
    } else if (m_colPosition < m_colStartingPosition) {
	  m_colStartingPosition = m_colPosition;
    }

    //==========================================================================
    /* create the grid */
    //==========================================================================
    attrset(COLOR_PAIR(3));
    /* horizontal lines */
    int offset = 10;
    for (int i = m_rowStartingPosition; i < (rowsCnt + m_rowStartingPosition); i++) {
	  if (m_rowPosition == i || m_rowPosition == (i + 1)) {
		attrset(COLOR_PAIR(2));
	  }
	  move(offset, 0);
	  hline(0, maxX);
	  attroff(COLOR_PAIR(2));
	  attrset(COLOR_PAIR(3));
	  offset += 2;
    }

    /* vertical lines */
    offset = 5;
    for (int i = m_colStartingPosition; i <= (colsCnt + m_colStartingPosition); i++) {
	  if (m_colPosition == i || m_colPosition == (i - 1)) {
		attrset(COLOR_PAIR(2));
	  }
	  move(7, offset);
	  vline(0, maxY - 7 - 3);
	  attroff(COLOR_PAIR(2));
	  attrset(COLOR_PAIR(3));
	  offset += 10;
    }
    attroff(COLOR_PAIR(3));

    /* We need to draw the main lines after we draw the regular ones, so they
	 will appear to be in front of the regular ones. */
    /* Main vertical line */
    move(7, 4);
    vline(0, maxY - 7 - 3);

    /* Main horizontal line. */
    move(8, 0);
    hline('=', maxX);

    //==========================================================================
    /* numbering cols and rows */
    //==========================================================================
    /* rows */
    offset = 9;
    for (int i = m_rowStartingPosition; i <= (rowsCnt + m_rowStartingPosition); i++) {
	  if (m_rowPosition == i) {
		attrset(COLOR_PAIR(2));
	  }
	  mvprintw(offset, 0, "%4d", i);
	  attroff(COLOR_PAIR(2));
	  offset += 2;
    }

    /* columns */
    offset = 6;
    std::string s;
    int digitsCnt;
    for (int i = m_colStartingPosition; i <= (colsCnt + m_colStartingPosition); i++) {
	  /* center the numbers */
	  s = "";
	  digitsCnt = std::to_string(i).length();
	  for (int j = 0; j < ((9 - digitsCnt) / 2); j++) {
		s.append(" ");
	  }
	  s.append(std::to_string(i));
	  for (int j = (s.length()); j < 9; j++) {
		s.append(" ");
	  }

	  if (m_colPosition == i) {
		attrset(COLOR_PAIR(2));
	  }
	  /* make sure to display only a part if there is not enough space */
	  if ((int) s.length() > (maxX - offset)) {
		mvprintw(7, offset, "%.*s", (maxX - offset), s.c_str());
	  } else {
		mvprintw(7, offset, "%s", s.c_str());
	  }
	  attroff(COLOR_PAIR(2));
	  offset += 10;
    }

    //==========================================================================
    /* filling out the table */
    //==========================================================================
    int rowOffset = 9;
    for (int i = m_rowStartingPosition; i <= (rowsCnt + m_rowStartingPosition); i++) {
	  int colOffset = 6;
	  for (int j = m_colStartingPosition; j <= (colsCnt + m_colStartingPosition); j++) {
		/* center the content */
		s = "";
		digitsCnt = m_database.getValue(i, j).length();
		for (int k = 0; k < ((9 - digitsCnt) / 2); k++) {
		    s.append(" ");
		}
		s.append(m_database.getValue(i, j));
		for (int k = (s.length()); k < 9; k++) {
		    s.append(" ");
		}

		/* keep only 9 characters */
		if (s.length() > 9) {
		    s = s.substr(0, 6);
		    s.append("...");
		}

		if (m_colPosition == j && m_rowPosition == i) {
		    attrset(COLOR_PAIR(2));
		}
		/* make sure to display only a part if there is not enough space */
		if ((int) s.length() > (maxX - colOffset)) {
		    mvprintw(rowOffset, colOffset, "%.*s", (maxX - colOffset), s.c_str());
		} else {
		    mvprintw(rowOffset, colOffset, "%s", s.c_str());
		}
		attroff(COLOR_PAIR(2));
		colOffset += 10;
	  }
	  rowOffset += 2;
    }

    refresh();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r12
movq 0x9b20(%rip), %rax      # 0x12fb8
movq (%rax), %rax
testq %rax, %rax
je 0x94b0
movswl 0x4(%rax), %r15d
incl %r15d
movswl 0x6(%rax), %eax
incl %eax
jmp 0x94bb
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rsp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x4050
movl $0x3, %edi
movl $0x4, %esi
xorl %edx, %edx
callq 0x4050
leal -0xd(%r15), %eax
shrl $0x1f, %eax
leal (%r15,%rax), %r13d
addl $-0xd, %r13d
sarl %r13d
movl 0x78(%r12), %eax
movl 0x80(%r12), %ecx
leal (%rcx,%r13), %edx
cmpl %eax, %edx
jge 0x950d
subl %r13d, %eax
jmp 0x9511
cmpl %ecx, %eax
jge 0x9519
movl %eax, 0x80(%r12)
movq (%rsp), %rax
addl $-0x6, %eax
cltq
imulq $0x66666667, %rax, %rsi # imm = 0x66666667
movq %rsi, %rax
shrq $0x3f, %rax
sarq $0x22, %rsi
addl %eax, %esi
movl 0x7c(%r12), %eax
movl 0x84(%r12), %ecx
leal (%rcx,%rsi), %edx
cmpl %eax, %edx
movq %rsi, 0x68(%rsp)
jle 0x9555
cmpl %ecx, %eax
jl 0x9559
jmp 0x9561
subl %esi, %eax
incl %eax
movl %eax, 0x84(%r12)
movq 0x9a50(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4310
cmpl $0xf, %r15d
jl 0x9603
movl 0x80(%r12), %ebp
movl $0xa, %ebx
movl 0x78(%r12), %eax
cmpl %eax, %ebp
sete %cl
incl %ebp
cmpl %eax, %ebp
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x95b7
movq 0x9a0e(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movl %ebx, %edi
xorl %esi, %esi
callq 0x41e0
movq 0x99f1(%rip), %r14      # 0x12fb8
movq (%r14), %rdi
xorl %esi, %esi
movq (%rsp), %rdx
callq 0x4290
movq (%r14), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
movq (%r14), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4310
addl $0x2, %ebx
movl 0x80(%r12), %eax
addl %r13d, %eax
cmpl %eax, %ebp
jl 0x958c
cmpl $-0x4, (%rsp)
movq %r15, 0x30(%rsp)
jg 0x9617
leal -0xa(%r15), %ebx
jmp 0x96b5
movl 0x84(%r12), %r14d
leal -0xa(%r15), %ebx
movl $0x5, %ebp
movl 0x7c(%r12), %eax
cmpl %eax, %r14d
sete %cl
decl %r14d
cmpl %r14d, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x9656
movq 0x996f(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movl $0x7, %edi
movl %ebp, %esi
callq 0x41e0
movq 0x994f(%rip), %r15      # 0x12fb8
movq (%r15), %rdi
xorl %esi, %esi
movl %ebx, %edx
callq 0x4390
movq (%r15), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
movq (%r15), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4310
addl $0xa, %ebp
movl 0x84(%r12), %eax
addl 0x68(%rsp), %eax
leal 0x1(%r14), %ecx
addl $0x2, %r14d
cmpl %eax, %ecx
jl 0x9628
movq 0x30(%rsp), %r15
movq 0x98fc(%rip), %r14      # 0x12fb8
movq (%r14), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x43b0
movl $0x7, %edi
movl $0x4, %esi
callq 0x41e0
movq (%r14), %rdi
xorl %esi, %esi
movl %ebx, %edx
callq 0x4390
movl $0x8, %edi
xorl %esi, %esi
callq 0x41e0
movq (%r14), %rdi
movl $0x3d, %esi
movq (%rsp), %rdx
callq 0x4290
cmpl $0xc, %r15d
jl 0x9779
movl 0x80(%r12), %r14d
movl $0x9, %ebx
leaq 0x4f94(%rip), %r15      # 0xe6b1
cmpl 0x78(%r12), %r14d
jne 0x9738
movq 0x988d(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movl %ebx, %edi
xorl %esi, %esi
movq %r15, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x43d0
movq 0x9868(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
addl $0x2, %ebx
leal 0x1(%r14), %eax
movl 0x80(%r12), %ecx
addl %r13d, %ecx
cmpl %ecx, %r14d
movl %eax, %r14d
jl 0x971d
movq %r13, 0x70(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpl $-0x3, (%rsp)
movq %r12, 0x38(%rsp)
jl 0x9a0c
movl 0x84(%r12), %r14d
movl $0x6, %ebp
leaq 0x48(%rsp), %r12
movq 0x50(%rsp), %rdx
movq %r12, %rdi
xorl %esi, %esi
leaq 0x50d0(%rip), %rcx      # 0xe894
xorl %r8d, %r8d
callq 0x44a0
movl %ebp, 0x28(%rsp)
movl %r14d, %ebx
negl %ebx
cmovsl %r14d, %ebx
movl $0x1, %ebp
cmpl $0xa, %ebx
leaq 0x18(%rsp), %rdi
jb 0x9829
movl $0x4, %ebp
movl %ebx, %eax
cmpl $0x63, %eax
jbe 0x9822
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9827
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9829
movl %eax, %ecx
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebp
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x97ef
addl $-0x3, %ebp
jmp 0x9829
addl $-0x2, %ebp
jmp 0x9829
decl %ebp
movq %r14, %r15
shrl $0x1f, %r14d
leal (%r14,%rbp), %esi
movq %rdi, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movl $0x2d, %edx
callq 0x4360
movl %r14d, %eax
movq 0x8(%rsp), %rdi
movq %rax, 0x40(%rsp)
addq %rax, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x9f34
movl 0x10(%rsp), %r13d
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9882
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpl $0x7, %r13d
jg 0x98a5
movl $0x9, %ebp
subl %r13d, %ebp
shrl %ebp
movq %r12, %rdi
leaq 0x4ff7(%rip), %rsi      # 0xe893
callq 0x4610
decl %ebp
jne 0x9892
movl $0x1, %ebp
cmpl $0xa, %ebx
movq 0x38(%rsp), %r13
jb 0x98f5
movl $0x4, %ebp
movl %ebx, %eax
cmpl $0x63, %eax
jbe 0x98ee
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x98f3
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x98f5
movl %eax, %ecx
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebp
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x98bb
addl $-0x3, %ebp
jmp 0x98f5
addl $-0x2, %ebp
jmp 0x98f5
decl %ebp
addl %ebp, %r14d
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movl $0x2d, %edx
callq 0x4360
movq 0x40(%rsp), %rdi
addq 0x8(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x9f34
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r12, %rdi
callq 0x40b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
movq 0x68(%rsp), %r14
movl 0x28(%rsp), %ebp
je 0x995e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movl 0x50(%rsp), %ebx
cmpl $0x8, %ebx
jg 0x997d
addl $-0x9, %ebx
movq %r12, %rdi
leaq 0x4f1f(%rip), %rsi      # 0xe893
callq 0x4610
incl %ebx
jne 0x996a
cmpl %r15d, 0x7c(%r13)
jne 0x9997
movq 0x962e(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movq (%rsp), %rax
movl %eax, %ecx
subl %ebp, %ecx
movq 0x48(%rsp), %r8
cmpl 0x50(%rsp), %ecx
jge 0x99c1
movl $0x7, %edi
movl %ebp, %esi
leaq 0x4cfd(%rip), %rdx      # 0xe6b5
xorl %eax, %eax
callq 0x43d0
jmp 0x99d9
movl $0x7, %edi
movl %ebp, %esi
leaq 0x4cc0(%rip), %rdx      # 0xe68f
movq %r8, %rcx
xorl %eax, %eax
callq 0x43d0
movq 0x95d8(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
addl $0xa, %ebp
leal 0x1(%r15), %eax
movl 0x84(%r13), %ecx
addl %r14d, %ecx
cmpl %ecx, %r15d
movl %eax, %r14d
jl 0x97b3
cmpl $0xc, 0x30(%rsp)
jl 0x9c66
movq 0x38(%rsp), %rcx
movl 0x80(%rcx), %eax
movl 0x84(%rcx), %ebp
addq $0x8, %rcx
movq %rcx, 0x40(%rsp)
movl $0x9, 0x30(%rsp)
leaq 0x48(%rsp), %r13
leaq 0x8(%rsp), %rbx
leaq 0x4e49(%rip), %r12      # 0xe893
movl %eax, %ecx
movq %rcx, 0x28(%rsp)
cmpl $-0x3, (%rsp)
jge 0x9a5e
movl %ebp, %ecx
jmp 0x9c41
movl $0x6, %r14d
movq 0x50(%rsp), %rdx
movq %r13, %rdi
xorl %esi, %esi
leaq 0x4e1f(%rip), %rcx      # 0xe894
xorl %r8d, %r8d
callq 0x44a0
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
callq 0x5ca0
movl 0x10(%rsp), %ebx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9ab1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpl $0x7, %ebx
jg 0x9ad2
movl $0x9, %r15d
subl %ebx, %r15d
shrl %r15d
movq %r13, %rdi
movq %r12, %rsi
callq 0x4610
decl %r15d
jne 0x9ac2
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %ecx
callq 0x5ca0
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r13, %rdi
callq 0x40b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9b19
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movq 0x50(%rsp), %rax
cmpl $0x8, %eax
jg 0x9b3f
leal -0x9(%rax), %ebx
movq %r13, %rdi
movq %r12, %rsi
callq 0x4610
incl %ebx
jne 0x9b26
movq 0x50(%rsp), %rax
leaq 0x8(%rsp), %rbx
cmpq $0x9, %rax
jbe 0x9b8d
movl $0x6, %ecx
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x42e0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4380
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9b7e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r13, %rdi
leaq 0x4b32(%rip), %rsi      # 0xe6ba
callq 0x4610
movq 0x38(%rsp), %rax
cmpl %ebp, 0x7c(%rax)
jne 0x9bba
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpl %ecx, 0x78(%rax)
jne 0x9bba
movq 0x940b(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movq (%rsp), %rax
movl %eax, %ecx
subl %r14d, %ecx
movq 0x48(%rsp), %r8
cmpl 0x50(%rsp), %ecx
jge 0x9be5
movl 0x30(%rsp), %edi
movl %r14d, %esi
leaq 0x4ad9(%rip), %rdx      # 0xe6b5
xorl %eax, %eax
callq 0x43d0
jmp 0x9bfd
movl 0x30(%rsp), %edi
movl %r14d, %esi
leaq 0x4a9c(%rip), %rdx      # 0xe68f
movq %r8, %rcx
xorl %eax, %eax
callq 0x43d0
movq 0x93b4(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
addl $0xa, %r14d
leal 0x1(%rbp), %eax
movq 0x38(%rsp), %rcx
movl 0x84(%rcx), %ecx
movq 0x68(%rsp), %rdx
addl %ecx, %edx
cmpl %edx, %ebp
movl %eax, %ebp
jl 0x9a64
movq 0x38(%rsp), %rax
movl 0x80(%rax), %eax
addl $0x2, 0x30(%rsp)
movq 0x28(%rsp), %rdi
leal 0x1(%rdi), %edx
movq 0x70(%rsp), %rsi
addl %eax, %esi
movl %ecx, %ebp
cmpl %esi, %edi
movl %edx, %ecx
movq %rcx, 0x28(%rsp)
jl 0x9a51
callq 0x4550
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9c87
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ca2
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ccf
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9cd2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x9cd2
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ccf
jmp 0x9ccf
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9cee
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x45a0