// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x88b8(%rip)     # 0x10bd0
movaps %xmm0, 0x88a1(%rip)     # 0x10bc0
movaps %xmm0, 0x88ba(%rip)     # 0x10be0
movaps %xmm0, 0x88c3(%rip)     # 0x10bf0
movaps %xmm0, 0x88cc(%rip)     # 0x10c00
movaps %xmm0, 0x88d5(%rip)     # 0x10c10
movaps %xmm0, 0x88de(%rip)     # 0x10c20
movaps %xmm0, 0x88e7(%rip)     # 0x10c30
movq $0x0, 0x88ec(%rip) # 0x10c40
xorl %ebx, %ebx
movl %ebx, 0x88ec(%rip)      # 0x10c48
movl %ebx, 0x88ea(%rip)      # 0x10c4c
movl $0x200, %edi            # imm = 0x200
callq 0x4140
movq %rax, 0x88cd(%rip)      # 0x10c40
testq %rax, %rax
jne 0x8390
callq 0x4060
movl (%rax), %esi
leaq 0x1acf(%rip), %rdx      # 0x9e55
movl $0x1, %edi
callq 0x4aab
movl $0x40, 0x88ae(%rip)     # 0x10c48
leaq 0x5f6f(%rip), %r15      # 0xe310
xorl %ebp, %ebp
xorl %r13d, %r13d
movl $0x0, 0x18(%rsp)
xorl %r14d, %r14d
callq 0x60e6
movq %rax, %r12
movslq (%r15), %rax
cmpq $0x14, %rax
jle 0x83e2
cmpl $0x15, %eax
je 0x878c
cmpl $0x16, %eax
je 0x878c
cmpl $0x29, %eax
je 0x866d
jmp 0x8654
testl %eax, %eax
je 0x8644
cmpl $0x1, %eax
jne 0x8654
movq %r12, %rdi
callq 0x40a0
testl %eax, %eax
je 0x878c
movl 0x18(%rsp), %ecx
testl %ecx, %ecx
je 0x877b
movq %rbx, 0x10(%rsp)
cmpl $0x1, %ecx
jne 0x8674
movl %ebp, 0x28(%rsp)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movl %ebp, %eax
movzbl (%r12,%rax), %edi
movl $0x4, %ebx
testl %edi, %edi
je 0x84e5
callq 0x4120
cmpl $0x62, %eax
jle 0x84a3
leal -0x6c(%rax), %ecx
cmpl $0x6, %ecx
ja 0x8464
movl $0x45, %edx
btl %ecx, %edx
jb 0x8469
cmpl $0x63, %eax
jne 0x846c
incl %r14d
cmpl $0x7, %r14d
ja 0x84e0
xorl %ebx, %ebx
cmpl $0x6d, %eax
jg 0x84b4
cmpl $0x64, %eax
jg 0x8503
cmpl $0x61, %eax
je 0x850d
cmpl $0x63, %eax
jne 0x84e5
movl %r14d, %eax
leaq 0x8746(%rip), %rcx      # 0x10be0
movl $0x2, (%rcx,%rax,4)
jmp 0x84e5
cmpl $0x2c, %eax
je 0x84da
cmpl $0x2e, %eax
je 0x84f9
cmpl $0x61, %eax
je 0x8469
jmp 0x846c
cmpl $0x76, %eax
jg 0x8520
cmpl $0x6e, %eax
je 0x8563
cmpl $0x72, %eax
jne 0x84e5
movl %r14d, %eax
leaq 0x870f(%rip), %rcx      # 0x10be0
movl $0x1, (%rcx,%rax,4)
jmp 0x84e5
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x6, %ebx
cmpl $0x6, %ebx
je 0x84f2
testl %ebx, %ebx
jne 0x8727
incl %ebp
jmp 0x8434
testl %r14d, %r14d
js 0x853a
incl %r14d
jmp 0x854a
cmpl $0x65, %eax
je 0x8579
cmpl $0x6c, %eax
jne 0x84e5
movl %r14d, %eax
leaq 0x86c9(%rip), %rcx      # 0x10be0
movl $0x0, (%rcx,%rax,4)
jmp 0x84e5
cmpl $0x77, %eax
je 0x8582
cmpl $0x7a, %eax
jne 0x84e5
movq 0x10(%rsp), %rax
btsl %r14d, %eax
movq %rax, 0x10(%rsp)
jmp 0x84e5
movl $0x0, 0x869c(%rip)      # 0x10be0
movl $0x1, %r14d
movl 0x18(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
cmpl $0x7, %r14d
movl $0x7, %eax
cmovgel %eax, %r14d
jmp 0x84e5
movl %r14d, %eax
leaq 0x8673(%rip), %rcx      # 0x10be0
movl $0x3, (%rcx,%rax,4)
jmp 0x84e5
btsl %r14d, %r13d
jmp 0x84e5
movl %r13d, 0x8(%rsp)
movq %r14, 0x20(%rsp)
leal 0x1(%rbp), %r13d
movb (%r12,%r13), %bl
xorl %r14d, %r14d
cmpb $0x28, %bl
jne 0x85c3
addl $0x2, %ebp
leaq (%r12,%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x68aa
movl %eax, %r14d
movl %ebp, %r13d
incl %r13d
movzbl (%r12,%r13), %ebx
cmpl $0x29, %ebx
je 0x85c3
testl %ebx, %ebx
jne 0x85b2
callq 0x41d0
movq (%rax), %rcx
movzbl %bl, %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x85da
movl %r14d, %eax
jmp 0x85ec
addl $-0x30, %eax
incl %r13d
movzbl (%r12,%r13), %edx
testb $0x8, 0x1(%rcx,%rdx,2)
jne 0x85f3
movq 0x20(%rsp), %r14
jmp 0x8613
movq 0x20(%rsp), %r14
movzbl %dl, %edx
leal (%rax,%rax,4), %eax
leal (%rdx,%rax,2), %eax
addl $-0x30, %eax
incl %r13d
movzbl (%r12,%r13), %edx
testb $0x8, 0x1(%rcx,%rdx,2)
jne 0x85f8
movl %r14d, %edx
movl $0x1, %esi
movl %r14d, %ecx
shll %cl, %esi
leaq 0x8599(%rip), %rcx      # 0x10bc0
movl %eax, (%rcx,%rdx,4)
testl %eax, %eax
cmovel %eax, %esi
orl %esi, %r15d
decl %r13d
xorl %ebx, %ebx
movl %r13d, %ebp
movl 0x8(%rsp), %r13d
jmp 0x84e5
xorl %edi, %edi
leaq 0x180f(%rip), %rsi      # 0x9e5c
callq 0x41f0
jmp 0x866d
leaq 0x5aa5(%rip), %rcx      # 0xe100
movq (%rcx,%rax,8), %rdx
xorl %edi, %edi
leaq 0x1802(%rip), %rsi      # 0x9e6a
callq 0x427b
movb $0x1, %al
jmp 0x878e
movl %ecx, 0x18(%rsp)
movl 0x85ca(%rip), %esi      # 0x10c48
cmpl %esi, 0x85c8(%rip)      # 0x10c4c
jne 0x86cb
movq %r14, %rbx
addl %esi, %esi
movl %esi, 0x85b7(%rip)      # 0x10c48
movq 0x85a8(%rip), %rdi      # 0x10c40
shlq $0x3, %rsi
callq 0x4160
movq %rax, %r14
testq %rax, %rax
jne 0x86c1
callq 0x4060
movl (%rax), %esi
movl $0x1, %edi
leaq 0x17c8(%rip), %rdx      # 0x9e84
callq 0x4aab
movq %r14, 0x8578(%rip)      # 0x10c40
movq %rbx, %r14
xorl %eax, %eax
movl $0x1, %ebx
movl %eax, %ecx
movzbl (%r12,%rcx), %ecx
testl %ecx, %ecx
je 0x86e8
cmpl $0x9, %ecx
jne 0x86e4
incl %ebx
movb $0x1, %cl
jmp 0x86ea
xorl %ecx, %ecx
incl %eax
testb %cl, %cl
jne 0x86d2
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
je 0x87a5
testl %ecx, %ecx
jne 0x87db
movq 0x8535(%rip), %rax      # 0x10c40
movl 0x853b(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x8532(%rip)      # 0x10c4c
movq $0x2, (%rax,%rcx,8)
jmp 0x87d2
movq 0x10(%rsp), %rbx
andl %r15d, %ebx
xorl %eax, %eax
andl %r13d, %r15d
je 0x89a2
testl %r14d, %r14d
movl 0x28(%rsp), %ebp
je 0x89b9
movl %r14d, %ecx
movl $0x1, %edx
leaq 0x846a(%rip), %rsi      # 0x10bc0
xorl %edi, %edi
testl %r15d, %edx
je 0x8766
movl %ebp, %eax
cmpq %rax, %rdi
jbe 0x8766
movl (%rsi), %ebp
incq %rdi
addl %edx, %edx
addq $0x4, %rsi
xorl %eax, %eax
cmpq %rdi, %rcx
jne 0x8758
jmp 0x89b9
decl %eax
movl $0x1, 0x18(%rsp)
cmpb $0x3b, (%r12,%rax)
jne 0x879b
xorl %eax, %eax
testb %al, %al
je 0x83b1
jmp 0x89c5
movl $0x1, %ecx
jmp 0x840f
movzbl (%r12), %ecx
cmpl $0x5f, %ecx
je 0x87b4
cmpl $0x3d, %ecx
jne 0x87db
movq 0x8485(%rip), %rax      # 0x10c40
movl 0x848b(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x8482(%rip)      # 0x10c4c
movq $0x1, (%rax,%rcx,8)
xorl %eax, %eax
movq 0x10(%rsp), %rbx
jmp 0x878e
movl %r13d, 0x8(%rsp)
cmpl %r14d, %ebx
cmovael %r14d, %ebx
movq %r14, 0x20(%rsp)
leal (%rax,%r14,2), %r14d
incl %r14d
movq %r14, %rdi
callq 0x4140
movq %rax, %r15
testq %rax, %rax
jne 0x881b
callq 0x4060
movl (%rax), %esi
movl $0x1, %edi
leaq 0x163f(%rip), %rdx      # 0x9e55
callq 0x4aab
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x40d0
movq 0x8411(%rip), %rax      # 0x10c40
movl 0x8417(%rip), %ecx      # 0x10c4c
leal 0x1(%rcx), %edx
movl %edx, 0x840e(%rip)      # 0x10c4c
movq %r15, (%rax,%rcx,8)
testl %ebx, %ebx
je 0x89a8
movl %ebx, %eax
movq %rax, 0x40(%rsp)
movl $0x1, %r11d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r10d, %r10d
movl %r11d, 0xc(%rsp)
movl %ebp, %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %ebx, %eax
movl %eax, %ebp
leal (%r14,%rbx), %eax
incl %eax
movzbl (%r12,%rax), %ecx
incl %r14d
cmpl $0x9, %ecx
je 0x888a
leal 0x1(%rbp), %eax
testl %ecx, %ecx
jne 0x886e
movl %edx, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movl %r10d, %eax
movb %r14b, (%r15,%rax)
leaq 0x833f(%rip), %rax      # 0x10be0
cmpl $0x3, (%rax,%r13,4)
jne 0x88fd
movl %ebx, %edi
addq %r12, %rdi
movl %r14d, %esi
leaq 0x3c(%rsp), %rdx
callq 0x8238
movl 0x3c(%rsp), %ecx
testl %ecx, %ecx
movl 0xc(%rsp), %r11d
jle 0x890f
leaq 0x8332(%rip), %rdx      # 0x10c00
cmpl (%rdx,%r13,4), %ecx
jle 0x88df
leaq 0x8325(%rip), %rdx      # 0x10c00
movl %ecx, (%rdx,%r13,4)
movl %eax, %edx
subl %ecx, %edx
leaq 0x8336(%rip), %rcx      # 0x10c20
cmpl (%rcx,%r13,4), %edx
jle 0x890f
leaq 0x8329(%rip), %rcx      # 0x10c20
movl %edx, (%rcx,%r13,4)
jmp 0x890f
movl %ebx, %edi
addq %r12, %rdi
movl %r14d, %esi
callq 0x7aa0
movl 0xc(%rsp), %r11d
movl 0x30(%rsp), %esi
testl %r11d, 0x10(%rsp)
movq 0x28(%rsp), %r10
jne 0x8937
leaq 0x829a(%rip), %rcx      # 0x10bc0
cmpl (%rcx,%r13,4), %eax
jbe 0x8937
leaq 0x828d(%rip), %rcx      # 0x10bc0
movl %eax, (%rcx,%r13,4)
leal 0x1(%r10), %ecx
cmpl %esi, %eax
movl %esi, %r9d
cmoval %eax, %r9d
leal (%rbx,%r14), %edx
testl %r11d, 0x8(%rsp)
cmovel %esi, %r9d
addl $0x2, %r10d
movl %ecx, %ecx
movb %al, (%r15,%rcx)
cmpl %edx, %ebx
jae 0x8985
movl %ebx, %edx
leaq (%r12,%rdx), %rax
movl %ebp, %ecx
subq %rdx, %rcx
movl %r10d, %edx
xorl %esi, %esi
leal (%rdx,%rsi), %edi
movb (%rax,%rsi), %r8b
movb %r8b, (%r15,%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x896f
addl %esi, %r10d
movl %r9d, %ebp
addl %r14d, %ebx
incl %ebx
incq %r13
addl %r11d, %r11d
xorl %eax, %eax
cmpq 0x40(%rsp), %r13
jne 0x885f
jmp 0x89aa
movl 0x28(%rsp), %ebp
jmp 0x89b9
xorl %eax, %eax
movq 0x20(%rsp), %r14
movl 0x8(%rsp), %r13d
movq 0x10(%rsp), %rbx
leaq 0x5950(%rip), %r15      # 0xe310
jmp 0x878e
movl %r14d, %r11d
testl %r14d, %r14d
je 0x8a49
leaq (,%r11,4), %rax
movl $0x1, %ecx
xorl %edx, %edx
leaq 0x81dd(%rip), %rsi      # 0x10bc0
testl %ebx, %ecx
jne 0x8a3e
leaq 0x81f2(%rip), %rdi      # 0x10be0
cmpl $0x3, (%rdx,%rdi)
jne 0x8a3e
leaq 0x8205(%rip), %rdi      # 0x10c00
movl (%rdx,%rdi), %r8d
leaq 0x821a(%rip), %rdi      # 0x10c20
movl (%rdx,%rdi), %edi
addl %r8d, %edi
movl (%rdx,%rsi), %r9d
movl %r9d, %r10d
subl %edi, %r10d
jae 0x8a1d
movl %edi, (%rdx,%rsi)
jmp 0x8a33
jbe 0x8a33
shrl %r10d
addl %r8d, %r10d
leaq 0x81d4(%rip), %rdi      # 0x10c00
movl %r10d, (%rdx,%rdi)
movl %r9d, %edi
cmpl %ebp, %edi
cmovbel %ebp, %edi
testl %r13d, %ecx
cmovnel %edi, %ebp
addl %ecx, %ecx
addq $0x4, %rdx
cmpq %rdx, %rax
jne 0x89e3
testl %r13d, %r13d
je 0x8a7c
testl %r14d, %r14d
je 0x8a7c
leaq (,%r11,4), %rax
movl $0x1, %ecx
xorl %edx, %edx
leaq 0x8157(%rip), %rsi      # 0x10bc0
testl %r13d, %ecx
je 0x8a71
movl %ebp, (%rdx,%rsi)
addl %ecx, %ecx
addq $0x4, %rdx
cmpq %rdx, %rax
jne 0x8a69
testl %r14d, %r14d
je 0x8ac0
leaq (,%r11,4), %rax
movl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
movl $0x1, %ecx
xorl %edx, %edx
leaq 0x8123(%rip), %rsi      # 0x10bc0
testl %r13d, %ecx
je 0x8aa9
movl %ebp, (%rdx,%rsi)
movl %ebp, %edi
jmp 0x8aac
movl (%rdx,%rsi), %edi
addl %edi, %r15d
addl $0x3, %r15d
addl %ecx, %ecx
addq $0x4, %rdx
cmpq %rdx, %rax
jne 0x8a9d
jmp 0x8ac6
movl $0xfffffffd, %r15d      # imm = 0xFFFFFFFD
movq %r14, 0x20(%rsp)
cmpl $0x0, 0x817a(%rip)      # 0x10c4c
je 0x8cf6
xorl %edi, %edi
movq 0x54df(%rip), %r13      # 0xdfc0
leaq 0x5884(%rip), %rbp      # 0xe36c
leaq 0x8161(%rip), %r14      # 0x10c50
leaq 0x80ca(%rip), %r8       # 0x10bc0
xorl %ebx, %ebx
movq %r11, 0x30(%rsp)
movq %r15, 0x18(%rsp)
movq 0x8137(%rip), %rax      # 0x10c40
movq (%rax,%rbx,8), %r12
cmpq $0x2, %r12
je 0x8b69
cmpq $0x1, %r12
jne 0x8b7c
movq %rbx, %r12
cmpl $0x0, (%rbp)
je 0x8b39
xorl %ebx, %ebx
movq (%r13), %rsi
movl $0x20, %edi
callq 0x40e0
incl %ebx
cmpl (%rbp), %ebx
jb 0x8b24
movl %r15d, %ebx
testl %r15d, %r15d
je 0x8b53
movq (%r13), %rsi
movl $0x5f, %edi
callq 0x40e0
decl %ebx
jne 0x8b41
movq (%r13), %rsi
movl $0xa, %edi
callq 0x40e0
movq %r12, %rbx
jmp 0x8cd3
movq (%r13), %rsi
movl $0xa, %edi
callq 0x40e0
jmp 0x8cd3
movq %rbx, 0x10(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x8c98
xorl %r9d, %r9d
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r13d, %r13d
movl (%r8,%r9,4), %r10d
leaq 0x803f(%rip), %rax      # 0x10be0
movl (%rax,%r9,4), %eax
leal 0x1(%rbx), %ecx
movl %ebx, %edx
movzbl (%r12,%rdx), %r15d
addl $0x2, %ebx
movzbl (%r12,%rcx), %esi
subl %esi, %r10d
cmovbl %edi, %r10d
cmpl $0x3, %eax
je 0x8be9
cmpl $0x2, %eax
je 0x8bd9
cmpl $0x1, %eax
jne 0x8c56
addl %r10d, %r13d
xorl %r10d, %r10d
jmp 0x8c56
movl %r10d, %eax
shrl %eax
addl %eax, %r13d
incl %r10d
shrl %r10d
jmp 0x8c56
movl %r10d, 0xc(%rsp)
movq %r9, 0x28(%rsp)
movl %ebx, %edi
addq %r12, %rdi
leaq 0x38(%rsp), %rdx
callq 0x8238
movl 0x38(%rsp), %eax
testl %eax, %eax
js 0x8c30
leaq 0x7fef(%rip), %rcx      # 0x10c00
movq 0x28(%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 0x8c45
movl 0xc(%rsp), %r10d
movl %r10d, %eax
shrl %eax
incl %r10d
shrl %r10d
movq 0x28(%rsp), %r9
addl %eax, %r13d
movq 0x30(%rsp), %r11
xorl %edi, %edi
leaq 0x7f6a(%rip), %r8       # 0x10bc0
testl %r13d, %r13d
je 0x8c69
movl %ebp, %eax
incl %ebp
movb $0x20, (%rax,%r14)
decl %r13d
jne 0x8c5b
testl %r15d, %r15d
je 0x8c83
movl %ebx, %eax
incl %ebx
movb (%r12,%rax), %al
movl %ebp, %ecx
incl %ebp
movb %al, (%rcx,%r14)
decl %r15d
jne 0x8c6e
addl $0x3, %r10d
incq %r9
movl %r10d, %r13d
cmpq %r11, %r9
jne 0x8b96
jmp 0x8c9a
xorl %ebp, %ebp
movl %ebp, %eax
incl %ebp
movb $0xa, (%rax,%r14)
movb $0x0, (%rbp,%r14)
movq %r14, %rdi
xorl %esi, %esi
callq 0x7836
movq %r12, %rdi
callq 0x4040
movq 0x18(%rsp), %r15
movq 0x52f9(%rip), %r13      # 0xdfc0
leaq 0x569e(%rip), %rbp      # 0xe36c
movq 0x10(%rsp), %rbx
incq %rbx
movl 0x7f70(%rip), %eax      # 0x10c4c
cmpq %rax, %rbx
movq 0x30(%rsp), %r11
movl $0x0, %edi
leaq 0x7ed0(%rip), %r8       # 0x10bc0
jb 0x8b02
movq 0x7f43(%rip), %rdi      # 0x10c40
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4040