// File: /workspace/github_c_makefile_star2_O0/hsjoihs[P]c-compiler/cpp.c
// Function: handle_include
static void
handle_include(struct Token **ptr_dst, const struct Token **ptr_src,
               int *ref_dst_offset,
               struct Map2 /*<struct Vector<struct Token>*/ *def_map,
               int *ptr_total_token_num)
{
	const struct Token *src = *ptr_src;
	int dst_offset = *ref_dst_offset;
	struct Token *dst_initial = *ptr_dst;

	if (src[0].kind == OP_LT) {
		unsupported("`#include <...>`");
	}

	expect_and_consume(&src, LIT_STRING, "path after `#include`");

	struct __FILE *fp = fopen(src[-1].literal_str, "r");

	if (!fp) {
		fprintf(stderr, "failed to open file `%s` to be `#include`d.\n",
		        src[-1].literal_str);
		exit(EXIT_FAILURE);
	}

	const char *imported = read_from_file(fp);
	const struct Tokvec new_vec = preprocess(imported, def_map);
	/* def_map will be modified, and that's how all the macros will
	 * be obtained here */

	*ptr_total_token_num += new_vec.tok_num - 2; /* BEGINNING and END gone */

	dst_initial = realloc(dst_initial,
	                      *ptr_total_token_num *
	                          sizeof(struct Token)); /* realloc never fails */

	int l = 1; /* skip BEGINNING */
	while (1) {
		if (new_vec.v[l].kind == END) {
			break;
		}
		dst_initial[dst_offset] = new_vec.v[l];
		dst_offset++;
		l++;
	}

	consume_spaces(&src);

	if (src[0].kind == NEWLINE) {
		src++;
	} else {
		error_unexpected_token(
		    src, "newline or end of file after `#include (filepath)`");
	}

	*ref_dst_offset = dst_offset;
	*ptr_src = src;
	*ptr_dst = dst_initial;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
cmpl $0xd, (%rax)
jne 0x11da0
leaq 0x59a8(%rip), %rdi      # 0x17743
callq 0xb1f0
leaq -0x30(%rbp), %rdi
movl $0x39, %esi
leaq 0x59a4(%rip), %rdx      # 0x17754
callq 0xb190
movq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
leaq 0x36ca(%rip), %rsi      # 0x1548e
callq 0x1110
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x11dfe
movq 0xa21d(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq -0x10(%rax), %rdx
leaq 0x597d(%rip), %rsi      # 0x1776a
movb $0x0, %al
callq 0x10d0
movl $0x1, %edi
callq 0x1150
movq -0x48(%rbp), %rdi
callq 0x11710
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x117c0
movl %eax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
movl -0x60(%rbp), %ecx
subl $0x2, %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq (%rax), %rsi
shlq $0x5, %rsi
callq 0x1100
movq %rax, -0x40(%rbp)
movl $0x1, -0x64(%rbp)
movq -0x58(%rbp), %rax
movslq -0x64(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
jne 0x11e62
jmp 0x11eb2
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq -0x58(%rbp), %rcx
movslq -0x64(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x11e4c
leaq -0x30(%rbp), %rdi
callq 0x11bb0
movq -0x30(%rbp), %rax
cmpl $0x4c, (%rax)
jne 0x11ed2
movq -0x30(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x30(%rbp)
jmp 0x11ee2
movq -0x30(%rbp), %rdi
leaq 0x58ba(%rip), %rsi      # 0x17797
callq 0xb070
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)