// File: /workspace/github_c_makefile_star2_O1/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 0x1517f(%rip), %rax     # 0x181b8
cmpq $0x7, %rax
jl 0x307d
leaq 0x1519a(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x1516f(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0x10271(%rip), %rsi     # 0x132cc
movl $0x6, %edi
xorl %eax, %eax
callq 0xa36c
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3930
movq %rdi, %r14
leal 0x1(%rax), %ecx
movl %ecx, 0x1512f(%rip)     # 0x181b8
leaq 0x15150(%rip), %rcx     # 0x181e0
movq %rsi, 0x8(%rsp)
movq %rsi, 0x8(%rcx,%rax,8)
leaq 0x1511f(%rip), %r12     # 0x181c0
movl $0x0, 0x4(%r12,%rax,4)
leaq 0x10(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x3490
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
leaq 0x10(%rsp), %r15
leaq 0x10283(%rip), %rbx     # 0x1335e
xorl %r13d, %r13d
movslq 0x150d3(%rip), %rax     # 0x181b8
incl (%r12,%rax,4)
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbp, %rax
sarq $0x20, %rax
movzbl 0x10(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x318b
cmpl $0xd, %eax
je 0x318b
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x318b
movslq 0x1508d(%rip), %rax     # 0x181b8
leaq 0x150ae(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
movl $0x6, %edi
leaq 0x1016c(%rip), %rsi     # 0x132b2
xorl %eax, %eax
callq 0xa36c
callq 0x3930
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbp, %rax
sarq $0x20, %rax
movzbl 0x10(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x31ac
cmpl $0xd, %eax
je 0x31ac
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
jne 0x3152
jmp 0x31ac
testl %r13d, %r13d
je 0x31ca
movl 0x10(%rsp), %eax
movl $0x6e6f632e, %ecx       # imm = 0x6E6F632E
xorl %ecx, %eax
movzbl 0x14(%rsp), %ecx
xorl $0x74, %ecx
xorl %r13d, %r13d
orl %eax, %ecx
setne %r13b
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
jne 0x30de
jmp 0x3490
movl 0x10(%rsp), %eax
movl $0x6f74732e, %ecx       # imm = 0x6F74732E
xorl %ecx, %eax
movzbl 0x14(%rsp), %ecx
xorl $0x70, %ecx
orl %eax, %ecx
je 0x329f
xorl %r13d, %r13d
cmpb $0x23, 0x10(%rsp)
je 0x31ac
movl 0x10(%rsp), %eax
movl $0x6c636e69, %ecx       # imm = 0x6C636E69
xorl %ecx, %eax
movl 0x13(%rsp), %ecx
movl $0x6564756c, %edx       # imm = 0x6564756C
xorl %edx, %ecx
orl %eax, %ecx
je 0x32aa
movq %rbx, %r12
xorl %r13d, %r13d
movl $0x2000, %edx           # imm = 0x2000
leaq 0x15001(%rip), %rbx     # 0x18220
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1110
movq %rbx, %rdi
movl $0xfff, %esi            # imm = 0xFFF
movq %r15, %rdx
movl $0x1000, %ecx           # imm = 0x1000
xorl %r8d, %r8d
callq 0x147f
movq %rbx, %rdi
callq 0x398a
testl %eax, %eax
je 0x3301
movq 0x16fd0(%rip), %rax     # 0x1a228
movl 0x16fc2(%rip), %ecx     # 0x1a220
cmpl $0x5, %ecx
movq %r12, %rbx
leaq 0x14f55(%rip), %r12     # 0x181c0
je 0x3319
cmpl $0x4, %ecx
jne 0x334b
xorl %edx, %edx
leaq 0x10044(%rip), %rsi     # 0x132c7
movsbl (%rdx,%rsi), %esi
cmpw %si, (%rax,%rdx,2)
jne 0x3314
incq %rdx
cmpq $0x4, %rdx
jne 0x327c
jmp 0x3490
movl $0x1, %r13d
jmp 0x31ac
movzbl 0x17(%rsp), %eax
cmpl $0x9, %eax
je 0x32bd
cmpl $0x20, %eax
jne 0x3364
movb 0x18(%rsp), %cl
movl $0x8, %r13d
testb %cl, %cl
je 0x3310
movabsq $0x100002600, %rdx      # imm = 0x100002600
cmpb $0x20, %cl
ja 0x3355
movzbl %cl, %eax
btq %rax, %rdx
jae 0x3355
leaq 0x1(%r13), %rax
cmpq $0xffe, %r13            # imm = 0xFFE
ja 0x32fc
movb 0x11(%rsp,%r13), %cl
movq %rax, %r13
testb %cl, %cl
jne 0x32d5
movq %rax, %r13
jmp 0x3358
movq %r12, %rbx
leaq 0x14eb5(%rip), %r12     # 0x181c0
jmp 0x31ac
xorl %eax, %eax
jmp 0x3360
cmpl $0x5, %ecx
jne 0x334b
xorl %ecx, %ecx
movsbl (%rcx,%rbx), %edx
cmpw %dx, (%rax,%rcx,2)
jne 0x334b
incq %rcx
cmpq $0x5, %rcx
jne 0x331b
movq %r14, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x39dd
testl %eax, %eax
jne 0x31ac
jmp 0x3407
callq 0x3e97
jmp 0x31ac
movl %r13d, %eax
cmpl $0x1000, %eax           # imm = 0x1000
setae %al
testb %al, %al
je 0x338b
movslq 0x14e4d(%rip), %rax     # 0x181b8
leaq 0x14e6e(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0xff77(%rip), %rsi      # 0x13300
jmp 0x3400
movq %r15, %rdi
callq 0x10b0
decl %eax
cmpl $0x9, %eax
jl 0x33db
leaq (%rsp,%r13), %r8
addq $0x10, %r8
movl %eax, %eax
movabsq $0x100002600, %rdx      # imm = 0x100002600
movzbl 0x10(%rsp,%rax), %ecx
cmpq $0x20, %rcx
ja 0x33d6
btq %rcx, %rdx
jae 0x33d6
movb $0x0, 0x10(%rsp,%rax)
leaq -0x1(%rax), %rcx
cmpq $0x9, %rax
movq %rcx, %rax
jg 0x33ae
movl $0x8, %eax
cmpl $0x8, %eax
jg 0x3411
movslq 0x14dd6(%rip), %rax     # 0x181b8
leaq 0x14df7(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0xff21(%rip), %rsi      # 0x13321
xorl %eax, %eax
callq 0xa36c
callq 0x3930
jmp 0x31ac
movq 0x14d68(%rip), %rax     # 0x18180
movq 0x10(%rax), %rcx
leaq 0x1010(%rsp), %r13
movq %r13, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r8, %rdx
movq %r8, (%rsp)
callq 0xa103
testq %rax, %rax
je 0x345b
movq %r13, %rsi
movq %rax, %r13
movq %rax, %rdi
callq 0x3021
movq %r13, %rdi
callq 0x10a0
xorl %r13d, %r13d
jmp 0x31ac
movslq 0x14d56(%rip), %rax     # 0x181b8
leaq 0x14d77(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0xfeb8(%rip), %rsi      # 0x13338
movq (%rsp), %r8
xorl %eax, %eax
callq 0xa36c
jmp 0x3407
decl 0x14d22(%rip)           # 0x181b8
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq