// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x498, %rsp            # imm = 0x498
movl $0x0, 0x494(%rsp)
movl %edi, 0x490(%rsp)
movq %rsi, 0x488(%rsp)
movq $0x0, 0x48(%rsp)
cmpl $0x2, 0x490(%rsp)
jge 0xab02
leaq 0x367e(%rip), %rdi      # 0xe169
movb $0x0, %al
callq 0x1090
movl $0x0, 0x494(%rsp)
jmp 0xad5d
movl 0x490(%rsp), %edi
movq 0x488(%rsp), %rsi
leaq 0x6b88(%rip), %rdx      # 0x116a0
movl $0x1f, %ecx
leaq 0x48(%rsp), %r8
callq 0xa8c0
cmpq $0x0, 0x48(%rsp)
jne 0xab3b
leaq 0x3667(%rip), %rax      # 0xe19d
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x365a(%rip), %rsi      # 0xe1a1
callq 0x1150
movq %rax, 0x6add(%rip)      # 0x11630
cmpq $0x0, 0x6ad5(%rip)      # 0x11630
jne 0xab84
movq 0x6494(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq 0x48(%rsp), %rdx
leaq 0x3630(%rip), %rsi      # 0xe1a3
movb $0x0, %al
callq 0x10f0
movl $0x1, %edi
callq 0x1170
movq %rsp, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xaf20
leaq 0x6739(%rip), %rdi      # 0x112d0
movq %rsp, %rsi
movl $0x48, %edx
callq 0x1120
leaq 0x6af5(%rip), %rax      # 0x116a0
movq %rax, 0x6bee(%rip)      # 0x117a0
leaq 0x675f(%rip), %rax      # 0x11318
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x675a(%rip), %rdi      # 0x11320
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10c0
movq 0x6bc7(%rip), %rax      # 0x117a0
cmpq $0x0, (%rax)
je 0xad3f
movq 0x6bb6(%rip), %rax      # 0x117a0
movq (%rax), %rdi
leaq 0x35d5(%rip), %rsi      # 0xe1c9
callq 0x1150
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0xac39
movq 0x63eb(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq 0x6b89(%rip), %rax      # 0x117a0
movq (%rax), %rdx
leaq 0x35ab(%rip), %rsi      # 0xe1cc
movb $0x0, %al
callq 0x10f0
movb $0x0, %al
callq 0x2f10
movl $0x1, %edi
callq 0x1170
movq 0x58(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1140
movq 0x58(%rsp), %rdi
callq 0x1100
movl %eax, 0x54(%rsp)
movq 0x58(%rsp), %rdi
callq 0x10a0
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x10e0
movq %rax, 0x69b8(%rip)      # 0x11638
movq 0x69b1(%rip), %rdi      # 0x11638
movl 0x54(%rsp), %eax
movl %eax, %edx
movq 0x58(%rsp), %rcx
movl $0x1, %esi
callq 0x1060
movl 0x54(%rsp), %ecx
cmpq %rcx, %rax
jae 0xace2
movq 0x58(%rsp), %rdi
callq 0x1070
movq 0x6342(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq 0x6ae0(%rip), %rax      # 0x117a0
movq (%rax), %rdx
leaq 0x3528(%rip), %rsi      # 0xe1f2
movb $0x0, %al
callq 0x10f0
movb $0x0, %al
callq 0x2f10
movl $0x1, %edi
callq 0x1170
movq 0x58(%rsp), %rdi
callq 0x1070
movb $0x0, %al
callq 0x12a0
movq 0x693e(%rip), %rdi      # 0x11638
leaq 0x460(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq 0x6922(%rip), %r9       # 0x11630
movl $0x20, %r8d
movl %r8d, %ecx
callq 0x8810
movq 0x6915(%rip), %rdi      # 0x11638
callq 0x1030
movq 0x6a71(%rip), %rax      # 0x117a0
addq $0x8, %rax
movq %rax, 0x6a66(%rip)      # 0x117a0
jmp 0xabd2
movq 0x68ea(%rip), %rdi      # 0x11630
callq 0x1070
movb $0x0, %al
callq 0x2f10
movl $0x0, 0x494(%rsp)
movl 0x494(%rsp), %eax
addq $0x498, %rsp            # imm = 0x498
retq
nopl (%rax)