// File: /workspace/github_c_makefile_star2_O3/MikeGray-APH[P]LibLouisAPH/source/outputs/table-output.c
// Function: rules_output
static void rules_output(FILE *output, const struct rule *const*rule_hash, const int rules_max, const enum rule_direction direction, const int use_dots)
{
	const struct rule *rule;
	int i, cnt, most;

#ifdef TABLE_ALLOCATE_HASHES
	if(!rule_hash)
		return;
#endif

	most = 0;
	for(i = 0; i < rules_max; i++)
	{
		rule = rule_hash[i];
		cnt = 0;
		while(rule)
		{
			cnt++;
			if(direction == FORWARD)
				rule = rule->chars_nxt;
			else
				rule = rule->dots_nxt;
		}
		if(cnt > most)
			most = cnt;
		if(!cnt)
			continue;

		fprintf(output, "[%5d] %5d", i, cnt);
		rule = rule_hash[i];
		while(rule)
		{
			fputs("\n   ", output);

			if(direction == FORWARD)
			{
				if(rule->chars_len == 1)
					utf16_output_char_escape(output, rule->chars[0]);
				else
					utf16_output(output, rule->chars, rule->chars_len);
				fputs(" ", output);
				if(use_dots)
					output_dots_string(output, rule->dots, rule->dots_len);
				else
				if(rule->dots_len == 1)
					utf16_output_char_escape(output, rule->dots[0]);
				else
					utf16_output(output, rule->dots, rule->dots_len);
			}
			else
			{
				if(use_dots)
					output_dots_string(output, rule->dots, rule->dots_len);
				else
				if(rule->dots_len == 1)
					utf16_output_char_escape(output, rule->dots[0]);
				else
					utf16_output(output, rule->dots, rule->dots_len);
				fputs(" ", output);
				if(rule->chars_len == 1)
					utf16_output_char_escape(output, rule->chars[0]);
				else
					utf16_output(output, rule->chars, rule->chars_len);
			}
			if(rule->attrs)
				fprintf(output, " <0x%08x>", rule->attrs);

			if(rule->filter_forward)
			{
				fputs("   ", output);
				if(!rule->filter_forward->name)
				{
					if(rule->filter_forward->before)
						pattern_print_reverse(output, rule->filter_forward->before, rule->filter_forward->before_len);
					else
						fputs("-", output);
					fputs("   ", output);
					if(rule->filter_forward->after)
						pattern_print(output, rule->filter_forward->after, attrs_chars);
					else
						fputs("-", output);
				}
				else
					utf16_output(output, rule->filter_forward->name, rule->filter_forward->name_len);
			}

			if(rule->filter_backward)
			{
				fputs("   ", output);
				if(!rule->filter_forward)
					fputs("--   ", output);
				if(!rule->filter_backward->name)
				{
					if(rule->filter_backward->before)
						pattern_print_reverse(output, rule->filter_backward->before, rule->filter_backward->before_len);
					else
						fputs("-", output);
					fputs("   ", output);
					if(rule->filter_backward->after)
						pattern_print(output, rule->filter_backward->after, attrs_chars);
					else
						fputs("-", output);
				}
				else
					utf16_output(output, rule->filter_backward->name, rule->filter_backward->name_len);
			}

			if(direction == FORWARD)
				rule = rule->chars_nxt;
			else
				rule = rule->dots_nxt;
		}
		fputs("\n", output);
	}
	fprintf(output, "most = %d\n", most);
}

// Assembly:
testq %rsi, %rsi
je 0x12170
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
xorl %eax, %eax
cmpl $0x1, %edx
setne %al
leaq 0x8(,%rax,8), %r13
leaq 0x238e(%rip), %r14      # 0x14261
xorl %r12d, %r12d
xorl %edx, %edx
movq %rsi, 0x10(%rsp)
movq (%r15,%r12,8), %rax
testq %rax, %rax
je 0x12141
xorl %ecx, %ecx
incl %ecx
movq (%rax,%r13), %rax
testq %rax, %rax
jne 0x11eec
cmpl %edx, %ecx
cmovgl %ecx, %edx
movl %edx, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x234c(%rip), %rsi      # 0x14256
movl %r12d, %edx
xorl %eax, %eax
callq 0x1160
movq (%r15,%r12,8), %r15
testq %r15, %r15
je 0x12129
leaq 0x2338(%rip), %rdi      # 0x14260
movq %rbx, %rsi
callq 0x1100
cmpl $0x1, %ebp
jne 0x11f4f
movl 0x74(%r15), %edx
leaq 0x18(%r15), %rsi
cmpl $0x1, %edx
jne 0x11f69
movzwl (%rsi), %esi
movq %rbx, %rdi
callq 0x1099e
jmp 0x11f71
movl 0x78(%r15), %edx
leaq 0x46(%r15), %rsi
cmpl $0x1, %edx
jne 0x11f8a
movzwl (%rsi), %esi
movq %rbx, %rdi
callq 0x1099e
jmp 0x11f92
movq %rbx, %rdi
callq 0x108bc
leaq 0x22eb(%rip), %rdi      # 0x14263
movq %rbx, %rsi
callq 0x1100
movl 0x78(%r15), %edx
leaq 0x46(%r15), %rsi
jmp 0x11fa9
movq %rbx, %rdi
callq 0x108bc
leaq 0x22ca(%rip), %rdi      # 0x14263
movq %rbx, %rsi
callq 0x1100
movl 0x74(%r15), %edx
leaq 0x18(%r15), %rsi
cmpl $0x1, %edx
jne 0x11fbb
movzwl (%rsi), %esi
movq %rbx, %rdi
callq 0x1099e
jmp 0x11fc3
movq %rbx, %rdi
callq 0x108bc
movl (%r15), %edx
testl %edx, %edx
je 0x11fdb
movq %rbx, %rdi
leaq 0x2291(%rip), %rsi      # 0x14265
xorl %eax, %eax
callq 0x1160
cmpq $0x0, 0x80(%r15)
je 0x12071
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1100
movq 0x80(%r15), %rax
movq 0x20(%rax), %rsi
testq %rsi, %rsi
je 0x12011
movl 0x28(%rax), %edx
movq %rbx, %rdi
callq 0x108bc
jmp 0x12071
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x12027
movl 0x18(%rax), %edx
movq %rbx, %rdi
callq 0x12171
jmp 0x12036
leaq 0x2226(%rip), %rdi      # 0x14254
movq %rbx, %rsi
callq 0x1100
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1100
movq 0x80(%r15), %rax
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x12062
movq %rbx, %rdi
leaq 0x8245(%rip), %rdx      # 0x1a2a0
callq 0x1135b
jmp 0x12071
leaq 0x21eb(%rip), %rdi      # 0x14254
movq %rbx, %rsi
callq 0x1100
cmpq $0x0, 0x88(%r15)
je 0x12120
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1100
cmpq $0x0, 0x80(%r15)
jne 0x120a3
leaq 0x21d4(%rip), %rdi      # 0x1426f
movq %rbx, %rsi
callq 0x1100
movq 0x88(%r15), %rax
movq 0x20(%rax), %rsi
testq %rsi, %rsi
je 0x120c0
movl 0x28(%rax), %edx
movq %rbx, %rdi
callq 0x108bc
jmp 0x12120
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x120d6
movl 0x18(%rax), %edx
movq %rbx, %rdi
callq 0x12171
jmp 0x120e5
leaq 0x2177(%rip), %rdi      # 0x14254
movq %rbx, %rsi
callq 0x1100
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1100
movq 0x88(%r15), %rax
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x12111
movq %rbx, %rdi
leaq 0x8196(%rip), %rdx      # 0x1a2a0
callq 0x1135b
jmp 0x12120
leaq 0x213c(%rip), %rdi      # 0x14254
movq %rbx, %rsi
callq 0x1100
movq (%r15,%r13), %r15
jmp 0x11f18
leaq 0x1f1c(%rip), %rdi      # 0x1404c
movq %rbx, %rsi
callq 0x1100
movq 0x10(%rsp), %r15
movl 0xc(%rsp), %edx
incq %r12
cmpq $0x100, %r12            # imm = 0x100
jne 0x11edd
leaq 0x20e0(%rip), %rsi      # 0x14238
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1160
retq