// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/preprocessor/gen.c
// Function: include_file
static bool _include_file(
	PPGeneratorContext *ctx,
	const char *filepath
) {
	assert(ctx);
	assert(filepath);

	ResizableString path;
 
	if (filepath[0] == '/' || filepath[0] == '\\') {
		rstr_init_with_cstr(&path, filepath);
	} else {
		rstr_init_with_cstr(&path, ctx->psrctx->lexctx->file);
		int sep_idx;
		if ((sep_idx = rstr_last_index_of(&path, "/")) != -1
				|| (sep_idx = rstr_last_index_of(&path, "\\")) != -1) {
			ResizableString tmp;
			rstr_init(&tmp);
			rstr_sub_string(&tmp, &path, 0, sep_idx);
			rstr_append_with_cstr(&tmp, OSDEP_PATH_SEPERATOR);
			rstr_append_with_cstr(&tmp, filepath);
			rstr_clear(&path);
			rstr_append_with_rstr(&path, &tmp);
			rstr_free(&tmp);
		} else {
			rstr_clear(&path);
			rstr_append_with_cstr(&path, filepath);
		}
	}

	const char *source = NULL;
	int len = 0;
	source = (const char *) util_get_file_content(RSTR_CSTR(&path), &len);
	if (source == NULL) {
		goto error;
	}

	ResizableString rstr_comment_removed;
	rstr_init(&rstr_comment_removed);
	pp_comment_process(
		&rstr_comment_removed,
		RSTR_CSTR(&path),
		source,
		len
	);

	ResizableString rstr_line_concated;
	rstr_init(&rstr_line_concated);
	pp_line_concat_process(
		&rstr_line_concated,
		RSTR_CSTR(&path),
		RSTR_CSTR(&rstr_comment_removed),
		RSTR_LEN(&rstr_comment_removed)
	);

	rstr_free(&rstr_comment_removed);

	ParserContext *ctx_psr = pp_parser_new_context(
		RSTR_CSTR(&path), RSTR_CSTR(&rstr_line_concated), RSTR_LEN(&rstr_line_concated)
	);
	pp_parser_parse(ctx_psr);

	PPGeneratorContext *pp_gen_ctx = pp_gen_new_context(
		ctx_psr,
		ctx->cstr_include_paths,
		ctx->map_kv,
		ctx->map_kv_with_params,
		ctx->out,
		ctx->result
	);
	pp_gen_generate(pp_gen_ctx);

	// include时使用的map_kv和map_kv_with_params是从包含#include指令的ctx来的。
	// 不能在include时新建的ctx中释放掉。
	pp_gen_ctx->map_kv = NULL;
	pp_gen_ctx->map_kv_with_params = NULL;
	pp_gen_free_context(pp_gen_ctx);

	pp_parser_free_context(ctx_psr);

	free((void *) source);

	rstr_free(&path);
	rstr_free(&rstr_line_concated);
	return true;

error:

	rstr_free(&path);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testq %rsi, %rsi
je 0x2977e
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0x5c, %eax
je 0x29587
cmpl $0x2f, %eax
jne 0x29598
leaq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0xe2a3
jmp 0x29632
movq (%rbx), %rax
movq (%rax), %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0xe2a3
leaq 0xc6ff(%rip), %rsi      # 0x35cb3
movq %r15, %rdi
callq 0xf0d1
cmpl $-0x1, %eax
jne 0x295da
leaq 0xc6ed(%rip), %rsi      # 0x35cb5
leaq -0x38(%rbp), %rdi
callq 0xf0d1
cmpl $-0x1, %eax
je 0x29766
movl %eax, %r12d
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0xe274
movslq %r12d, %rcx
leaq -0x38(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xf19a
leaq 0xc6af(%rip), %rsi      # 0x35cb3
movq %r15, %rdi
callq 0xe2fb
movq %r15, %rdi
movq %r14, %rsi
callq 0xe2fb
movq %r12, %rdi
callq 0xf27f
movq %r12, %rdi
movq %r15, %rsi
callq 0xe5be
movq %r15, %rdi
callq 0xe772
leaq -0x48(%rbp), %rsi
movl $0x0, (%rsi)
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
leaq 0x5148(%rip), %r15      # 0x2e792
cmoveq %r15, %rdi
callq 0x104c5
movq %rax, %r14
testq %rax, %rax
je 0x29743
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0xe274
leaq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
cmoveq %r15, %rsi
movl -0x48(%rbp), %ecx
movq %r13, %rdi
movq %r14, %rdx
callq 0x24324
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0xe274
leaq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
cmoveq %r15, %rsi
movq 0x8(%r13), %rdx
testq %rdx, %rdx
cmoveq %r15, %rdx
movl 0x4(%r13), %ecx
movq %r12, %rdi
callq 0x2b8b0
movq %r13, %rdi
callq 0xe772
leaq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
testq %rdi, %rdi
cmoveq %r15, %rdi
movq 0x8(%r12), %rsi
testq %rsi, %rsi
cmoveq %r15, %rsi
movl 0x4(%r12), %edx
callq 0x2b928
movq %rax, %r13
movq %rax, %rdi
callq 0x2ba02
movq 0x28(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq 0x20(%rbx), %rcx
movq 0x8(%rbx), %r8
movq 0x10(%rbx), %r9
movq %r13, %rdi
callq 0x280af
movq %rax, %rbx
movq %rax, %rdi
callq 0x28004
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movq %rbx, %rdi
callq 0x28300
movq %r13, %rdi
callq 0x2b9bf
movq %r14, %rdi
callq 0xa1a0
leaq -0x38(%rbp), %rdi
callq 0xe772
jmp 0x29747
leaq -0x38(%rbp), %r12
testq %r14, %r14
setne %bl
movq %r12, %rdi
callq 0xe772
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0xf27f
movq %r15, %rdi
movq %r14, %rsi
callq 0xe2fb
jmp 0x29632
leaq 0xc525(%rip), %rdi      # 0x35caa
leaq 0xc1a0(%rip), %rsi      # 0x3592c
leaq 0xc4df(%rip), %rcx      # 0x35c72
movl $0x54, %edx
callq 0xa0b0