// File: /workspace/github_c_makefile_star2_O0/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
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3f81c
jmp 0x3f83b
leaq 0xe33e(%rip), %rdi      # 0x4db61
leaq 0xf6cb(%rip), %rsi      # 0x4eef5
movl $0x53, %edx
leaq 0xfb17(%rip), %rcx      # 0x4f34d
callq 0xa0b0
cmpq $0x0, -0x18(%rbp)
je 0x3f844
jmp 0x3f863
leaq 0xfb3a(%rip), %rdi      # 0x4f385
leaq 0xf6a3(%rip), %rsi      # 0x4eef5
movl $0x54, %edx
leaq 0xfaef(%rip), %rcx      # 0x4f34d
callq 0xa0b0
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x3f87b
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
jne 0x3f88d
movq -0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xfd00
jmp 0x3f947
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq (%rax), %rsi
leaq -0x28(%rbp), %rdi
callq 0xfd00
leaq -0x28(%rbp), %rdi
leaq 0xd87a(%rip), %rsi      # 0x4d128
callq 0x11130
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
jne 0x3f8d3
leaq -0x28(%rbp), %rdi
leaq 0xfac8(%rip), %rsi      # 0x4f38e
callq 0x11130
movl %eax, -0x2c(%rbp)
cmpl $-0x1, %eax
je 0x3f92f
leaq -0x40(%rbp), %rdi
callq 0xfca0
movslq -0x2c(%rbp), %rcx
leaq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x11230
leaq -0x40(%rbp), %rdi
leaq 0xd82c(%rip), %rsi      # 0x4d128
callq 0xfd80
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0xfd80
leaq -0x28(%rbp), %rdi
callq 0x113c0
leaq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x10110
leaq -0x40(%rbp), %rdi
callq 0x10320
jmp 0x3f945
leaq -0x28(%rbp), %rdi
callq 0x113c0
movq -0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xfd80
jmp 0x3f947
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f96d
leaq 0x7f23(%rip), %rax      # 0x47887
movq %rax, -0x88(%rbp)
jmp 0x3f978
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x129c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x3f998
jmp 0x3fb56
leaq -0x60(%rbp), %rdi
callq 0xfca0
cmpq $0x0, -0x20(%rbp)
jne 0x3f9b8
leaq 0x7ed8(%rip), %rax      # 0x47887
movq %rax, -0x90(%rbp)
jmp 0x3f9c3
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl -0x4c(%rbp), %ecx
leaq -0x60(%rbp), %rdi
callq 0x35ab0
leaq -0x70(%rbp), %rdi
callq 0xfca0
cmpq $0x0, -0x20(%rbp)
jne 0x3f9fa
leaq 0x7e96(%rip), %rax      # 0x47887
movq %rax, -0x98(%rbp)
jmp 0x3fa05
movq -0x20(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x3fa2a
leaq 0x7e66(%rip), %rax      # 0x47887
movq %rax, -0xa8(%rbp)
jmp 0x3fa35
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movl -0x5c(%rbp), %ecx
leaq -0x70(%rbp), %rdi
callq 0x43550
leaq -0x60(%rbp), %rdi
callq 0x10320
cmpq $0x0, -0x20(%rbp)
jne 0x3fa6f
leaq 0x7e21(%rip), %rax      # 0x47887
movq %rax, -0xb0(%rbp)
jmp 0x3fa7a
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x3fa9f
leaq 0x7df1(%rip), %rax      # 0x47887
movq %rax, -0xc0(%rbp)
jmp 0x3faaa
movq -0x68(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movl -0x6c(%rbp), %edx
callq 0x43600
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x43720
movq -0x78(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r9
callq 0x3ccc0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x3cb30
movq -0x80(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x80(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x80(%rbp), %rdi
callq 0x3cf70
movq -0x78(%rbp), %rdi
callq 0x436d0
movq -0x48(%rbp), %rdi
callq 0xa1b0
leaq -0x28(%rbp), %rdi
callq 0x10320
leaq -0x70(%rbp), %rdi
callq 0x10320
movb $0x1, -0x1(%rbp)
jmp 0x3fb63
leaq -0x28(%rbp), %rdi
callq 0x10320
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)