// File: /workspace/github_c_makefile_star2_O2/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 0x51da
testl %eax, %eax
je 0x542e
callq 0x6220
movl 0x13f65(%rip), %r13d    # 0x19230
testl %r13d, %r13d
jle 0x547f
movq 0x13f5d(%rip), %r14     # 0x19238
callq 0x51da
testl %eax, %eax
je 0x542e
callq 0x64b0
testl %eax, %eax
jle 0x542e
movq 0x13f3c(%rip), %r12     # 0x19238
movl 0x13f2e(%rip), %ebp     # 0x19230
movq 0x11e87(%rip), %r8      # 0x17190
movq 0x28(%r8), %r9
addq $0x30, %r8
leaq 0x10(%rsp), %rdi
movl $0x2520, %esi           # imm = 0x2520
movq %r12, %rdx
movl %ebp, %ecx
callq 0x7490
testl %eax, %eax
je 0x542e
movl %eax, %r15d
callq 0x51da
testl %eax, %eax
je 0x5359
movq 0x13ef8(%rip), %rax     # 0x19238
cmpw $0x3c, (%rax)
jne 0x5359
cmpl $0x1, 0x13ee3(%rip)     # 0x19230
jne 0x5359
leaq 0x10(%rsp), %rdi
callq 0x7904
leaq 0x2(,%r13,2), %rdi
callq 0x1190
testq %rax, %rax
je 0x54c2
movq %rax, %rbx
movq %r12, 0x8(%rsp)
leaq 0x1(%r13), %rdx
movq %rax, %rdi
movq %r14, %rsi
callq 0x5277
movslq %r15d, %rax
leaq 0x2(,%rax,2), %r14
movq %r14, %rdi
callq 0x1190
testq %rax, %rax
je 0x54e0
movq %rax, %r12
movl %ebp, 0x4(%rsp)
movslq %ebp, %rbp
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x1180
leaq 0x2(,%rbp,2), %rdi
callq 0x1190
testq %rax, %rax
je 0x5508
movq %rax, %r14
incq %rbp
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x5277
callq 0x7424
testq %rax, %rax
je 0x5523
andl $0x0, 0x2c(%rax)
movq %rbx, 0x8(%rax)
movl %r13d, 0x20(%rax)
movq %r12, 0x10(%rax)
movl %r15d, 0x24(%rax)
movq %r14, 0x18(%rax)
movl 0x4(%rsp), %ecx
movl %ecx, 0x28(%rax)
movq 0x11d75(%rip), %rcx     # 0x17190
movq 0x28(%rcx), %rdx
movq %rdx, (%rax)
movq %rax, 0x28(%rcx)
pushq $0x1
popq %rbx
jmp 0x54ae
movslq 0x11d93(%rip), %rax     # 0x171c8
leaq 0x11db4(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x11d89(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
leaq 0xc387(%rip), %rsi      # 0x117d8
xorl %r14d, %r14d
pushq $0x6
popq %rdi
xorl %eax, %eax
callq 0x9174
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x1040
movq %r12, %rdi
callq 0x1040
movq %r14, %rdi
callq 0x1040
xorl %ebx, %ebx
jmp 0x54ae
movslq 0x11d42(%rip), %rax     # 0x171c8
leaq 0x11d63(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x11d38(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
leaq 0xc31a(%rip), %rsi      # 0x117bc
xorl %ebx, %ebx
pushq $0x6
popq %rdi
xorl %eax, %eax
callq 0x9174
movl %ebx, %eax
addq $0x4a58, %rsp           # imm = 0x4A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbd73(%rip), %rsi      # 0x1123c
leaq 0xbe11(%rip), %rdx      # 0x112e1
xorl %r14d, %r14d
pushq $0x7
popq %rdi
movl $0x371, %ecx            # imm = 0x371
jmp 0x5457
leaq 0xbd55(%rip), %rsi      # 0x1123c
leaq 0xbdf3(%rip), %rdx      # 0x112e1
xorl %r14d, %r14d
pushq $0x7
popq %rdi
movl $0x379, %ecx            # imm = 0x379
xorl %eax, %eax
callq 0x9174
xorl %r12d, %r12d
jmp 0x5463
leaq 0xbd2d(%rip), %rsi      # 0x1123c
leaq 0xbdcb(%rip), %rdx      # 0x112e1
xorl %r14d, %r14d
pushq $0x7
popq %rdi
movl $0x381, %ecx            # imm = 0x381
jmp 0x5539
leaq 0xbd12(%rip), %rsi      # 0x1123c
leaq 0xbdb0(%rip), %rdx      # 0x112e1
pushq $0x7
popq %rdi
movl $0x389, %ecx            # imm = 0x389
xorl %eax, %eax
callq 0x9174
jmp 0x5463