// File: /workspace/github_c_makefile_star2_O3/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 $0x2028, %rsp           # imm = 0x2028
movslq 0x1521f(%rip), %rax     # 0x181b8
cmpq $0x7, %rax
jl 0x2fdd
leaq 0x1523a(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
leaq 0x1520f(%rip), %rcx     # 0x181c0
movl (%rcx,%rax,4), %ecx
leaq 0x103b1(%rip), %rsi     # 0x1336c
movl $0x6, %edi
xorl %eax, %eax
callq 0xa278
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x38c0
movq %rdi, %r14
leal 0x1(%rax), %ecx
movl %ecx, 0x151cf(%rip)     # 0x181b8
leaq 0x151f0(%rip), %rcx     # 0x181e0
movq %rsi, 0x18(%rsp)
movq %rsi, 0x8(%rcx,%rax,8)
leaq 0x151bf(%rip), %r12     # 0x181c0
movl $0x0, 0x4(%r12,%rax,4)
leaq 0x20(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x341e
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
leaq 0x20(%rsp), %r15
movl $0x6e6f632e, %ebx       # imm = 0x6E6F632E
xorl %r13d, %r13d
movslq 0x15175(%rip), %rax     # 0x181b8
incl (%r12,%rax,4)
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbp, %rax
sarq $0x20, %rax
movzbl 0x20(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x30e9
cmpl $0xd, %eax
je 0x30e9
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
je 0x30e9
movslq 0x1512f(%rip), %rax     # 0x181b8
leaq 0x15150(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
movl $0x6, %edi
leaq 0x102ae(%rip), %rsi     # 0x13352
xorl %eax, %eax
callq 0xa278
callq 0x38c0
movq %r15, %rdi
callq 0x10b0
shlq $0x20, %rax
addq %rbp, %rax
sarq $0x20, %rax
movzbl 0x20(%rsp,%rax), %eax
cmpl $0xa, %eax
je 0x3105
cmpl $0xd, %eax
je 0x3105
movq %r15, %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdx
callq 0x1140
testq %rax, %rax
jne 0x30b0
jmp 0x3105
testl %r13d, %r13d
je 0x3123
movl 0x20(%rsp), %eax
xorl %ebx, %eax
movzbl 0x24(%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 0x303c
jmp 0x341e
movl 0x20(%rsp), %eax
movl $0x6f74732e, %ecx       # imm = 0x6F74732E
xorl %ecx, %eax
movzbl 0x24(%rsp), %ecx
xorl $0x70, %ecx
orl %eax, %ecx
je 0x320f
xorl %r13d, %r13d
cmpb $0x23, 0x20(%rsp)
je 0x3105
movl 0x20(%rsp), %eax
movl $0x6c636e69, %ecx       # imm = 0x6C636E69
xorl %ecx, %eax
movl 0x23(%rsp), %ecx
movl $0x6564756c, %edx       # imm = 0x6564756C
xorl %edx, %ecx
orl %eax, %ecx
je 0x321a
xorl %r13d, %r13d
movl $0x2000, %edx           # imm = 0x2000
leaq 0x150ab(%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 0x1491
movq %rbx, %rdi
callq 0x391a
testl %eax, %eax
je 0x3396
movq 0x1707a(%rip), %rax     # 0x1a228
movl 0x1706c(%rip), %ecx     # 0x1a220
cmpl $0x4, %ecx
leaq 0x101a9(%rip), %rsi     # 0x13367
leaq 0x10239(%rip), %rdi     # 0x133fe
movl $0x6e6f632e, %ebx       # imm = 0x6E6F632E
je 0x32ac
cmpl $0x5, %ecx
jne 0x32c6
xorl %ecx, %ecx
movsbl (%rcx,%rdi), %edx
cmpw %dx, (%rax,%rcx,2)
jne 0x32c6
incq %rcx
cmpq $0x5, %rcx
jne 0x31db
movq %r14, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
callq 0x396d
testl %eax, %eax
jne 0x3105
jmp 0x32fc
movl $0x1, %r13d
jmp 0x3105
movzbl 0x27(%rsp), %eax
cmpl $0x9, %eax
je 0x322d
cmpl $0x20, %eax
jne 0x32d0
movb 0x28(%rsp), %al
testb %al, %al
je 0x3306
movl $0x7, %ebx
movabsq $0x100002600, %rdx      # imm = 0x100002600
cmpb $0x20, %al
ja 0x3315
movzbl %al, %eax
btq %rax, %rdx
jae 0x3315
leaq 0x1(%rbx), %rcx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x3275
movb 0x22(%rsp,%rbx), %al
movq %rcx, %rbx
testb %al, %al
jne 0x3248
cmpq $0xfff, %rcx            # imm = 0xFFF
jb 0x330d
movslq 0x14f2f(%rip), %rax     # 0x181b8
leaq 0x14f50(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0x100f9(%rip), %rsi     # 0x133a0
jmp 0x338a
xorl %ecx, %ecx
movsbl (%rcx,%rsi), %edx
cmpw %dx, (%rax,%rcx,2)
jne 0x32c6
incq %rcx
cmpq $0x4, %rcx
jne 0x32ae
jmp 0x341e
callq 0x3da3
jmp 0x3105
movslq 0x14ee1(%rip), %rax     # 0x181b8
leaq 0x14f02(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0x100ab(%rip), %rsi     # 0x133a0
xorl %eax, %eax
callq 0xa278
callq 0x38c0
jmp 0x3105
movl $0x8, %ebx
jmp 0x3318
incq %rcx
movq %rcx, %rbx
jmp 0x3318
incq %rbx
movq %r15, %rdi
callq 0x10b0
decl %eax
cmpl $0x9, %eax
leaq 0x1020(%rsp), %rdi
movabsq $0x100002600, %rsi      # imm = 0x100002600
jl 0x3365
leaq (%rsp,%rbx), %rdx
addq $0x20, %rdx
movl %eax, %eax
incq %rax
movzbl 0x1f(%rsp,%rax), %ecx
cmpq $0x20, %rcx
ja 0x33a0
btq %rcx, %rsi
jae 0x33a0
movb $0x0, 0x1f(%rsp,%rax)
decq %rax
cmpq $0x9, %rax
jg 0x3346
movslq 0x14e4c(%rip), %rax     # 0x181b8
leaq 0x14e6d(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0x10037(%rip), %rsi     # 0x133c1
xorl %eax, %eax
callq 0xa278
callq 0x38c0
movl $0x6e6f632e, %ebx       # imm = 0x6E6F632E
jmp 0x3105
movq 0x14dd9(%rip), %rax     # 0x18180
movq 0x10(%rax), %rcx
movl $0x1000, %esi           # imm = 0x1000
movq %rdx, 0x10(%rsp)
callq 0xa004
testq %rax, %rax
movl $0x6e6f632e, %ebx       # imm = 0x6E6F632E
je 0x33e8
movq %rax, %rdi
movq %rax, 0x8(%rsp)
leaq 0x1020(%rsp), %rsi
callq 0x2f81
movq 0x8(%rsp), %rdi
callq 0x10a0
jmp 0x3105
movslq 0x14dc9(%rip), %rax     # 0x181b8
leaq 0x14dea(%rip), %rcx     # 0x181e0
movq (%rcx,%rax,8), %rdx
movl (%r12,%rax,4), %ecx
xorl %r13d, %r13d
movl $0x6, %edi
leaq 0xffcb(%rip), %rsi      # 0x133d8
movq 0x10(%rsp), %r8
xorl %eax, %eax
callq 0xa278
jmp 0x32fc
decl 0x14d94(%rip)           # 0x181b8
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq