// File: /workspace/github_c_makefile_star2_O2/MikeGray-APH[P]LibLouisAPH/source/compile.c
// Function: file_read
static void file_read(FILE *file, const char *file_name)
{
	FILE *include_file;
	char cchars[INPUT_LINE_MAX], path_name[INPUT_LINE_MAX];
	int pause, len, crs, i;

	if(include_depth >= INCLUDE_DEPTH_MAX - 1)
	{
		log_message(LOG_ERROR, "%s:%d  too many levels of include files", table_file_names[include_depth], table_file_lines[include_depth]);
		log_included_file_errors();
		return;
	}

	include_depth++;
	table_file_names[include_depth] = file_name;
	table_file_lines[include_depth] = 0;

	pause = 0;
	while(fgets(cchars, INPUT_LINE_MAX, file))
	{
		table_file_lines[include_depth]++;

		len = strlen(cchars);
		if(cchars[len - 1] != '\n' && cchars[len - 1] != '\r')
		{
			/*   last line not empty   */
			if(fgets(cchars, INPUT_LINE_MAX, file))
			{
				/*   input too long   */
				log_message(LOG_ERROR, "%s:%d  line too long", table_file_names[include_depth], table_file_lines[include_depth]);
				log_included_file_errors();

				len = strlen(cchars);
				while(cchars[len - 1] != '\n' && cchars[len - 1] != '\r')
				if(fgets(cchars, INPUT_LINE_MAX, file))
					len = strlen(cchars);
				else
					break;
				continue;
			}
		}

		if(pause)
		{
			if(!strncmp(cchars, ".cont", 5))
				pause = 0;
			continue;
		}
		else if(!strncmp(cchars, ".stop", 5))
		{
			pause = 1;
			continue;
		}

		if(cchars[0] == '#')
			continue;

		/*   include file   */
		else if(!strncmp(cchars, "include", 7))
		{
			/*   parse file name   */
			if(cchars[7] != ' ' && cchars[7] != '\t')
			{
				log_message(LOG_ERROR, "%s:%d  include missing file name", table_file_names[include_depth], table_file_lines[include_depth]);
				log_included_file_errors();
				continue;
			}
			for(crs = 8; cchars[crs] && crs < INPUT_LINE_MAX; crs++)
			if(!is_space(cchars[crs]))
				break;
			if(crs >= INPUT_LINE_MAX)
			{
				log_message(LOG_ERROR, "%s:%d  include missing file name", table_file_names[include_depth], table_file_lines[include_depth]);
				log_included_file_errors();
				continue;
			}

			/*   trim whitespace at end   */
			for(i = strlen(cchars) - 1; i > 8; i--)
			if(is_space(cchars[i]))
				cchars[i] = 0;
			else
				break;
			if(i <= 8)
			{
				log_message(LOG_ERROR, "%s:%d  invalid include", table_file_names[include_depth], table_file_lines[include_depth]);
				log_included_file_errors();
				continue;
			}

			/*   compile include file   */
			include_file = lookup_open_file(path_name, INPUT_LINE_MAX, &cchars[crs], table->file_name);
			if(!include_file)
			{
				log_message(LOG_ERROR, "%s:%d  unable to open include file %s", table_file_names[include_depth], table_file_lines[include_depth], &cchars[crs]);
				log_included_file_errors();
				continue;
			}
			file_read(include_file, path_name);
			fclose(include_file);
			continue;
		}

		memset(token_line, 0, INPUT_LINE_MAX * sizeof(unichar));
		utf8_convert_to_utf16(token_line, INPUT_LINE_MAX - 1, cchars, INPUT_LINE_MAX, NULL);

		if(!token_init(token_line))
			continue;

		if(token_is_equal(".end", 4))
			break;

		/*  do this here so macros can't define other macros   */
		if(token_is_equal("macro", 5))
		{
			if(!compile_macro(file, cchars, file_name))
				log_included_file_errors();
			continue;
		}

		token_compile();
	}

	include_depth--;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movslq 0x1436d(%rip), %rax     # 0x171c8
leaq 0x1438e(%rip), %rdx     # 0x171f0
cmpq $0x7, %rax
jl 0x2e9d
movq (%rdx,%rax,8), %rdx
leaq 0x1435d(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
leaq 0xe48f(%rip), %rsi      # 0x1130c
pushq $0x6
popq %rdi
xorl %eax, %eax
callq 0x9174
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3612
movq %rdi, %r14
movabsq $-0x100000000, %rbx     # imm = 0xFFFFFFFF00000000
leal 0x1(%rax), %ecx
movl %ecx, 0x14315(%rip)     # 0x171c8
movq %rsi, 0x8(%rsp)
movq %rsi, 0x8(%rdx,%rax,8)
leaq 0x1430c(%rip), %rcx     # 0x171d0
andl $0x0, 0x4(%rcx,%rax,4)
leaq 0x10(%rsp), %r15
leaq 0xe45f(%rip), %r13      # 0x11334
xorl %ebp, %ebp
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x3228
movslq 0x142d1(%rip), %rax     # 0x171c8
leaq 0x142d2(%rip), %rcx     # 0x171d0
incl (%rcx,%rax,4)
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbx, %rax
sarq $0x20, %rax
movzbl 0x10(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x2fb6
cmpl $0xd, %eax
je 0x2fb6
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x2fb6
movslq 0x14281(%rip), %rax     # 0x171c8
leaq 0x142a2(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x14277(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
pushq $0x6
popq %rdi
leaq 0xe38c(%rip), %rsi      # 0x112f2
xorl %eax, %eax
callq 0x9174
callq 0x3612
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbx, %rax
sarq $0x20, %rax
movzbl 0x10(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x2ed7
cmpl $0xd, %eax
je 0x2ed7
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
jne 0x2f72
jmp 0x2ed7
movq %r15, %rdi
testl %ebp, %ebp
je 0x2fd5
movq %r13, %rsi
pushq $0x5
popq %rdx
callq 0x11b0
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
jmp 0x2ed7
leaq 0xe35e(%rip), %rsi      # 0x1133a
pushq $0x5
popq %rdx
callq 0x11b0
pushq $0x1
popq %rcx
movl %ecx, %ebp
testl %eax, %eax
je 0x2ed7
cmpb $0x23, 0x10(%rsp)
movl $0x0, %ebp
je 0x2ed7
movq %r15, %rdi
leaq 0xe365(%rip), %rsi      # 0x11370
pushq $0x7
popq %rdx
callq 0x11b0
testl %eax, %eax
je 0x30a5
xorl %ebp, %ebp
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %r12
leaq 0x14204(%rip), %r13     # 0x17230
movq %r13, %rdi
xorl %esi, %esi
callq 0x1110
movq %r13, %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl $0x1000, %ecx           # imm = 0x1000
xorl %r8d, %r8d
callq 0x146a
movq %r13, %rdi
movq %r12, %r13
callq 0x3664
testl %eax, %eax
je 0x2ed7
leaq 0xe29f(%rip), %rdi      # 0x11307
pushq $0x4
popq %rsi
callq 0x36a1
testl %eax, %eax
jne 0x3228
leaq 0xe31f(%rip), %rdi      # 0x1139e
pushq $0x5
popq %rsi
callq 0x36a1
testl %eax, %eax
je 0x30dc
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x36e9
testl %eax, %eax
jne 0x2ed7
jmp 0x311e
movzbl 0x17(%rsp), %eax
cmpl $0x20, %eax
je 0x30b4
cmpl $0x9, %eax
jne 0x30ef
pushq $0x8
popq %rbp
cmpq $0xfff, %rbp            # imm = 0xFFF
ja 0x30e6
movb 0x10(%rsp,%rbp), %al
testb %al, %al
je 0x30e6
movsbl %al, %eax
movzwl %ax, %edi
callq 0x36b8
testl %eax, %eax
je 0x3128
incq %rbp
jmp 0x30b7
callq 0x3ac7
jmp 0x2ed7
cmpq $0x1000, %rbp           # imm = 0x1000
jb 0x3128
movslq 0x140d2(%rip), %rax     # 0x171c8
leaq 0x140f3(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x140c8(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
xorl %ebp, %ebp
pushq $0x6
popq %rdi
leaq 0xe229(%rip), %rsi      # 0x11340
xorl %eax, %eax
callq 0x9174
callq 0x3612
jmp 0x2ed7
leaq (%rsp,%rbp), %r12
addq $0x10, %r12
movq %r15, %rdi
callq 0x10b0
movl %eax, %r13d
decq %r13
cmpl $0x9, %r13d
jl 0x3165
movl %r13d, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movsbl 0x10(%rsp,%rbp), %eax
movzwl %ax, %edi
callq 0x36b8
testl %eax, %eax
je 0x31a5
movb $0x0, 0x10(%rsp,%rbp)
jmp 0x313b
movslq 0x1405c(%rip), %rax     # 0x171c8
leaq 0x1407d(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x14052(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
xorl %ebp, %ebp
pushq $0x6
popq %rdi
leaq 0xe1d4(%rip), %rsi      # 0x11361
xorl %eax, %eax
callq 0x9174
callq 0x3612
leaq 0xe194(%rip), %r13      # 0x11334
jmp 0x2ed7
movq 0x13fe4(%rip), %rax     # 0x17190
movq 0x10(%rax), %rcx
leaq 0x1010(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rdx
callq 0x8fcc
testq %rax, %rax
leaq 0xe165(%rip), %r13      # 0x11334
jne 0x3208
movslq 0x13ff0(%rip), %rax     # 0x171c8
leaq 0x14011(%rip), %rcx     # 0x171f0
movq (%rcx,%rax,8), %rdx
leaq 0x13fe6(%rip), %rcx     # 0x171d0
movl (%rcx,%rax,4), %ecx
xorl %ebp, %ebp
pushq $0x6
popq %rdi
leaq 0xe17f(%rip), %rsi      # 0x11378
movq %r12, %r8
xorl %eax, %eax
callq 0x9174
jmp 0x311e
movq %rax, %rbp
movq %rax, %rdi
leaq 0x1010(%rsp), %rsi
callq 0x2e43
movq %rbp, %rdi
callq 0x10a0
jmp 0x2ed5
decl 0x13f9a(%rip)           # 0x171c8
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq