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

	match_t match[2] = {0};
	while (regexec_2_0_beta(&all_regex->c_include_regex, operating_line->data, 2, match) == 0) {
		const match_t inner_match = match[1];
		assert(inner_match.rm_so != -1 && inner_match.rm_eo != -1);

		/* Copy the string here so we only get the match, not everything after it. */
		char just_match_str[inner_match.len + 1];
		just_match_str[inner_match.len] = '\0';
		strncpy(just_match_str, inner_match.start, inner_match.len);


		/* Open the file here. */
		/* TODO: Make this actually the whole size of the file, not just a random buffer. */
		char template_file[2048] = {0};
		size_t template_file_siz = 0;
		FILE *include_file = fopen(just_match_str, "r");
		if (!include_file) {
			/* If we couldn't open the file, blow up with an assertion. */
			printf("Could not open SCREAM file for reading.\n");
			printf("Line: %s\n", operating_line->data);
			assert(1 == 0);
		}

		template_file_siz = fread(template_file, 1, sizeof(template_file), include_file);
		fclose(include_file);
		template_file[template_file_siz] = '\0';

		line rendered_piece = {0};
		rendered_piece.data = gshkl_render(ctext, template_file, template_file_siz, &rendered_piece.size);

		free(interpolated_line.data);
		interpolated_line.size = rendered_piece.size;
		interpolated_line.data = rendered_piece.data;
		operating_line = &interpolated_line;

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

	return *operating_line;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x868, %rsp            # imm = 0x868
andq $0x0, -0x30(%rbp)
movq %rsi, %r15
movq %rdi, -0x58(%rbp)
movq 0x8(%rsi), %rsi
testq %rsi, %rsi
je 0x3dc2
movq %rdx, %rbx
leaq 0x8(%r15), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rax
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
addq $0x140, %rbx            # imm = 0x140
leaq -0x30(%rbp), %rax
movq (%rax), %r12
xorl %r14d, %r14d
movq $0x0, -0x40(%rbp)
movq %rbx, %rdi
pushq $0x2
popq %rdx
leaq -0x90(%rbp), %rcx
callq 0x354a
testl %eax, %eax
jne 0x3d3a
cmpl $-0x1, -0x78(%rbp)
je 0x3d5b
cmpl $-0x1, -0x74(%rbp)
je 0x3d5b
movq %rsp, %r13
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rsi
movq %rsp, %r15
leaq 0x10(%rdx), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movb $0x0, (%rdx,%r15)
movq %r15, %rdi
callq 0x1050
movl $0x800, %edx            # imm = 0x800
leaq -0x890(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x1120
movq %r15, %rdi
leaq 0x13de(%rip), %rsi      # 0x5081
callq 0x11f0
testq %rax, %rax
je 0x3d7e
movq %rax, %r15
movl $0x800, %edx            # imm = 0x800
movq %r14, %rdi
pushq $0x1
popq %rsi
movq %rax, %rcx
callq 0x1080
movq %r14, %r12
movq %rax, %r14
movq %r15, %rdi
callq 0x10a0
movb $0x0, -0x890(%rbp,%r14)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
leaq -0x50(%rbp), %rcx
callq 0x2398
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %r12
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x70(%rbp)
movq %r13, %rsp
movq %r12, %rsi
movq %r12, -0x40(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x60(%rbp), %r15
jmp 0x3c2c
movq %r12, -0x30(%rbp)
movq %r14, -0x60(%rbp)
movq (%r15), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rdx
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, -0x30(%rbp)
leaq 0x2cd8(%rip), %rdi      # 0x6a3e
leaq 0x24d1(%rip), %rsi      # 0x623e
leaq 0x2dd6(%rip), %rcx      # 0x6b4a
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x1110
movq %r12, -0x30(%rbp)
leaq 0x2f6a(%rip), %rdi      # 0x6cf3
callq 0x1070
movq -0x38(%rbp), %rax
movq (%rax), %rsi
leaq 0x294d(%rip), %rdi      # 0x66e9
xorl %eax, %eax
callq 0x10e0
leaq 0x299c(%rip), %rdi      # 0x6746
leaq 0x248d(%rip), %rsi      # 0x623e
leaq 0x2d92(%rip), %rcx      # 0x6b4a
movl $0x209, %edx            # imm = 0x209
callq 0x1110
leaq 0x2bfc(%rip), %rdi      # 0x69c5
leaq 0x246e(%rip), %rsi      # 0x623e
leaq 0x2d73(%rip), %rcx      # 0x6b4a
movl $0x1f3, %edx            # imm = 0x1F3
callq 0x1110