// File: /workspace/github_c_makefile_star2_O1/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 0x5525
testl %eax, %eax
je 0x57e6
movq 0x12b6c(%rip), %rdi     # 0x18180
movq 0x14c0d(%rip), %rsi     # 0x1a228
movl 0x14bff(%rip), %edx     # 0x1a220
callq 0x1fef
movl %eax, 0x14bf4(%rip)     # 0x1a220
movq 0x14bf5(%rip), %rdi     # 0x1a228
movl %eax, %esi
callq 0x133d
movl %eax, 0x14be0(%rip)     # 0x1a220
testl %eax, %eax
jle 0x5848
movl %eax, %ebx
movq 0x14bd7(%rip), %r15     # 0x1a228
callq 0x5525
testl %eax, %eax
je 0x57e6
callq 0x6edd
testl %eax, %eax
jle 0x57e6
movq 0x14bb6(%rip), %r13     # 0x1a228
movl 0x14ba8(%rip), %ebp     # 0x1a220
movq 0x12b01(%rip), %r8      # 0x18180
movq 0x28(%r8), %r9
addq $0x30, %r8
leaq 0x10(%rsp), %rdi
movl $0x2520, %esi           # imm = 0x2520
movq %r13, %rdx
movl %ebp, %ecx
callq 0x8144
testl %eax, %eax
je 0x57e6
movl %eax, %r12d
callq 0x5525
testl %eax, %eax
je 0x56cf
movq 0x14b72(%rip), %rax     # 0x1a228
cmpw $0x3c, (%rax)
jne 0x56cf
cmpl $0x1, 0x14b5d(%rip)     # 0x1a220
jne 0x56cf
leaq 0x10(%rsp), %rdi
callq 0x85c5
leal 0x2(,%rbx,2), %edi
callq 0x1180
testq %rax, %rax
je 0x588d
movq %rax, %r14
movl %ebp, 0x4(%rsp)
movslq %ebp, %rax
movq %rax, 0x8(%rsp)
movl %ebx, %eax
incl %eax
movl %eax, %eax
xorl %ecx, %ecx
movzwl (%r15,%rcx,2), %edx
movw %dx, (%r14,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x56fb
movw $0x0, -0x2(%r14,%rax,2)
movslq %r12d, %rax
leaq 0x2(,%rax,2), %r15
movq %r15, %rdi
callq 0x1180
testq %rax, %rax
je 0x58ad
movq %rax, %rbp
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x1170
movq 0x8(%rsp), %rax
leaq 0x2(,%rax,2), %rdi
callq 0x1180
testq %rax, %rax
je 0x58d6
movq %rax, %r15
cmpl $0x0, 0x4(%rsp)
js 0x5788
movq 0x8(%rsp), %rax
incq %rax
movl %eax, %eax
xorl %ecx, %ecx
movzwl (%r13,%rcx,2), %edx
movw %dx, (%r15,%rcx,2)
incq %rcx
cmpq %rcx, %rax
jne 0x5775
movq 0x8(%rsp), %rax
movw $0x0, (%r15,%rax,2)
callq 0x80bc
testq %rax, %rax
je 0x58f3
movq $0x0, (%rax)
movl $0x0, 0x2c(%rax)
movq %r14, 0x8(%rax)
movl %ebx, 0x20(%rax)
movq %rbp, 0x10(%rax)
movl %r12d, 0x24(%rax)
movq %r15, 0x18(%rax)
movl 0x4(%rsp), %ecx
movl %ecx, 0x28(%rax)
movq 0x129af(%rip), %rcx     # 0x18180
movq 0x28(%rcx), %rdx
movq %rdx, (%rax)
movq %rax, 0x28(%rcx)
movl $0x1, %ebx
jmp 0x5879
movslq 0x129cb(%rip), %rax     # 0x181b8
leaq 0x129ec(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x129c1(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0xdf93(%rip), %rsi      # 0x1379c
xorl %r15d, %r15d
movl $0x6, %edi
xorl %eax, %eax
callq 0xa36c
xorl %ebp, %ebp
xorl %r14d, %r14d
testq %r14, %r14
je 0x582a
movq %r14, %rdi
callq 0x1040
testq %rbp, %rbp
je 0x5837
movq %rbp, %rdi
callq 0x1040
xorl %ebx, %ebx
testq %r15, %r15
je 0x5879
movq %r15, %rdi
callq 0x1040
jmp 0x5879
movslq 0x12969(%rip), %rax     # 0x181b8
leaq 0x1298a(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x1295f(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0xdf15(%rip), %rsi      # 0x13780
xorl %ebx, %ebx
movl $0x6, %edi
xorl %eax, %eax
callq 0xa36c
movl %ebx, %eax
addq $0x4a58, %rsp           # imm = 0x4A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd960(%rip), %rsi      # 0x131f4
leaq 0xda06(%rip), %rdx      # 0x132a1
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x371, %ecx            # imm = 0x371
jmp 0x5811
leaq 0xd940(%rip), %rsi      # 0x131f4
leaq 0xd9e6(%rip), %rdx      # 0x132a1
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x379, %ecx            # imm = 0x379
xorl %eax, %eax
callq 0xa36c
xorl %ebp, %ebp
jmp 0x581d
leaq 0xd917(%rip), %rsi      # 0x131f4
leaq 0xd9bd(%rip), %rdx      # 0x132a1
xorl %r15d, %r15d
movl $0x7, %edi
movl $0x381, %ecx            # imm = 0x381
jmp 0x590b
leaq 0xd8fa(%rip), %rsi      # 0x131f4
leaq 0xd9a0(%rip), %rdx      # 0x132a1
movl $0x7, %edi
movl $0x389, %ecx            # imm = 0x389
xorl %eax, %eax
callq 0xa36c
jmp 0x581d