// File: /workspace/github_c_makefile_star2_O2/been-jamming[P]MinimalCC/compile.c
// Function: main
int main(int argc, char **argv){
	char identifier_name[32];
	char arguments[32*32];
	FILE *fp;
	unsigned int file_size;
	char *output_filename = NULL;

	if(argc < 2){
		printf("Minimal C Compiler for MIPS\nby Ben Jones\n2/29/2020\n");
		return 0;
	}
	parse_arguments(argc, argv, source_files, MAX_SOURCEFILES - 1, &output_filename);
	if(!output_filename){
		output_filename = "a.s";
	}
	output_file = fopen(output_filename, "w");
	if(!output_file){
		fprintf(stderr, "Could not open file '%s' for writing\n", output_filename);
		exit(1);
	}
	global_variables = create_dictionary(NULL);
	current_source_file = source_files;
	current_scope = -1;
	memset(local_variables, 0, sizeof(local_variables));
	while(*current_source_file){
		fp = fopen(*current_source_file, "rb");
		if(!fp){
			fprintf(stderr, "Could not open file '%s' for reading\n", *current_source_file);
			free_global_variables();
			exit(1);
		}
		fseek(fp, 0, SEEK_END);
		file_size = ftell(fp);
		rewind(fp);
		program = calloc(file_size + 1, sizeof(char));
		if(fread(program, sizeof(char), file_size, fp) < file_size){
			fclose(fp);
			fprintf(stderr, "Failed to read file '%s'\n", *current_source_file);
			free_global_variables();
			exit(1);
		}
		fclose(fp);
		initialize_register_list();
		compile_file(program, identifier_name, arguments, 32, 32, output_file);
		free(program);
		current_source_file++;
	}
	fclose(output_file);
	free_global_variables();

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
andq $0x0, 0x8(%rsp)
cmpl $0x1, %edi
jg 0x6c62
leaq 0x235f(%rip), %rdi      # 0x8fb7
callq 0x1060
jmp 0x6dd9
leaq 0x59e7(%rip), %rbx      # 0xc650
pushq $0x1f
popq %rcx
leaq 0x8(%rsp), %r14
movq %rbx, %rdx
movq %r14, %r8
callq 0x6b63
movq (%r14), %rax
testq %rax, %rax
leaq 0x2212(%rip), %r14      # 0x8e9b
cmovneq %rax, %r14
leaq 0x220b(%rip), %rsi      # 0x8e9f
movq %r14, %rdi
callq 0x1160
movq %rax, 0x593d(%rip)      # 0xc5e0
testq %rax, %rax
je 0x6e3b
leaq 0x30(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x6f30
leaq 0x55be(%rip), %rdi      # 0xc280
pushq $0x9
popq %rcx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, 0x5a7e(%rip)      # 0xc750
leaq 0x55ef(%rip), %rax      # 0xc2c8
orl $-0x1, (%rax)
leaq 0x55ed(%rip), %rdi      # 0xc2d0
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x10d0
pushq $0x1
popq %r15
leaq 0x10(%rsp), %r12
pushq $0x20
popq %r13
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x6dc6
leaq 0x21b8(%rip), %rsi      # 0x8ec7
callq 0x1160
testq %rax, %rax
je 0x6ded
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
callq 0x1150
movq %rbx, %rdi
callq 0x1110
movq %rax, %r14
movq %rbx, %rdi
callq 0x10b0
leal 0x1(%r14), %edi
movq %r15, %rsi
callq 0x10f0
movq %rax, 0x5895(%rip)      # 0xc5e8
movl %r14d, %r14d
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x1070
movq %rax, %rbp
movq %rbx, %rdi
callq 0x1080
cmpq %r14, %rbp
jb 0x6e0a
xorl %eax, %eax
callq 0x12bc
movq 0x585f(%rip), %rdi      # 0xc5e8
movq 0x5850(%rip), %r9       # 0xc5e0
movq %r12, %rsi
leaq 0x30(%rsp), %rdx
movl %r13d, %ecx
movl %r13d, %r8d
callq 0x5726
movq 0x583e(%rip), %rdi      # 0xc5e8
callq 0x1030
movq 0x599a(%rip), %rbx      # 0xc750
addq $0x8, %rbx
movq %rbx, 0x598f(%rip)      # 0xc750
jmp 0x6cfc
movq 0x5813(%rip), %rdi      # 0xc5e0
callq 0x1080
xorl %eax, %eax
callq 0x2861
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5204(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq 0x5952(%rip), %rax      # 0xc750
movq (%rax), %rdx
leaq 0x20c2(%rip), %rsi      # 0x8eca
jmp 0x6e25
movq 0x51e7(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq 0x5935(%rip), %rax      # 0xc750
movq (%rax), %rdx
leaq 0x20cb(%rip), %rsi      # 0x8ef0
xorl %eax, %eax
callq 0x1100
xorl %eax, %eax
callq 0x2861
pushq $0x1
popq %rdi
callq 0x1180
movq 0x51b6(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x2055(%rip), %rsi      # 0x8ea1
movq %r14, %rdx
xorl %eax, %eax
callq 0x1100
jmp 0x6e33