// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, %r13
movq 0x9a8f(%rip), %rax      # 0x12fb8
movq (%rax), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x10(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x9546
movswl 0x4(%rax), %ebx
incl %ebx
testq %rax, %rax
je 0x9556
movswl 0x6(%rax), %eax
incl %eax
movq %rax, 0x10(%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(%rbx), %eax
shrl $0x1f, %eax
leal (%rbx,%rax), %r12d
addl $-0xd, %r12d
sarl %r12d
movl 0x78(%r13), %eax
movl 0x80(%r13), %ecx
leal (%rcx,%r12), %edx
cmpl %eax, %edx
jge 0x95a1
subl %r12d, %eax
jmp 0x95a5
cmpl %ecx, %eax
jge 0x95ac
movl %eax, 0x80(%r13)
movq 0x10(%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(%r13), %eax
movl 0x84(%r13), %ecx
leal (%rcx,%rsi), %edx
cmpl %eax, %edx
movq %rsi, 0x70(%rsp)
jle 0x95e7
cmpl %ecx, %eax
jl 0x95eb
jmp 0x95f2
subl %esi, %eax
incl %eax
movl %eax, 0x84(%r13)
movq 0x99bf(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x300, %esi            # imm = 0x300
callq 0x4310
movq %rbx, 0x68(%rsp)
cmpl $0xf, %ebx
jl 0x9696
movl 0x80(%r13), %ebp
movl $0xa, %ebx
movl 0x78(%r13), %eax
cmpl %eax, %ebp
sete %cl
incl %ebp
cmpl %eax, %ebp
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x964a
movq 0x997b(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movl %ebx, %edi
xorl %esi, %esi
callq 0x41e0
movq 0x995e(%rip), %r14      # 0x12fb8
movq (%r14), %rdi
xorl %esi, %esi
movq 0x10(%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(%r13), %eax
addl %r12d, %eax
cmpl %eax, %ebp
jl 0x9620
cmpl $-0x3, 0x10(%rsp)
jl 0x973b
movl 0x84(%r13), %r14d
movq 0x68(%rsp), %rax
leal -0xa(%rax), %ebx
movl $0x5, %ebp
movl 0x7c(%r13), %eax
cmpl %eax, %r14d
sete %cl
decl %r14d
cmpl %r14d, %eax
sete %al
orb %cl, %al
cmpb $0x1, %al
jne 0x96e2
movq 0x98e3(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movl $0x7, %edi
movl %ebp, %esi
callq 0x41e0
movq 0x98c3(%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(%r13), %eax
addl 0x70(%rsp), %eax
leal 0x1(%r14), %ecx
addl $0x2, %r14d
cmpl %eax, %ecx
jl 0x96b5
movq 0x9876(%rip), %rbx      # 0x12fb8
movq (%rbx), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x43b0
movl $0x7, %edi
movl $0x4, %esi
callq 0x41e0
movq (%rbx), %rdi
movq 0x68(%rsp), %r14
leal -0xa(%r14), %edx
xorl %esi, %esi
callq 0x4390
movl $0x8, %edi
xorl %esi, %esi
callq 0x41e0
movq (%rbx), %rdi
movl $0x3d, %esi
movq 0x10(%rsp), %rdx
callq 0x4290
cmpl $0xc, %r14d
jl 0x9804
movl 0x80(%r13), %r14d
movl $0x9, %ebx
leaq 0x4ef7(%rip), %r15      # 0xe6a1
cmpl 0x78(%r13), %r14d
jne 0x97c4
movq 0x9801(%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 0x97dc(%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(%r13), %ecx
addl %r12d, %ecx
cmpl %ecx, %r14d
movl %eax, %r14d
jl 0x97aa
movq %r12, 0x78(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpl $-0x3, 0x10(%rsp)
movq %r13, 0x38(%rsp)
jl 0x9aaf
movl 0x84(%r13), %r14d
movl $0x6, 0xc(%rsp)
leaq 0x48(%rsp), %r12
leaq 0x503b(%rip), %r15      # 0xe883
movq 0x50(%rsp), %rdx
movq %r12, %rdi
xorl %esi, %esi
leaq 0x502b(%rip), %rcx      # 0xe884
xorl %r8d, %r8d
callq 0x44a0
movl %r14d, %ebx
negl %ebx
movq %r14, 0x40(%rsp)
cmovsl %r14d, %ebx
movl $0x1, %ebp
cmpl $0xa, %ebx
jb 0x98ba
movl $0x4, %ebp
movl %ebx, %eax
movl $0xd1b71759, %edx       # imm = 0xD1B71759
cmpl $0x63, %eax
jbe 0x98b3
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x98b8
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x98ba
movl %eax, %ecx
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebp
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x9885
addl $-0x3, %ebp
jmp 0x98ba
addl $-0x2, %ebp
jmp 0x98ba
decl %ebp
movq 0x40(%rsp), %r14
shrl $0x1f, %r14d
leal (%r14,%rbp), %esi
leaq 0x28(%rsp), %r13
movq %r13, 0x18(%rsp)
leaq 0x18(%rsp), %rdi
movl $0x2d, %edx
callq 0x4360
movl %r14d, %eax
movq 0x18(%rsp), %rdi
movq %rax, 0x80(%rsp)
addq %rax, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x9fd2
movl 0x20(%rsp), %ebp
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x9917
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpl $0x7, %ebp
movl $0xd1b71759, %r13d      # imm = 0xD1B71759
jg 0x994c
movl $0x9, %eax
subl %ebp, %eax
movl %eax, %ebp
shrl $0x1f, %ebp
addl %eax, %ebp
sarl %ebp
cmpl $0x2, %ebp
movl $0x1, %eax
cmovll %eax, %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0x4610
decl %ebp
jne 0x993d
movl $0x1, %ebp
cmpl $0xa, %ebx
jb 0x9992
movl $0x4, %ebp
movl %ebx, %eax
cmpl $0x63, %eax
jbe 0x998b
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x9990
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x9992
movl %eax, %ecx
imulq %r13, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebp
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x995d
addl $-0x3, %ebp
jmp 0x9992
addl $-0x2, %ebp
jmp 0x9992
decl %ebp
addl %ebp, %r14d
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
movl $0x2d, %edx
callq 0x4360
movq 0x80(%rsp), %rdi
addq 0x18(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x9fd2
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rdi
callq 0x40b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq 0x38(%rsp), %r13
movq 0x70(%rsp), %r14
movq 0x40(%rsp), %rbp
je 0x9a04
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
movl 0x50(%rsp), %ebx
cmpl $0x8, %ebx
jg 0x9a1f
addl $-0x9, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0x4610
incl %ebx
jne 0x9a10
cmpl %ebp, 0x7c(%r13)
jne 0x9a39
movq 0x958c(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movq 0x10(%rsp), %rax
movl %eax, %ecx
movl 0xc(%rsp), %esi
subl %esi, %ecx
movq 0x48(%rsp), %r8
cmpl 0x50(%rsp), %ecx
jge 0x9a66
movl $0x7, %edi
leaq 0x4c48(%rip), %rdx      # 0xe6a5
xorl %eax, %eax
callq 0x43d0
jmp 0x9a7c
movl $0x7, %edi
leaq 0x4c0d(%rip), %rdx      # 0xe67f
movq %r8, %rcx
xorl %eax, %eax
callq 0x43d0
movq 0x9535(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
addl $0xa, 0xc(%rsp)
leal 0x1(%rbp), %eax
movl 0x84(%r13), %ecx
addl %r14d, %ecx
cmpl %ecx, %ebp
movl %eax, %r14d
jl 0x9848
cmpl $0xc, 0x68(%rsp)
jl 0x9d00
movl 0x80(%r13), %r12d
leaq 0x8(%r13), %rax
movq %rax, 0x40(%rsp)
movl $0x9, 0xc(%rsp)
leaq 0x48(%rsp), %r14
leaq 0x4da5(%rip), %rbx      # 0xe883
cmpl $-0x3, 0x10(%rsp)
jl 0x9cdb
movq 0x38(%rsp), %rax
movl 0x84(%rax), %r13d
movl $0x6, %ebp
movq 0x50(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
leaq 0x4d79(%rip), %rcx      # 0xe884
xorl %r8d, %r8d
callq 0x44a0
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x5c8e
movl 0x20(%rsp), %r15d
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9b49
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
cmpl $0x7, %r15d
jg 0x9b81
movl $0x9, %eax
subl %r15d, %eax
movl %eax, %r15d
shrl $0x1f, %r15d
addl %eax, %r15d
sarl %r15d
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4610
decl %r15d
jne 0x9b71
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x5c8e
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x40b0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9bc4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
movl 0x50(%rsp), %r15d
cmpl $0x8, %r15d
jg 0x9be3
addl $-0x9, %r15d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4610
incl %r15d
jne 0x9bd3
cmpq $0x9, 0x50(%rsp)
jbe 0x9c38
movl $0x6, %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x42e0
movq %r14, %rdi
movq %r15, %rsi
callq 0x4380
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9c29
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %r14, %rdi
leaq 0x4a77(%rip), %rsi      # 0xe6aa
callq 0x4610
movq 0x38(%rsp), %rax
cmpl %r13d, 0x7c(%rax)
jne 0x9c62
movq 0x38(%rsp), %rax
cmpl %r12d, 0x78(%rax)
jne 0x9c62
movq 0x9363(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4310
movq 0x10(%rsp), %rax
movl %eax, %ecx
subl %ebp, %ecx
movq 0x48(%rsp), %r8
cmpl 0x50(%rsp), %ecx
jge 0x9c8c
movl 0xc(%rsp), %edi
movl %ebp, %esi
leaq 0x4a22(%rip), %rdx      # 0xe6a5
xorl %eax, %eax
callq 0x43d0
jmp 0x9ca3
movl 0xc(%rsp), %edi
movl %ebp, %esi
leaq 0x49e6(%rip), %rdx      # 0xe67f
movq %r8, %rcx
xorl %eax, %eax
callq 0x43d0
movq 0x930e(%rip), %rax      # 0x12fb8
movq (%rax), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x43b0
addl $0xa, %ebp
leal 0x1(%r13), %eax
movq 0x38(%rsp), %rcx
movl 0x84(%rcx), %ecx
addl 0x70(%rsp), %ecx
cmpl %ecx, %r13d
movl %eax, %r13d
jl 0x9afa
addl $0x2, 0xc(%rsp)
leal 0x1(%r12), %eax
movq 0x38(%rsp), %rcx
movl 0x80(%rcx), %ecx
addl 0x78(%rsp), %ecx
cmpl %ecx, %r12d
movl %eax, %r12d
jl 0x9ade
callq 0x4550
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9d21
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d3f
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d6c
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9d6f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x42d0
jmp 0x9d6f
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d6c
jmp 0x9d6c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9d8b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0x45a0
nop