// File: /workspace/github_c_makefile_star2_O1/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 0x70cf
leaq 0x2f1e(%rip), %rdi      # 0x9fe3
callq 0x1060
jmp 0x7265
leaq 0x657a(%rip), %rbx      # 0xd650
leaq 0x8(%rsp), %r15
movq %rbx, %rdx
movl $0x1f, %ecx
movq %r15, %r8
callq 0x7006
movq (%r15), %rax
testq %rax, %rax
leaq 0x2dcf(%rip), %r14      # 0x9ec7
cmovneq %rax, %r14
movq %r14, (%r15)
leaq 0x2dc5(%rip), %rsi      # 0x9ecb
movq %r14, %rdi
callq 0x1160
movq %rax, 0x64cb(%rip)      # 0xd5e0
testq %rax, %rax
je 0x7283
leaq 0x30(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x728c
leaq 0x614c(%rip), %rdi      # 0xd280
movl $0x9, %ecx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, 0x660a(%rip)      # 0xd750
leaq 0x617b(%rip), %rax      # 0xd2c8
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x6176(%rip), %rdi      # 0xd2d0
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x10d0
movq 0x64e3(%rip), %rdi      # 0xd650
testq %rdi, %rdi
je 0x7252
leaq 0x2d76(%rip), %rbx      # 0x9ef3
leaq 0x10(%rsp), %r14
leaq 0x30(%rsp), %r15
movq %rbx, %rsi
callq 0x1160
testq %rax, %rax
je 0x7279
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, 0x6416(%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 0x727e
xorl %eax, %eax
callq 0x14ec
movq 0x63de(%rip), %rdi      # 0xd5e8
movq 0x63cf(%rip), %r9       # 0xd5e0
movq %r14, %rsi
movq %r15, %rdx
movl $0x20, %ecx
movl $0x20, %r8d
callq 0x5b41
movq 0x63ba(%rip), %rdi      # 0xd5e8
callq 0x1030
movq 0x6516(%rip), %rax      # 0xd750
leaq 0x8(%rax), %rcx
movq %rcx, 0x650b(%rip)      # 0xd750
movq 0x8(%rax), %rdi
testq %rdi, %rdi
jne 0x7187
movq 0x6387(%rip), %rdi      # 0xd5e0
callq 0x1080
xorl %eax, %eax
callq 0x2ab6
xorl %eax, %eax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1384
callq 0x1352
movq %r14, %rdi
callq 0x13b6
nop