// File: /workspace/github_c_makefile_star2_O3/MikeGray-APH[P]LibLouisAPH/source/compile.c
// Function: compile_pattern
static int compile_pattern(void)
{
	struct subpattern *subpattern;
	unichar pattern[PATTERN_MAX], *token_tag, *token_src, *tag, *expr_data, *src_data;
	int tag_len, expr_len, src_len;

	tag =
	expr_data =
	src_data = NULL;

	if(!token_parse())
		goto return_fail;

	token_convert_escapes();
	if(token_len <= 0)
	{
		log_message(LOG_ERROR, "%s:%d  invalid pattern name", table_file_names[include_depth], table_file_lines[include_depth]);
		return 0;
	}
	token_tag = token_crs;
	tag_len = token_len;

	if(!token_parse())
		goto return_fail;
	if(token_convert_escapes_with_dots() <= 0)
		goto return_fail;

	token_src = token_crs;
	src_len = token_len;
	expr_len = pattern_compile(pattern, PATTERN_MAX, token_crs, token_len, table->attrs_chars, table->subpatterns);
	if(!expr_len)
		goto return_fail;

	if(token_parse())
	if(token_crs[0] == u'<' && token_len == 1)
		pattern_reverse(pattern);

	tag = MALLOC((tag_len + 1) * sizeof(unichar));
	if(!tag)
	{
		LOG_ALLOCATE_FAIL
		goto return_fail_free;
	}
	utf16_copy(tag, token_tag, tag_len + 1);

	expr_data = MALLOC((expr_len + 1) * sizeof(unichar));
	if(!expr_data)
	{
		LOG_ALLOCATE_FAIL
		goto return_fail_free;
	}
	memcpy(expr_data, pattern, (expr_len + 1) * sizeof(unichar));

	src_data = MALLOC((src_len + 1) * sizeof(unichar));
	if(!src_data)
	{
		LOG_ALLOCATE_FAIL
		goto return_fail_free;
	}
	utf16_copy(src_data, token_src, src_len + 1);

	subpattern = subpattern_allocate();
	if(!subpattern)
	{
		LOG_ALLOCATE_FAIL
		goto return_fail_free;
	}
	subpattern->nxt = NULL;
	subpattern->processing = 0;
	subpattern->tag = tag;
	subpattern->tag_len = tag_len;
	subpattern->expr_data = expr_data;
	subpattern->expr_len = expr_len;
	subpattern->src_data = src_data;
	subpattern->src_len = src_len;

	subpattern->nxt = table->subpatterns;
	table->subpatterns = subpattern;

	return 1;

	return_fail:
	log_message(LOG_ERROR, "%s:%d  invalid pattern", table_file_names[include_depth], table_file_lines[include_depth]);

	return_fail_free:
	if(tag)
		FREE(tag);
	if(expr_data)
		FREE(expr_data);
	if(src_data)
		FREE(src_data);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a58, %rsp           # imm = 0x4A58
callq 0x53ae
testl %eax, %eax
je 0x565e
movq 0x12ce6(%rip), %rdi     # 0x18180
movq 0x14d87(%rip), %rsi     # 0x1a228
movl 0x14d79(%rip), %edx     # 0x1a220
callq 0x2022
movl %eax, 0x14d6e(%rip)     # 0x1a220
movq 0x14d6f(%rip), %rdi     # 0x1a228
movl %eax, %esi
callq 0x134f
movl %eax, 0x14d5a(%rip)     # 0x1a220
testl %eax, %eax
jle 0x5683
movl %eax, %ebx
movq 0x14d51(%rip), %r13     # 0x1a228
callq 0x53ae
testl %eax, %eax
je 0x565e
callq 0x6cea
testl %eax, %eax
jle 0x565e
movq 0x14d30(%rip), %r15     # 0x1a228
movl 0x14d22(%rip), %ebp     # 0x1a220
movq 0x12c7b(%rip), %r8      # 0x18180
movq 0x28(%r8), %r9
addq $0x30, %r8
leaq 0x10(%rsp), %rdi
movl $0x2520, %esi           # imm = 0x2520
movq %r15, %rdx
movl %ebp, %ecx
callq 0x8061
testl %eax, %eax
je 0x565e
movl %eax, %r12d
callq 0x53ae
testl %eax, %eax
je 0x5555
movq 0x14cec(%rip), %rax     # 0x1a228
cmpw $0x3c, (%rax)
jne 0x5555
cmpl $0x1, 0x14cd7(%rip)     # 0x1a220
jne 0x5555
leaq 0x10(%rsp), %rdi
callq 0x84e0
leal 0x2(,%rbx,2), %edi
callq 0x1190
testq %rax, %rax
je 0x56c8
movq %rax, %r14
movslq %ebp, %rax
movq %rax, 0x8(%rsp)
movl %ebx, %eax
incl %eax
movl %eax, %eax
xorl %ecx, %ecx
movzwl (%r13,%rcx,2), %edx
movw %dx, (%r14,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x557d
movw $0x0, -0x2(%r14,%rax,2)
movslq %r12d, %rax
leaq 0x2(,%rax,2), %r13
movq %r13, %rdi
callq 0x1190
testq %rax, %rax
je 0x56e4
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %r13, %rdx
movq %rax, (%rsp)
callq 0x1180
movq 0x8(%rsp), %rax
leaq 0x2(,%rax,2), %rdi
callq 0x1190
testq %rax, %rax
je 0x570a
movq %rax, %r13
testl %ebp, %ebp
js 0x5609
movq 0x8(%rsp), %rax
incq %rax
movl %eax, %eax
xorl %ecx, %ecx
movzwl (%r15,%rcx,2), %edx
movw %dx, (%r13,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x55f6
movq 0x8(%rsp), %rax
movw $0x0, (%r13,%rax,2)
callq 0x7fe0
testq %rax, %rax
je 0x5739
movl $0x0, 0x2c(%rax)
movq %r14, 0x8(%rax)
movl %ebx, 0x20(%rax)
movq (%rsp), %rcx
movq %rcx, 0x10(%rax)
movl %r12d, 0x24(%rax)
movq %r13, 0x18(%rax)
movl %ebp, 0x28(%rax)
movq 0x12b34(%rip), %rcx     # 0x18180
movq 0x28(%rcx), %rdx
movq %rdx, (%rax)
movq %rax, 0x28(%rcx)
movl $0x1, %ebx
jmp 0x56b4
movslq 0x12b53(%rip), %rax     # 0x181b8
leaq 0x12b74(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x12b49(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0xe1b7(%rip), %rsi      # 0x13838
jmp 0x56a6
movslq 0x12b2e(%rip), %rax     # 0x181b8
leaq 0x12b4f(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x12b24(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0xe176(%rip), %rsi      # 0x1381c
xorl %ebx, %ebx
movl $0x6, %edi
xorl %eax, %eax
callq 0xa278
movl %ebx, %eax
addq $0x4a58, %rsp           # imm = 0x4A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdb6d(%rip), %rsi      # 0x1323c
leaq 0xdc6b(%rip), %rdx      # 0x13341
xorl %ebx, %ebx
movl $0x7, %edi
movl $0x371, %ecx            # imm = 0x371
jmp 0x56ad
leaq 0xdb51(%rip), %rsi      # 0x1323c
leaq 0xdc4f(%rip), %rdx      # 0x13341
xorl %ebx, %ebx
movl $0x7, %edi
movl $0x379, %ecx            # imm = 0x379
xorl %eax, %eax
callq 0xa278
movq %r14, %rdi
jmp 0x5773
leaq 0xdb2b(%rip), %rsi      # 0x1323c
leaq 0xdc29(%rip), %rdx      # 0x13341
xorl %ebx, %ebx
movl $0x7, %edi
movl $0x381, %ecx            # imm = 0x381
xorl %eax, %eax
callq 0xa278
movq %r14, %rdi
callq 0x1040
movq (%rsp), %rdi
jmp 0x5773
leaq 0xdafc(%rip), %rsi      # 0x1323c
leaq 0xdbfa(%rip), %rdx      # 0x13341
xorl %ebx, %ebx
movl $0x7, %edi
movl $0x389, %ecx            # imm = 0x389
xorl %eax, %eax
callq 0xa278
movq %r14, %rdi
callq 0x1040
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x5770
callq 0x1040
movq %r13, %rdi
callq 0x1040
jmp 0x56b4