// File: /workspace/github_c_makefile_star2_O1/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 0x2a168
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0x5c, %eax
je 0x29f71
cmpl $0x2f, %eax
jne 0x29f82
leaq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0xe497
jmp 0x2a01c
movq (%rbx), %rax
movq (%rax), %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0xe497
leaq 0xcd6d(%rip), %rsi      # 0x36d0b
movq %r15, %rdi
callq 0xf2ba
cmpl $-0x1, %eax
jne 0x29fc4
leaq 0xcd5b(%rip), %rsi      # 0x36d0d
leaq -0x38(%rbp), %rdi
callq 0xf2ba
cmpl $-0x1, %eax
je 0x2a150
movl %eax, %r12d
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0xe468
movslq %r12d, %rcx
leaq -0x38(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xf383
leaq 0xcd1d(%rip), %rsi      # 0x36d0b
movq %r15, %rdi
callq 0xe4ef
movq %r15, %rdi
movq %r14, %rsi
callq 0xe4ef
movq %r12, %rdi
callq 0xf468
movq %r12, %rdi
movq %r15, %rsi
callq 0xe7ac
movq %r15, %rdi
callq 0xe958
leaq -0x48(%rbp), %rsi
movl $0x0, (%rsi)
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
leaq 0x5782(%rip), %r15      # 0x2f7b6
cmoveq %r15, %rdi
callq 0x106d5
movq %rax, %r14
testq %rax, %rax
je 0x2a12d
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0xe468
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 0x24b28
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0xe468
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 0x2c277
movq %r13, %rdi
callq 0xe958
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 0x2c2f0
movq %rax, %r13
movq %rax, %rdi
callq 0x2c3ca
movq 0x28(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq 0x20(%rbx), %rcx
movq 0x8(%rbx), %r8
movq 0x10(%rbx), %r9
movq %r13, %rdi
callq 0x289e7
movq %rax, %rbx
movq %rax, %rdi
callq 0x2893c
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movq %rbx, %rdi
callq 0x28c38
movq %r13, %rdi
callq 0x2c387
movq %r14, %rdi
callq 0xa190
leaq -0x38(%rbp), %rdi
callq 0xe958
jmp 0x2a131
leaq -0x38(%rbp), %r12
testq %r14, %r14
setne %bl
movq %r12, %rdi
callq 0xe958
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0xf468
movq %r15, %rdi
movq %r14, %rsi
callq 0xe4ef
jmp 0x2a01c
leaq 0xcb93(%rip), %rdi      # 0x36d02
leaq 0xc80e(%rip), %rsi      # 0x36984
leaq 0xcb4d(%rip), %rcx      # 0x36cca
movl $0x54, %edx
callq 0xa0b0