// File: /workspace/github_c_makefile_star2_O2/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 0x2825b
movq %rsi, %r14
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0x5c, %eax
je 0x28067
cmpl $0x2f, %eax
jne 0x28078
leaq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0xde49
jmp 0x28112
movq (%rbx), %rax
movq (%rax), %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0xde49
leaq 0xccaf(%rip), %rsi      # 0x34d43
movq %r15, %rdi
callq 0xebd4
cmpl $-0x1, %eax
jne 0x280ba
leaq 0xcc9d(%rip), %rsi      # 0x34d45
leaq -0x38(%rbp), %rdi
callq 0xebd4
cmpl $-0x1, %eax
je 0x28243
movl %eax, %r12d
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0xde1c
movslq %r12d, %rcx
leaq -0x38(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xec93
leaq 0xcc5f(%rip), %rsi      # 0x34d43
movq %r15, %rdi
callq 0xde99
movq %r15, %rdi
movq %r14, %rsi
callq 0xde99
movq %r12, %rdi
callq 0xed67
movq %r12, %rdi
movq %r15, %rsi
callq 0xe12e
movq %r15, %rdi
callq 0xe2b9
leaq -0x48(%rbp), %rsi
andl $0x0, (%rsi)
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
leaq 0x566b(%rip), %r15      # 0x2d792
cmoveq %r15, %rdi
callq 0xfe3a
movq %rax, %r14
testq %rax, %rax
je 0x28220
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0xde1c
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 0x231b0
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0xde1c
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 0x2a251
movq %r13, %rdi
callq 0xe2b9
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 0x2a2bc
movq %rax, %r13
movq %rax, %rdi
callq 0x2a393
movq 0x28(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq 0x20(%rbx), %rcx
movq 0x8(%rbx), %r8
movq 0x10(%rbx), %r9
movq %r13, %rdi
callq 0x26c4b
movq %rax, %rbx
movq %rax, %rdi
callq 0x26ba0
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movq %rbx, %rdi
callq 0x26e92
movq %r13, %rdi
callq 0x2a350
movq %r14, %rdi
callq 0xa190
leaq -0x38(%rbp), %rdi
callq 0xe2b9
jmp 0x28224
leaq -0x38(%rbp), %r12
testq %r14, %r14
setne %bl
movq %r12, %rdi
callq 0xe2b9
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0xed67
movq %r15, %rdi
movq %r14, %rsi
callq 0xde99
jmp 0x28112
leaq 0xcad8(%rip), %rdi      # 0x34d3a
leaq 0xc753(%rip), %rsi      # 0x349bc
leaq 0xca92(%rip), %rcx      # 0x34d02
pushq $0x54
popq %rdx
callq 0xa0b0