// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x8(%rsp)
cmpl $0x1, %edi
jg 0x710f
leaq 0x2ed2(%rip), %rdi      # 0x9fd7
callq 0x1060
jmp 0x72a2
leaq 0x653a(%rip), %rbx      # 0xd650
leaq 0x8(%rsp), %r14
movq %rbx, %rdx
movl $0x1f, %ecx
movq %r14, %r8
callq 0x704f
movq (%r14), %rax
testq %rax, %rax
leaq 0x2d83(%rip), %r14      # 0x9ebb
cmovneq %rax, %r14
leaq 0x2d7c(%rip), %rsi      # 0x9ebf
movq %r14, %rdi
callq 0x1160
movq %rax, 0x648e(%rip)      # 0xd5e0
testq %rax, %rax
je 0x72c0
leaq 0x30(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x72c8
leaq 0x610f(%rip), %rdi      # 0xd280
movl $0x9, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, 0x65cd(%rip)      # 0xd750
leaq 0x613e(%rip), %rax      # 0xd2c8
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x6139(%rip), %rdi      # 0xd2d0
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x10d0
movq 0x64a6(%rip), %rdi      # 0xd650
testq %rdi, %rdi
je 0x728f
leaq 0x2d2d(%rip), %rbx      # 0x9ee7
leaq 0x10(%rsp), %r14
leaq 0x30(%rsp), %r15
movq %rbx, %rsi
callq 0x1160
testq %rax, %rax
je 0x72b6
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1150
movq %r12, %rdi
callq 0x1110
movq %rax, %r13
movq %r12, %rdi
callq 0x10b0
leal 0x1(%r13), %edi
movl $0x1, %esi
callq 0x10f0
movq %rax, 0x63d9(%rip)      # 0xd5e8
movl %r13d, %r13d
movl $0x1, %esi
movq %rax, %rdi
movq %r13, %rdx
movq %r12, %rcx
callq 0x1070
movq %rax, %rbp
movq %r12, %rdi
callq 0x1080
cmpq %r13, %rbp
jb 0x72bb
xorl %eax, %eax
callq 0x14ec
movq 0x63a1(%rip), %rdi      # 0xd5e8
movq 0x6392(%rip), %r9       # 0xd5e0
movq %r14, %rsi
movq %r15, %rdx
movl $0x20, %ecx
movl $0x20, %r8d
callq 0x5b71
movq 0x637d(%rip), %rdi      # 0xd5e8
callq 0x1030
movq 0x64d9(%rip), %rax      # 0xd750
leaq 0x8(%rax), %rcx
movq %rcx, 0x64ce(%rip)      # 0xd750
movq 0x8(%rax), %rdi
testq %rdi, %rdi
jne 0x71c4
movq 0x634a(%rip), %rdi      # 0xd5e0
callq 0x1080
xorl %eax, %eax
callq 0x2ac2
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1386
callq 0x1354
movq %r14, %rdi
callq 0x13b8