// File: /workspace/github_c_makefile_star2_O2/qpfiffer[P]38-Moths/src/greshunkel.c
// Function: filter_line
static line
_filter_line(const greshunkel_ctext *ctext, const line *current_line, const struct compiled_regex *all_regex) {
	line interpolated_line = {0};
	line new_line_to_add = {0};
	const line *operating_line = current_line;
	assert(operating_line->data != NULL);

	/* Now we match template filters: */
	match_t filter_matches[3];
	while (regexec_2_0_beta(&all_regex->c_filter_regex, operating_line->data, 3, filter_matches) == 0) {
		match_t whole_match = filter_matches[0];
		const char *start_of_first_XxX = strstr(whole_match.start, " XxX");
		const char *end_of_first_XxX = start_of_first_XxX + strlen(" XxX");
		const size_t full_diff = end_of_first_XxX - whole_match.start;

		whole_match.rm_eo = (whole_match.start + full_diff) - operating_line->data;
		whole_match.len = full_diff;
		assert(start_of_first_XxX != NULL);

		const match_t function_name = filter_matches[1];
		const match_t argument = filter_matches[2];

		const greshunkel_filter *filter;
		char just_match_str[function_name.len + 1];
		just_match_str[function_name.len] = '\0';
		strncpy(just_match_str, function_name.start, function_name.len);

		if ((filter = find_needle(ctext, just_match_str, 0))) {

			const size_t new_len = start_of_first_XxX - argument.start;

			/* Render the argument out so we can pass it to the filter function. */
			char *rendered_argument = strndup(argument.start, new_len);

			/* Pass it to the filter function. */
			char *filter_result = filter->filter_func(rendered_argument);

			vishnu(&new_line_to_add, whole_match, filter_result, operating_line);

			if (filter->clean_up != NULL)
				filter->clean_up(filter_result);

			free(rendered_argument);
		}
		assert(filter != NULL);

		free(interpolated_line.data);
		interpolated_line.size = new_line_to_add.size;
		interpolated_line.data = new_line_to_add.data;
		new_line_to_add.size = 0;
		new_line_to_add.data = NULL;
		operating_line = &interpolated_line;

		/* Set the next regex check after this one. */
		memset(filter_matches, 0, sizeof(filter_matches));
	}

	/* No arguments matching. */
	match_t filter_matches_no_args[2];
	while (regexec_2_0_beta(&all_regex->c_filter_no_args_regex, operating_line->data, 2, filter_matches_no_args) == 0) {
		match_t whole_match = filter_matches_no_args[0];
		const char *start_of_first_XxX = strstr(whole_match.start, " XxX");
		const char *end_of_first_XxX = start_of_first_XxX + strlen(" XxX");
		const size_t full_diff = end_of_first_XxX - whole_match.start;

		whole_match.rm_eo = (whole_match.start + full_diff) - operating_line->data;
		whole_match.len = full_diff;
		assert(start_of_first_XxX != NULL);

		const match_t function_name = filter_matches_no_args[1];

		const greshunkel_filter *filter;
		char just_match_str[function_name.len + 1];
		just_match_str[function_name.len] = '\0';
		strncpy(just_match_str, function_name.start, function_name.len);

		if ((filter = find_needle(ctext, just_match_str, 0))) {
			char *filter_result = filter->filter_func(NULL);

			vishnu(&new_line_to_add, whole_match, filter_result, operating_line);

			if (filter->clean_up != NULL)
				filter->clean_up(filter_result);
		}
		assert(filter != NULL);

		free(interpolated_line.data);
		interpolated_line.size = new_line_to_add.size;
		interpolated_line.data = new_line_to_add.data;
		new_line_to_add.size = 0;
		new_line_to_add.data = NULL;
		operating_line = &interpolated_line;

		memset(filter_matches_no_args, 0, sizeof(filter_matches_no_args));
	}

	return *operating_line;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, -0x60(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x40(%rbp)
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x417c
leaq 0x8(%r14), %r13
movq %rdx, -0x58(%rbp)
leaq 0xc0(%rdx), %rax
movq %rax, -0xb8(%rbp)
xorl %r12d, %r12d
movq -0xb8(%rbp), %rdi
pushq $0x3
popq %rdx
leaq -0x110(%rbp), %rcx
callq 0x354a
testl %eax, %eax
jne 0x3faa
movq %r14, %r15
movq %r12, -0xc0(%rbp)
movaps -0x110(%rbp), %xmm0
movaps %xmm0, -0x90(%rbp)
movq -0x100(%rbp), %r14
movq %r14, -0x80(%rbp)
movq %r14, %rdi
leaq 0x2d85(%rip), %rsi      # 0x6bfd
callq 0x1200
movq %rax, %rbx
addq $0x4, %rax
movq %rax, %rcx
subl (%r13), %eax
subq %r14, %rcx
movl %eax, -0x8c(%rbp)
movq %rcx, -0x88(%rbp)
testq %rbx, %rbx
je 0x4100
movq %rsp, %r12
movq -0xf0(%rbp), %rdx
movq -0xe8(%rbp), %rsi
movq -0xd0(%rbp), %r13
movq %rsp, %r14
leaq 0x10(%rdx), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movb $0x0, (%rdx,%r14)
movq %r14, %rdi
callq 0x1050
movq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x35f0
testq %rax, %rax
je 0x411f
movq %rax, %r14
subq %r13, %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1150
movq %rax, %rbx
movq %rax, %rdi
callq *0x20(%r14)
movq %rax, %r13
subq $0x20, %rsp
movq -0x80(%rbp), %rax
movq %rax, 0x10(%rsp)
movaps -0x90(%rbp), %xmm0
movups %xmm0, (%rsp)
leaq -0x40(%rbp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3b20
addq $0x20, %rsp
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x3f48
movq %r13, %rdi
callq *%rax
movq %rbx, %rdi
callq 0x1030
movq -0xc0(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rsi
movq %rax, -0x50(%rbp)
movq %rsi, -0x48(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x110(%rbp)
movaps %xmm0, -0x100(%rbp)
movaps %xmm0, -0xf0(%rbp)
movaps %xmm0, -0xe0(%rbp)
andq $0x0, -0xd0(%rbp)
movq %r12, %rsp
movq %rsi, %r12
leaq -0x48(%rbp), %r13
leaq -0x50(%rbp), %r14
jmp 0x3e2d
movq -0x58(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq 0x8(%r14), %rsi
movq %rdi, -0x58(%rbp)
pushq $0x2
popq %rdx
leaq -0x90(%rbp), %rcx
callq 0x354a
testl %eax, %eax
jne 0x40ea
movaps -0x90(%rbp), %xmm0
movaps %xmm0, -0xb0(%rbp)
movq -0x80(%rbp), %rbx
movq %rbx, -0xa0(%rbp)
movq %rbx, %rdi
leaq 0x2c06(%rip), %rsi      # 0x6bfd
callq 0x1200
leaq 0x4(%rax), %rcx
movq %rcx, %rdx
subl 0x8(%r14), %ecx
subq %rbx, %rdx
movl %ecx, -0xac(%rbp)
movq %rdx, -0xa8(%rbp)
testq %rax, %rax
je 0x413e
movq %r14, %r13
movq %rsp, %r15
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rsi
movq %rsp, %rbx
leaq 0x10(%rdx), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movb $0x0, (%rdx,%rbx)
movq %rbx, %rdi
callq 0x1050
movq -0x60(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x35f0
testq %rax, %rax
je 0x415d
movq %rax, %rbx
xorl %edi, %edi
callq *0x20(%rax)
movq %rax, %r14
subq $0x20, %rsp
movq -0xa0(%rbp), %rax
movq %rax, 0x10(%rsp)
movaps -0xb0(%rbp), %xmm0
movups %xmm0, (%rsp)
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3b20
addq $0x20, %rsp
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x40a9
movq %r14, %rdi
callq *%rax
movq %r12, %rdi
callq 0x1030
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rsi
movq %rax, -0x50(%rbp)
movq %rsi, -0x48(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
movq %r15, %rsp
movq %rsi, %r12
leaq -0x50(%rbp), %r14
movq -0x58(%rbp), %rdi
jmp 0x3fbd
movq (%r14), %rax
movq 0x8(%r14), %rdx
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2afb(%rip), %rdi      # 0x6c02
leaq 0x2130(%rip), %rsi      # 0x623e
leaq 0x2a8f(%rip), %rcx      # 0x6ba4
movl $0x154, %edx            # imm = 0x154
callq 0x1110
leaq 0x2af7(%rip), %rdi      # 0x6c1d
leaq 0x2111(%rip), %rsi      # 0x623e
leaq 0x2a70(%rip), %rcx      # 0x6ba4
movl $0x16f, %edx            # imm = 0x16F
callq 0x1110
leaq 0x2abd(%rip), %rdi      # 0x6c02
leaq 0x20f2(%rip), %rsi      # 0x623e
leaq 0x2a51(%rip), %rcx      # 0x6ba4
movl $0x186, %edx            # imm = 0x186
callq 0x1110
leaq 0x2ab9(%rip), %rdi      # 0x6c1d
leaq 0x20d3(%rip), %rsi      # 0x623e
leaq 0x2a32(%rip), %rcx      # 0x6ba4
movl $0x197, %edx            # imm = 0x197
callq 0x1110
leaq 0x2842(%rip), %rdi      # 0x69c5
leaq 0x20b4(%rip), %rsi      # 0x623e
leaq 0x2a13(%rip), %rcx      # 0x6ba4
movl $0x148, %edx            # imm = 0x148
callq 0x1110
nop