// File: /workspace/github_c_makefile_star2_O2/ksherlock[P]nroff_man/tbl.c
// Function: tbl
void tbl(void) {


	int cols = 0;
	unsigned st = 0;
	unsigned e_flag = 0;
	unsigned e_width = 0;
	unsigned z_flag = 0;

	memset(column_width, 0, sizeof(column_width));
	memset(column_align, 0, sizeof(column_align));
	memset(column_n_left, 0, sizeof(column_n_left));
	memset(column_n_right, 0, sizeof(column_n_right));

	lines = NULL;
	lines_capacity = 0;
	lines_length = 0;


	lines = malloc(sizeof(char *) * 64);
	if (!lines) man_err(1,"malloc");
	lines_capacity = 64;

	for(;;) {
		const unsigned char *cp = read_text();
		if (type == tkEOF) {
			man_warnx("TS without TE");
			break;
		}

		if (type == tkTE) break;
		if (type == tkPP) continue;
		if (type == tkPD) continue;
		if (type != tkTEXT) {
			man_warnx1s("unsupported %s within tbl", token_names[type]);
			break;
		}

		// text!
		unsigned x = strlen(cp);
		if (!x) continue;

		if (st == 0) {
			// (optional) option string (;-terminated)
			++st;
			if (cp[x-1] == ';') continue;
		}

		if (st == 1) {

			// 1+ format strings, final one is '.' terminated.
			// currently, only one line is (partially) supported

			// format string...
			cols = -1;
			unsigned w_flag = 0;

			for (unsigned i = 0; ;++i) {
				unsigned c = cp[i];
				if (c == 0) break;
				c = tolower(c);

				if (c == ',') {
					// multiple formats on one line.
					cols = -1;
					continue;
				}

				if (c == '.') {
					++st;
					++cols;
					if (cols < 1) {
						cols = 1;
						column_align[0] = align_left;
					}
					if (cols >= MAX_COLS) cols = MAX_COLS - 1;
					break;
				}
				if (c == 'l' || c == 'r' || c == 'c' || c == 'n' || c == 'a') {
					++cols;
				}
				if (cols < 0 || cols >= MAX_COLS) continue;

				switch(c) {
				case 'l':
				case 'a': // alphabetic subcolumn
					column_align[cols] = align_left;
					break;
				case 'r':
					column_align[cols] = align_right;
					break;
				case 'n':
					column_align[cols] = align_number;
					break;
				case 'c': 
					column_align[cols] = align_center;
					break;

				case 'e':
					e_flag |= (1 << cols);
					break;
				case 'z':
					z_flag |= (1 << cols);
					break;


				case 'w':
					// followed by unit-less integer -or- (width expression)
					c = cp[++i];
					x = 0;
					if (c == '(') {
						++i;
						x = get_unit(cp + i, 0, 0);
						for(;;) {
							c = cp[++i];
							if (c == ')' || c == 0) break;
						}
					}
					if (isdigit(c)) {
						x = c - '0';
						while (isdigit(c = cp[++i])) {
							x *= 10;
							x += c - '0';
						}
					}
					column_width[cols] = x;
					if (x) w_flag |= (1 << cols);
					--i;
					break;
				}
				// silently ignore everything else....
			}

			// e/z/w interaction...
			// z_flag w/o w_flag is an error...
			if ((z_flag & w_flag) != z_flag) {
				z_flag &= w_flag;
			}
			if (w_flag & e_flag) {
				w_flag &= e_flag;
				for (unsigned i = 0, mask = 1; i < cols; ++i, mask <<= 1) {
					if (w_flag & mask) {
						x = column_width[i];
						if (i > e_width) e_width = x;
					}
				}
			}

			continue;
		}


		if (lines_length == lines_capacity) {
			lines_capacity <<= 1;
			char **tmp = realloc(lines, lines_capacity * sizeof(char *));
			if (!tmp) man_err(1, "realloc");
			lines = tmp;
		}

		// a line of data...
		// count the columns...
		unsigned nc = 1;
		unsigned l = 0;
		for (l = 0; ; ++l) {
			unsigned c = cp[l];
			if (!c) break;
			if (c == '\t') ++nc;
		}

		if (!l) {
			lines[lines_length++] = SPECIAL_BLANK;
			continue;
		}

		// todo: '-', '=' just draw a line.
		if (l == 1) {
			if (cp[0] == '_' || cp[0] == '=') {
				lines[lines_length++] = SPECIAL_DASH;
				continue;
			}
		}

		if (nc > cols) nc = cols;

		// each chunk has 1 byte length, 1 byte length w/o formatting.
		char *line = malloc(l + cols * 2 + 2);
		if (!line) man_err(1, "malloc");
		memset(line, 0, l + cols * 2 + 2);
		lines[lines_length++] = line;

		for (unsigned i = 0, j = 0, col = 0, mask = 1; col < nc; ++col, mask <<= 1) {

			unsigned st = i;
			unsigned c;

			for (;;) { c = cp[i++]; if (c == '\t' || c == 0) break; }
			unsigned end = i - 1;

			line[j++] = end - st; // total length

			unsigned x = 0;

			if (column_align[col] == align_number) {
				int left;
				x = num_width(cp + st, end - st, &left);

				if (left > 0) {
					int right = x - left;
					if (left > column_n_left[col]) column_n_left[col] = left;
					if (right > column_n_right[col]) column_n_right[col] = right;
				}
			} else {
				x = xstrnlen(cp + st, end - st);
			}

			if (!(z_flag & mask)) {
				if (x > column_width[col]) column_width[col] = x;
			}

			if (e_flag & mask) {
				if (x > e_width) e_width = x;
			}

			line[j++] = x;
			while (st < end) line[j++] = cp[st++];
		}

		// todo -- only first N lines to calc width?

	}

	// re-calc n columns:
	for (unsigned col = 0, mask = 1; col < cols; ++col, mask <<= 1) {
		if (z_flag & mask) continue;
		if (column_align[col] == align_number) {
			unsigned x = column_n_left[col] + column_n_right[col];
			unsigned w = column_width[col];
			if (x > w)
				column_width[col] = x;
			else if (x < w) {
				// adjust left so content will be centered.
				unsigned sp = (w - x) >> 1;
				column_n_left[col] += sp;
				x = w;
			}

			if ((e_flag & mask) && x > e_width)
				e_width = x;

		}
	}

	// resize e columns?
	if (e_flag) {
		for (unsigned col = 0, mask = 1; col < cols; ++col, mask <<= 1) {
			if (e_flag & mask) column_width[col] = e_width;
		}
	}


	// calculate the total width (for _)
	unsigned twidth = -3; // account for extra padding
	for (unsigned i = 0, mask = 1; i < cols; ++i, mask <<= 1) {

		if (e_flag & mask) {
			column_width[i] = e_width;
			twidth += e_width;
		} else {
			twidth += column_width[i];
		}
		twidth += 3;
	}

	// now print the buffered table...

	for (unsigned i = 0; i < lines_length; ++i) {
		unsigned char *line = lines[i];


		if (line == SPECIAL_BLANK) {
			fputc('\n', stdout);
			continue;
		}
		if (line == SPECIAL_DASH) {
			for (unsigned j = 0; j < in; ++j) fputc(' ', stdout);
			for (unsigned j = 0; j < twidth; ++j)
				fputc('_', stdout);
			fputc('\n', stdout);
			continue;
		}

		unsigned padding = 0;
		unsigned k = 0;
		for (unsigned col = 0, offset = 0; col < cols; ++col) {
			unsigned w = column_width[col];
			unsigned align = column_align[col];

			unsigned ll = line[offset++]; // width w/ formatting
			unsigned l = line[offset++]; // printable width

			unsigned sp = w > l ? w - l : 0;


			switch(align) {
			default:
			case align_left:
				break;
			case align_right:
				padding += sp;
				sp = 0;
				break;
			case align_center:
				padding += sp >> 1;
				sp = (sp+1) >> 1;
				break;
			case align_number: {
					int left;
					int x;
					num_width(line + offset, l, &left);
					if (left < 0) {
						// just center it..
						padding += sp >> 1;
						sp = (sp+1) >> 1;
					} else {
						x = column_n_left[col] - left;
						if (x > 0) padding += x;
						sp = sp - x;
					}
				}
				break;

			}

			for (unsigned i = 0; i < padding; ++i) {
				buffer[k++] = ' ';
			}

			for(unsigned i = 0; i < ll; ++i) {
				buffer[k++] = line[offset++];
			}

			padding = sp + 3; // 3 spaces of padding between columns + alignment.
		}


		buffer[k++] = '\n';
		buffer[k++] = 0;
		print(buffer, 0);

		free(line);
	}

	
	free(lines);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x910d(%rip)     # 0x10bd0
movaps %xmm0, 0x90f6(%rip)     # 0x10bc0
movaps %xmm0, 0x910f(%rip)     # 0x10be0
movaps %xmm0, 0x9118(%rip)     # 0x10bf0
movaps %xmm0, 0x9121(%rip)     # 0x10c00
movaps %xmm0, 0x912a(%rip)     # 0x10c10
movaps %xmm0, 0x9133(%rip)     # 0x10c20
andl $0x0, 0x9154(%rip)      # 0x10c48
movaps %xmm0, 0x9135(%rip)     # 0x10c30
andl $0x0, 0x914a(%rip)      # 0x10c4c
movl $0x200, %edi            # imm = 0x200
callq 0x4130
movq %rax, 0x912d(%rip)      # 0x10c40
testq %rax, %rax
jne 0x7b2e
callq 0x4060
movl (%rax), %esi
leaq 0x231f(%rip), %rdx      # 0x9e45
pushq $0x1
popq %rdi
callq 0x4712
movl $0x40, 0x9110(%rip)     # 0x10c48
xorl %r14d, %r14d
leaq 0x67ce(%rip), %rbx      # 0xe310
movl $0x0, 0xc(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %ebp, %ebp
callq 0x5a94
movq %rax, %rdi
movl (%rbx), %eax
leal -0x15(%rax), %ecx
cmpl $0x2, %ecx
jb 0x7b52
cmpl $0x1, %eax
jne 0x80a4
movq %rdi, 0x18(%rsp)
callq 0x4090
movq 0x18(%rsp), %rdi
testl %eax, %eax
je 0x7b52
cmpl $0x1, %r15d
je 0x7b9b
testl %r15d, %r15d
jne 0x7dc9
decl %eax
cmpb $0x3b, (%rdi,%rax)
pushq $0x1
popq %r15
je 0x7b52
xorl %r12d, %r12d
movl $0x0, 0x10(%rsp)
pushq $-0x1
popq %rax
movl %eax, %ebp
movl %r12d, %eax
movzbl (%rdi,%rax), %edi
testl %edi, %edi
je 0x7d7d
callq 0x4110
leal -0x6c(%rax), %ecx
cmpl $0x6, %ecx
jbe 0x7be0
cmpl $0x2c, %eax
je 0x7c49
cmpl $0x61, %eax
je 0x7be8
cmpl $0x63, %eax
je 0x7be8
cmpl $0x2e, %eax
jne 0x7bea
jmp 0x8079
pushq $0x45
popq %rdx
btl %ecx, %edx
jae 0x7bc7
incl %ebp
cmpl $0x7, %ebp
movq 0x18(%rsp), %rdi
ja 0x7d2c
movq %rbp, %r15
movl %ebp, %ebp
cmpl $0x61, %eax
je 0x7c39
cmpl $0x63, %eax
je 0x7d1b
cmpl $0x65, %eax
je 0x7d3d
cmpl $0x7a, %eax
je 0x7d34
cmpl $0x6e, %eax
je 0x7c58
cmpl $0x72, %eax
je 0x7d0b
cmpl $0x77, %eax
je 0x7c6b
cmpl $0x6c, %eax
jne 0x7d29
leaq 0x8fa0(%rip), %rax      # 0x10be0
andl $0x0, (%rax,%rbp,4)
jmp 0x7d29
pushq $-0x1
popq %rax
movl %eax, %ebp
movq 0x18(%rsp), %rdi
jmp 0x7d2c
leaq 0x8f81(%rip), %rax      # 0x10be0
movl $0x3, (%rax,%rbp,4)
jmp 0x7d29
movq %r14, 0x28(%rsp)
movl %r13d, 0x24(%rsp)
leal 0x1(%r12), %ebx
movb (%rdi,%rbx), %r13b
xorl %r14d, %r14d
cmpb $0x28, %r13b
jne 0x7cb4
addl $0x2, %r12d
addq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x61c3
movq 0x18(%rsp), %rcx
movl %eax, %r14d
movl %r12d, %ebx
incl %ebx
movzbl (%rcx,%rbx), %r13d
cmpl $0x29, %r13d
je 0x7cb4
testl %r13d, %r13d
jne 0x7ca2
callq 0x41c0
movq (%rax), %rax
movzbl %r13b, %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x7d46
movl 0x24(%rsp), %r13d
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %esi
pushq $0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
testl %r14d, %r14d
cmovel %r14d, %eax
leaq 0x8ed5(%rip), %rdx      # 0x10bc0
movl %r14d, (%rdx,%rbp,4)
movq %r15, %rbp
orl %eax, %esi
movl %esi, 0x10(%rsp)
decl %ebx
movl %ebx, %r12d
movq 0x28(%rsp), %r14
leaq 0x6607(%rip), %rbx      # 0xe310
jmp 0x7d2c
leaq 0x8ece(%rip), %rax      # 0x10be0
movl $0x1, (%rax,%rbp,4)
jmp 0x7d29
leaq 0x8ebe(%rip), %rax      # 0x10be0
movl $0x2, (%rax,%rbp,4)
movq %r15, %rbp
incl %r12d
jmp 0x7bab
movq %r15, %rbp
btsl %ebp, %r14d
jmp 0x7d2c
movq %r15, %rbp
btsl %ebp, %r13d
jmp 0x7d2c
addl $-0x30, %ecx
incl %ebx
movl %ecx, %r14d
movl 0x24(%rsp), %r13d
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %esi
movl %ebx, %ecx
movzbl (%rdi,%rcx), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x7cd5
imull $0xa, %r14d, %edx
leal (%rdx,%rcx), %r14d
addl $-0x30, %r14d
incl %ebx
jmp 0x7d5c
pushq $0x1
popq %r15
movl 0x10(%rsp), %r9d
andl %r9d, %r14d
andl %r13d, %r9d
je 0x7b52
movl %ebp, %eax
leaq 0x8e25(%rip), %rcx      # 0x10bc0
xorl %edx, %edx
pushq $0x1
popq %rsi
movl 0xc(%rsp), %r8d
cmpq %rdx, %rax
je 0x7e6e
testl %r9d, %esi
je 0x7dbe
movl %r8d, %edi
cmpq %rdi, %rdx
jbe 0x7dbe
movl (%rcx), %r8d
incq %rdx
addl %esi, %esi
addq $0x4, %rcx
jmp 0x7da5
movl 0x8e7d(%rip), %esi      # 0x10c4c
cmpl 0x8e73(%rip), %esi      # 0x10c48
jne 0x7e1f
movq %r14, %rbx
addl %esi, %esi
movl %esi, 0x8e66(%rip)      # 0x10c48
movq 0x8e57(%rip), %rdi      # 0x10c40
shlq $0x3, %rsi
callq 0x4150
movq %rax, %r14
testq %rax, %rax
jne 0x7e10
callq 0x4060
movl (%rax), %esi
pushq $0x1
popq %rdi
leaq 0x2069(%rip), %rdx      # 0x9e74
callq 0x4712
movq %r14, 0x8e29(%rip)      # 0x10c40
movq %rbx, %r14
movq 0x18(%rsp), %rdi
xorl %eax, %eax
pushq $0x1
popq %rbx
movl %eax, %ecx
movzbl (%rdi,%rcx), %ecx
cmpl $0x9, %ecx
je 0x7e35
testl %ecx, %ecx
jne 0x7e37
jmp 0x7e3b
incl %ebx
incl %eax
jmp 0x7e24
cmpl $0x1, %eax
je 0x7e78
testl %eax, %eax
jne 0x7eaf
movq 0x8df5(%rip), %rax      # 0x10c40
movl 0x8dfb(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x8df2(%rip)      # 0x10c4c
movq $0x2, (%rax,%rcx,8)
leaq 0x64a7(%rip), %rbx      # 0xe310
jmp 0x7b52
movl %r8d, 0xc(%rsp)
jmp 0x7b52
movzbl (%rdi), %ecx
cmpl $0x5f, %ecx
je 0x7e85
cmpl $0x3d, %ecx
jne 0x7eaf
movq 0x8db4(%rip), %rax      # 0x10c40
movl 0x8dba(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x8db1(%rip)      # 0x10c4c
movq $0x1, (%rax,%rcx,8)
leaq 0x6466(%rip), %rbx      # 0xe310
jmp 0x7b52
movl %r15d, 0x3c(%rsp)
movq %r14, 0x28(%rsp)
cmpl %ebp, %ebx
cmovael %ebp, %ebx
movq %rbp, 0x48(%rsp)
leal (%rax,%rbp,2), %r14d
addl $0x2, %r14d
movq %r14, %rdi
callq 0x4130
movq %rax, %r15
testq %rax, %rax
jne 0x7ef1
callq 0x4060
movl (%rax), %esi
pushq $0x1
popq %rdi
leaq 0x1f59(%rip), %rdx      # 0x9e45
callq 0x4712
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x40c0
xorl %r8d, %r8d
movq 0x8d38(%rip), %rax      # 0x10c40
movl 0x8d3e(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x8d35(%rip)      # 0x10c4c
movq %r15, (%rax,%rcx,8)
movl %ebx, %eax
movq %rax, 0x50(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
pushq $0x1
popq %r9
movl 0xc(%rsp), %esi
movq 0x18(%rsp), %rdi
movl %r13d, 0x24(%rsp)
cmpq 0x50(%rsp), %r8
movl %esi, 0xc(%rsp)
je 0x805e
pushq $-0x1
popq %rax
movl %eax, %r14d
leal (%r14,%rbp), %r12d
incl %r12d
movzbl (%rdi,%r12), %eax
incl %r14d
cmpl $0x9, %eax
je 0x7f65
testl %eax, %eax
jne 0x7f4d
movl %r9d, 0x30(%rsp)
movl %ebx, %eax
movb %r14b, (%r15,%rax)
leaq 0x8c69(%rip), %rax      # 0x10be0
movq %r8, 0x10(%rsp)
cmpl $0x3, (%rax,%r8,4)
movl %ebp, %r13d
leaq (%rdi,%r13), %rdi
movl %r14d, %esi
jne 0x7fe3
leaq 0x44(%rsp), %rdx
callq 0x7a04
movl 0x44(%rsp), %ecx
testl %ecx, %ecx
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %r8
movl 0x30(%rsp), %r9d
jle 0x7ff6
leaq 0x8c4c(%rip), %rdx      # 0x10c00
cmpl (%rdx,%r8,4), %ecx
jle 0x7fc5
leaq 0x8c3f(%rip), %rdx      # 0x10c00
movl %ecx, (%rdx,%r8,4)
movl %eax, %edx
subl %ecx, %edx
leaq 0x8c50(%rip), %rcx      # 0x10c20
cmpl (%rcx,%r8,4), %edx
jle 0x7ff6
leaq 0x8c43(%rip), %rcx      # 0x10c20
movl %edx, (%rcx,%r8,4)
jmp 0x7ff6
callq 0x7364
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %r8
movl 0x30(%rsp), %r9d
testl %r9d, 0x28(%rsp)
jne 0x8015
leaq 0x8bbc(%rip), %rcx      # 0x10bc0
cmpl (%rcx,%r8,4), %eax
jbe 0x8015
leaq 0x8baf(%rip), %rcx      # 0x10bc0
movl %eax, (%rcx,%r8,4)
addl %r14d, %ebp
incl %ebp
cmpl %esi, %eax
movl %esi, %ecx
cmoval %eax, %ecx
leal 0x1(%rbx), %edx
addl $0x2, %ebx
movl %edx, %edx
movb %al, (%r15,%rdx)
movq 0x18(%rsp), %rdi
cmpq %r12, %r13
jae 0x8048
movb (%rdi,%r13), %al
incq %r13
movl %ebx, %edx
incl %ebx
movb %al, (%r15,%rdx)
jmp 0x8032
movl 0x24(%rsp), %r13d
testl %r13d, %r9d
cmovnel %ecx, %esi
incq %r8
addl %r9d, %r9d
jmp 0x7f38
movq 0x28(%rsp), %r14
leaq 0x62a6(%rip), %rbx      # 0xe310
movq 0x48(%rsp), %rbp
movl 0x3c(%rsp), %r15d
jmp 0x7b52
testl %ebp, %ebp
js 0x8081
incl %ebp
jmp 0x808d
andl $0x0, 0x8b58(%rip)      # 0x10be0
pushq $0x1
popq %rax
movl %eax, %ebp
movl 0x10(%rsp), %r9d
cmpl $0x7, %ebp
pushq $0x7
popq %rax
cmovael %eax, %ebp
pushq $0x2
popq %r15
jmp 0x7d86
cmpl $0x29, %eax
je 0x80d8
testl %eax, %eax
jne 0x80bd
leaq 0x1d98(%rip), %rsi      # 0x9e4c
xorl %edi, %edi
callq 0x4726
jmp 0x80d8
cltq
leaq 0x603a(%rip), %rcx      # 0xe100
movq (%rcx,%rax,8), %rdx
leaq 0x1d89(%rip), %rsi      # 0x9e5a
xorl %edi, %edi
callq 0x47c8
movl %ebp, %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,4), %rax
pushq $0x1
popq %rcx
xorl %edx, %edx
leaq 0x8acd(%rip), %r11      # 0x10bc0
movl 0xc(%rsp), %r10d
cmpq %rdx, %rax
je 0x8163
testl %r14d, %ecx
jne 0x815b
leaq 0x8ad7(%rip), %rsi      # 0x10be0
cmpl $0x3, (%rdx,%rsi)
jne 0x815b
leaq 0x8aea(%rip), %rsi      # 0x10c00
movl (%rdx,%rsi), %edi
leaq 0x8b00(%rip), %rsi      # 0x10c20
movl (%rdx,%rsi), %esi
addl %edi, %esi
movl (%rdx,%r11), %r8d
movl %r8d, %r9d
subl %esi, %r9d
jae 0x8137
movl %esi, (%rdx,%r11)
jmp 0x814d
jbe 0x814d
shrl %r9d
addl %edi, %r9d
leaq 0x8aba(%rip), %rsi      # 0x10c00
movl %r9d, (%rdx,%rsi)
movl %r8d, %esi
cmpl %r10d, %esi
cmovbel %r10d, %esi
testl %r13d, %ecx
cmovnel %esi, %r10d
addl %ecx, %ecx
addq $0x4, %rdx
jmp 0x80f8
testl %r13d, %r13d
je 0x8183
pushq $0x1
popq %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x8183
testl %r13d, %ecx
je 0x817b
movl %r10d, (%rdx,%r11)
addl %ecx, %ecx
addq $0x4, %rdx
jmp 0x816d
pushq $0x1
popq %rcx
pushq $-0x3
popq %r14
xorl %edx, %edx
cmpq %rdx, %rax
je 0x81b2
testl %r13d, %ecx
je 0x819f
movl %r10d, (%rdx,%r11)
movl %r10d, %esi
jmp 0x81a3
movl (%rdx,%r11), %esi
addl %esi, %r14d
addl $0x3, %r14d
addl %ecx, %ecx
addq $0x4, %rdx
jmp 0x818c
xorl %r8d, %r8d
movq 0x5e04(%rip), %r12      # 0xdfc0
pushq $0xa
popq %rbp
leaq 0x8a8a(%rip), %r15      # 0x10c50
xorl %ebx, %ebx
movq %r14, 0x28(%rsp)
movl 0x8a79(%rip), %eax      # 0x10c4c
movq 0x8a66(%rip), %rdi      # 0x10c40
cmpq %rax, %rbx
jae 0x83ca
movq (%rdi,%rbx,8), %r13
cmpq $0x2, %r13
je 0x823d
movq %rbx, 0x30(%rsp)
cmpq $0x1, %r13
jne 0x824d
xorl %ebx, %ebx
leaq 0x616b(%rip), %r13      # 0xe36c
cmpl (%r13), %ebx
jae 0x8217
movq (%r12), %rsi
pushq $0x20
popq %rdi
callq 0x40d0
incl %ebx
jmp 0x8201
movl %r14d, %ebx
pushq $0x5f
popq %r13
movq (%r12), %rsi
subl $0x1, %ebx
jb 0x8231
movl %r13d, %edi
callq 0x40d0
jmp 0x821e
movl %ebp, %edi
callq 0x40d0
jmp 0x83b3
movq (%r12), %rsi
movl %ebp, %edi
callq 0x40d0
jmp 0x83b8
xorl %r9d, %r9d
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
cmpq %rdi, %r9
je 0x8382
movl (%r11,%r9,4), %r10d
leaq 0x8970(%rip), %rax      # 0x10be0
movl (%rax,%r9,4), %eax
leal 0x1(%rbp), %ecx
movl %ebp, %edx
movzbl (%r13,%rdx), %r12d
addl $0x2, %ebp
movzbl (%r13,%rcx), %esi
subl %esi, %r10d
cmovbl %r8d, %r10d
cmpl $0x3, %eax
je 0x82c1
cmpl $0x2, %eax
je 0x82b0
cmpl $0x1, %eax
jne 0x8330
addl %ebx, %r10d
movl %r10d, %ebx
xorl %r10d, %r10d
jmp 0x8330
movl %r10d, %eax
shrl %eax
addl %ebx, %eax
incl %r10d
shrl %r10d
movl %eax, %ebx
jmp 0x8330
movl %r10d, 0xc(%rsp)
movq %r9, 0x18(%rsp)
movl %ebp, %edi
addq %r13, %rdi
leaq 0x40(%rsp), %rdx
callq 0x7a04
movl 0x40(%rsp), %eax
testl %eax, %eax
js 0x8308
leaq 0x8917(%rip), %rcx      # 0x10c00
movq 0x18(%rsp), %r9
movl (%rcx,%r9,4), %ecx
subl %eax, %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movl 0xc(%rsp), %r10d
subl %ecx, %r10d
jmp 0x831d
movl 0xc(%rsp), %r10d
movl %r10d, %eax
shrl %eax
incl %r10d
shrl %r10d
movq 0x18(%rsp), %r9
addl %ebx, %eax
movl %eax, %ebx
movq 0x10(%rsp), %rdi
leaq 0x8893(%rip), %r11      # 0x10bc0
xorl %r8d, %r8d
leal (%rbx,%r14), %ecx
leal (%r14,%r12), %eax
subl %ebx, %r12d
negl %ebx
xorl %edx, %edx
cmpl %edx, %ebx
je 0x8355
movl %r14d, %esi
incl %r14d
movb $0x20, (%rsi,%r15)
decl %edx
incl %r12d
jmp 0x833f
subl %edx, %eax
subl $0x1, %r12d
jb 0x8370
movl %ebp, %edx
incl %ebp
movb (%r13,%rdx), %dl
movl %ecx, %esi
incl %ecx
movb %dl, (%rsi,%r15)
jmp 0x8357
addl $0x3, %r10d
incq %r9
movl %r10d, %ebx
movl %eax, %r14d
jmp 0x825c
movl %r14d, %eax
incl %r14d
movb $0xa, (%rax,%r15)
movb $0x0, (%r14,%r15)
movq %r15, %rdi
xorl %esi, %esi
callq 0x711c
movq %r13, %rdi
callq 0x4040
movq 0x28(%rsp), %r14
movq 0x5c10(%rip), %r12      # 0xdfc0
pushq $0xa
popq %rbp
movq 0x30(%rsp), %rbx
incq %rbx
leaq 0x87fe(%rip), %r11      # 0x10bc0
xorl %r8d, %r8d
jmp 0x81cd
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4040