// File: /workspace/github_c_makefile_star2_O3/MikeGray-APH[P]LibLouisAPH/source/table.c
// Function: table_add_rule
struct rule* table_add_rule(
	struct table *table,
	const enum table_hash_type hash_type,
	const enum rule_direction direction,
	struct filter *filter_forward,
	struct filter *filter_backward,
	const unichar *chars,
	const int chars_len,
	const unichar *dots,
	const int dots_len,
	const int chars_weight,
	const int dots_weight)
{
	struct rule **chars_hash, **dots_hash;
	int *chars_hash_cnt, *dots_hash_cnt;
	unsigned int chars_hash_size, dots_hash_size;

	//NOTE:  these affect the function above when compiling optimal
	chars_hash =
	dots_hash = NULL;
	chars_hash_cnt =
	dots_hash_cnt = NULL;

#ifdef TABLE_ALLOCATE_HASHES
	int size;
#endif

	switch(hash_type)
	{
#ifdef TABLE_ALLOCATE_HASHES

	case TABLE_HASH_INIT:

		if(!table->init_chars_hash)
		{
			size = TABLE_INIT_HASH_SIZE * sizeof(struct rule*);
			table->init_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->init_chars_hash)
			memset(table->init_chars_hash, 0, size);
		}
		if(!table->init_dots_hash)
		{
			ASSERT(table->init_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->init_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->init_dots_hash)
			memset(table->init_dots_hash, 0, size);
		}
		chars_hash = table->init_chars_hash;
		chars_hash_cnt = &table->init_chars_hash_cnt;
		chars_hash_size = TABLE_INIT_HASH_SIZE;
		dots_hash = table->init_dots_hash;
		dots_hash_cnt = &table->init_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_PREMODE:

		if(!table->premode_chars_hash)
		{
			size = TABLE_PREMODE_HASH_SIZE * sizeof(struct rule*);
			table->premode_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->premode_chars_hash)
			memset(table->premode_chars_hash, 0, size);
		}
		if(!table->premode_dots_hash)
		{
			ASSERT(table->premode_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->premode_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->premode_dots_hash)
			memset(table->premode_dots_hash, 0, size);
		}
		chars_hash = table->premode_chars_hash;
		chars_hash_cnt = &table->premode_chars_hash_cnt;
		chars_hash_size = TABLE_PREMODE_HASH_SIZE;
		dots_hash = table->premode_dots_hash;
		dots_hash_cnt = &table->premode_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_POSTMODE:

		if(!table->postmode_chars_hash)
		{
			size = TABLE_POSTMODE_HASH_SIZE * sizeof(struct rule*);
			table->postmode_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->postmode_chars_hash)
			memset(table->postmode_chars_hash, 0, size);
		}
		if(!table->postmode_dots_hash)
		{
			ASSERT(table->postmode_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->postmode_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->postmode_dots_hash)
			memset(table->postmode_dots_hash, 0, size);
		}
		chars_hash = table->postmode_chars_hash;
		chars_hash_cnt = &table->postmode_chars_hash_cnt;
		chars_hash_size = TABLE_POSTMODE_HASH_SIZE;
		dots_hash = table->postmode_dots_hash;
		dots_hash_cnt = &table->postmode_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_PRETRANS:

		if(!table->pretrans_chars_hash)
		{
			size = TABLE_PRETRANS_HASH_SIZE * sizeof(struct rule*);
			table->pretrans_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->pretrans_chars_hash)
			memset(table->pretrans_chars_hash, 0, size);
		}
		if(!table->pretrans_dots_hash)
		{
			ASSERT(table->pretrans_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->pretrans_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->pretrans_dots_hash)
			memset(table->pretrans_dots_hash, 0, size);
		}
		chars_hash = table->pretrans_chars_hash;
		chars_hash_cnt = &table->pretrans_chars_hash_cnt;
		chars_hash_size = TABLE_PRETRANS_HASH_SIZE;
		dots_hash = table->pretrans_dots_hash;
		dots_hash_cnt = &table->pretrans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_TRANS:

		if(!table->trans_chars_hash)
		{
			ASSERT(!table->trans_dots_hash)
			size = TABLE_TRANS_HASH_SIZE * sizeof(struct rule*);
			table->trans_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->trans_chars_hash)
			memset(table->trans_chars_hash, 0, size);
		}
		if(!table->trans_dots_hash)
		{
			ASSERT(table->trans_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->trans_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->trans_dots_hash)
			memset(table->trans_dots_hash, 0, size);
		}
		chars_hash = table->trans_chars_hash;
		chars_hash_cnt = &table->trans_chars_hash_cnt;
		chars_hash_size = TABLE_TRANS_HASH_SIZE;
		dots_hash = table->trans_dots_hash;
		dots_hash_cnt = &table->trans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_POSTTRANS:

		if(!table->posttrans_chars_hash)
		{
			ASSERT(!table->posttrans_dots_hash)
			size = TABLE_TRANS_HASH_SIZE * sizeof(struct rule*);
			table->posttrans_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->posttrans_chars_hash)
			memset(table->posttrans_chars_hash, 0, size);
		}
		if(!table->posttrans_dots_hash)
		{
			ASSERT(table->posttrans_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->posttrans_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->posttrans_dots_hash)
			memset(table->posttrans_dots_hash, 0, size);
		}
		chars_hash = table->posttrans_chars_hash;
		chars_hash_cnt = &table->posttrans_chars_hash_cnt;
		chars_hash_size = TABLE_POSTTRANS_HASH_SIZE;
		dots_hash = table->posttrans_dots_hash;
		dots_hash_cnt = &table->posttrans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_FINI:

		if(!table->fini_chars_hash)
		{
			size = TABLE_FINI_HASH_SIZE * sizeof(struct rule*);
			table->fini_chars_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->fini_chars_hash)
			memset(table->fini_chars_hash, 0, size);
		}
		if(!table->fini_dots_hash)
		{
			ASSERT(table->fini_chars_hash)
			size = TABLE_DOTS_HASH_SIZE * sizeof(struct rule*);
			table->fini_dots_hash = MALLOC(size);
			LOG_ALLOCATE_FAIL_RETURN_NULL(table->fini_dots_hash)
			memset(table->fini_dots_hash, 0, size);
		}
		chars_hash = table->fini_chars_hash;
		chars_hash_cnt = &table->fini_chars_hash_cnt;
		chars_hash_size = TABLE_FINI_HASH_SIZE;
		dots_hash = table->fini_dots_hash;
		dots_hash_cnt = &table->fini_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

#else

	case TABLE_HASH_INIT:

		chars_hash = table->init_chars_hash;
		chars_hash_cnt = &table->init_chars_hash_cnt;
		chars_hash_size = TABLE_INIT_HASH_SIZE;
		dots_hash = table->init_dots_hash;
		dots_hash_cnt = &table->init_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_PREMODE:

		chars_hash = table->premode_chars_hash;
		chars_hash_cnt = &table->premode_chars_hash_cnt;
		chars_hash_size = TABLE_PREMODE_HASH_SIZE;
		dots_hash = table->premode_dots_hash;
		dots_hash_cnt = &table->premode_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_POSTMODE:

		chars_hash = table->postmode_chars_hash;
		chars_hash_cnt = &table->postmode_chars_hash_cnt;
		chars_hash_size = TABLE_POSTMODE_HASH_SIZE;
		dots_hash = table->postmode_dots_hash;
		dots_hash_cnt = &table->postmode_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_PRETRANS:

		chars_hash = table->pretrans_chars_hash;
		chars_hash_cnt = &table->pretrans_chars_hash_cnt;
		chars_hash_size = TABLE_PRETRANS_HASH_SIZE;
		dots_hash = table->pretrans_dots_hash;
		dots_hash_cnt = &table->pretrans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_TRANS:

		chars_hash = table->trans_chars_hash;
		chars_hash_cnt = &table->trans_chars_hash_cnt;
		chars_hash_size = TABLE_TRANS_HASH_SIZE;
		dots_hash = table->trans_dots_hash;
		dots_hash_cnt = &table->trans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_POSTTRANS:

		chars_hash = table->posttrans_chars_hash;
		chars_hash_cnt = &table->posttrans_chars_hash_cnt;
		chars_hash_size = TABLE_POSTTRANS_HASH_SIZE;
		dots_hash = table->posttrans_dots_hash;
		dots_hash_cnt = &table->posttrans_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;

	case TABLE_HASH_FINI:

		chars_hash = table->fini_chars_hash;
		chars_hash_cnt = &table->fini_chars_hash_cnt;
		chars_hash_size = TABLE_FINI_HASH_SIZE;
		dots_hash = table->fini_dots_hash;
		dots_hash_cnt = &table->fini_dots_hash_cnt;
		dots_hash_size = TABLE_DOTS_HASH_SIZE;
		break;
#endif

	case TABLE_HASH_NONE:

		log_message(LOG_FATAL, "%s:%d  table_add_rule failed", __FILE__, __LINE__);
		ASSERT(0)
		return NULL;
	}

	switch(direction)
	{
	case BOTH:

		return rule_add_new(
			chars_hash, chars_hash_cnt, chars_hash_size,
			dots_hash, dots_hash_cnt, dots_hash_size,
			filter_forward, filter_backward, chars, chars_len, dots, dots_len, chars_weight, dots_weight);
	case FORWARD:

		return rule_add_new(
			chars_hash, chars_hash_cnt, chars_hash_size,
			NULL, NULL, 0,
			filter_forward, filter_backward, chars, chars_len, dots, dots_len, chars_weight, dots_weight);
	case BACKWARD:

		return rule_add_new(
			NULL, NULL, 0,
			dots_hash, dots_hash_cnt, dots_hash_size,
			filter_forward, filter_backward, chars, chars_len, dots, dots_len, chars_weight, dots_weight);
	}

	ASSERT(0);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rcx, %rbx
movl %edx, %ebp
cmpl $0x7, %esi
ja 0x233f
movq %rdi, %r12
movl %esi, %eax
leaq 0x11081(%rip), %rcx     # 0x13200
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x278(%r12), %r13
testq %r13, %r13
jne 0x21b8
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x278(%r12)
testq %rax, %rax
je 0x263d
movq 0x280(%r12), %rcx
testq %rcx, %rcx
jne 0x21e8
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x280(%r12)
testq %rax, %rax
je 0x2702
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
leaq 0x288(%r12), %rsi
addq $0x28c, %r12            # imm = 0x28C
jmp 0x2555
movq %r15, 0x8(%rsp)
movq 0x2d8(%r12), %r13
movq 0x2e0(%r12), %rcx
testq %r13, %r13
movq %rbx, 0x10(%rsp)
je 0x2491
movq %r14, %r15
testq %rcx, %rcx
jne 0x24e3
jmp 0x24c0
movq 0x2c0(%r12), %r13
testq %r13, %r13
jne 0x226d
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x2c0(%r12)
testq %rax, %rax
je 0x2603
movq 0x2c8(%r12), %rcx
testq %rcx, %rcx
jne 0x229d
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x2c8(%r12)
testq %rax, %rax
je 0x26ce
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
leaq 0x2d0(%r12), %rsi
addq $0x2d4, %r12            # imm = 0x2D4
jmp 0x2555
movq 0x2a8(%r12), %r13
testq %r13, %r13
jne 0x22ee
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x2a8(%r12)
testq %rax, %rax
je 0x2620
movq 0x2b0(%r12), %rcx
testq %rcx, %rcx
jne 0x231e
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x2b0(%r12)
testq %rax, %rax
je 0x26e8
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
leaq 0x2b8(%r12), %rsi
addq $0x2bc, %r12            # imm = 0x2BC
jmp 0x2555
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %esi, %esi
xorl %r12d, %r12d
jmp 0x2555
movq 0x290(%r12), %r13
testq %r13, %r13
jne 0x238b
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x290(%r12)
testq %rax, %rax
je 0x265a
movq 0x298(%r12), %rcx
testq %rcx, %rcx
jne 0x23bb
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x298(%r12)
testq %rax, %rax
je 0x271c
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
leaq 0x2a0(%r12), %rsi
addq $0x2a4, %r12            # imm = 0x2A4
jmp 0x2555
movq %r15, 0x8(%rsp)
movq 0x2f0(%r12), %r13
movq 0x2f8(%r12), %rcx
testq %r13, %r13
movq %rbx, 0x10(%rsp)
je 0x24f4
movq %r14, %r15
testq %rcx, %rcx
jne 0x2546
jmp 0x2523
movq 0x308(%r12), %r13
testq %r13, %r13
jne 0x2440
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x308(%r12)
testq %rax, %rax
je 0x2677
movq 0x310(%r12), %rcx
testq %rcx, %rcx
jne 0x2470
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x310(%r12)
testq %rax, %rax
je 0x2736
movq %r15, 0x8(%rsp)
movq %r14, %r15
movq %rbx, 0x10(%rsp)
leaq 0x318(%r12), %rsi
addq $0x31c, %r12            # imm = 0x31C
jmp 0x2555
testq %rcx, %rcx
jne 0x2766
movq %r14, %r15
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x2d8(%r12)
testq %rax, %rax
je 0x2694
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x2e0(%r12)
testq %rax, %rax
je 0x25c9
leaq 0x2e8(%r12), %rsi
addq $0x2ec, %r12            # imm = 0x2EC
jmp 0x2555
testq %rcx, %rcx
jne 0x2766
movq %r14, %r15
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %r13
movq %rax, 0x2f0(%r12)
testq %rax, %rax
je 0x26b1
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x1150
movq %rax, %rcx
movq %rax, 0x2f8(%r12)
testq %rax, %rax
je 0x25e6
leaq 0x300(%r12), %rsi
addq $0x304, %r12            # imm = 0x304
movl 0x70(%rsp), %r14d
movl 0x68(%rsp), %ebx
movl 0x60(%rsp), %r11d
movq 0x58(%rsp), %r10
movl 0x50(%rsp), %eax
cmpl $-0x1, %ebp
je 0x259a
cmpl $0x1, %ebp
je 0x2588
testl %ebp, %ebp
jne 0x2766
movq %r13, %rdi
movl $0x100, %edx            # imm = 0x100
jmp 0x25a0
movq %r13, %rdi
movl $0x100, %edx            # imm = 0x100
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
jmp 0x25a9
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
movq %r12, %r8
movl $0x100, %r9d            # imm = 0x100
pushq %r14
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
pushq 0x30(%rsp)
pushq %r15
pushq 0x48(%rsp)
callq 0x278f
addq $0x58, %rsp
jmp 0x275b
leaq 0x10c6c(%rip), %rsi     # 0x1323c
leaq 0x10c85(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x33f, %ecx            # imm = 0x33F
jmp 0x274e
leaq 0x10c4f(%rip), %rsi     # 0x1323c
leaq 0x10c68(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x359, %ecx            # imm = 0x359
jmp 0x274e
leaq 0x10c32(%rip), %rsi     # 0x1323c
leaq 0x10c4b(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x31d, %ecx            # imm = 0x31D
jmp 0x274e
leaq 0x10c15(%rip), %rsi     # 0x1323c
leaq 0x10c2e(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x304, %ecx            # imm = 0x304
jmp 0x274e
leaq 0x10bf8(%rip), %rsi     # 0x1323c
leaq 0x10c11(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x2d2, %ecx            # imm = 0x2D2
jmp 0x274e
leaq 0x10bdb(%rip), %rsi     # 0x1323c
leaq 0x10bf4(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x2eb, %ecx            # imm = 0x2EB
jmp 0x274e
leaq 0x10bbe(%rip), %rsi     # 0x1323c
leaq 0x10bd7(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x36a, %ecx            # imm = 0x36A
jmp 0x274e
leaq 0x10ba1(%rip), %rsi     # 0x1323c
leaq 0x10bba(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x337, %ecx            # imm = 0x337
jmp 0x274e
leaq 0x10b84(%rip), %rsi     # 0x1323c
leaq 0x10b9d(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x351, %ecx            # imm = 0x351
jmp 0x274e
leaq 0x10b67(%rip), %rsi     # 0x1323c
leaq 0x10b80(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x325, %ecx            # imm = 0x325
jmp 0x274e
leaq 0x10b4d(%rip), %rsi     # 0x1323c
leaq 0x10b66(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x30c, %ecx            # imm = 0x30C
jmp 0x274e
leaq 0x10b33(%rip), %rsi     # 0x1323c
leaq 0x10b4c(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x2da, %ecx            # imm = 0x2DA
jmp 0x274e
leaq 0x10b19(%rip), %rsi     # 0x1323c
leaq 0x10b32(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x2f3, %ecx            # imm = 0x2F3
jmp 0x274e
leaq 0x10aff(%rip), %rsi     # 0x1323c
leaq 0x10b18(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x372, %ecx            # imm = 0x372
xorl %eax, %eax
callq 0xa278
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1060
leaq 0x10af9(%rip), %rsi     # 0x1326b
leaq 0x10ae3(%rip), %rdx     # 0x1325c
movl $0x7, %edi
movl $0x3c8, %ecx            # imm = 0x3C8
xorl %eax, %eax
callq 0xa278
callq 0x1060