// File: /workspace/github_c_makefile_star2_O0/kisom[P]kam/compiler.c
// Function: main
int
main(int argc, char *argv[])
{
	int	 opt, trace, status = EXIT_SUCCESS;
	char	*prog_file = DEFAULT_BIN;

	init_compiler();

	while (-1 != (opt = getopt(argc, argv, "o:t"))) {
		switch(opt) {
		case 'o':
			prog_file = optarg;
			break;
		case 't':
			trace = 1;
			break;
		default:
			/* not reached */
			abort();
		}
	}
	argc -= optind;
	argv += optind;

	if (0 == argc) {
		compiler.source = stdin;
	} else if (1 == argc) {
		printf("Source file: %s\n", argv[0]);
		compiler.source = fopen(argv[0], "rb");
		if (NULL == compiler.source) {
			err(EX_IOERR, "failed to open source file.");
		}
	} else {
		fprintf(stderr, "Compiling multiple files is not supported.\n");
		exit(EX_USAGE);
	}
	compiler.out = fopen(prog_file, "wb");
	if (NULL == compiler.out) {
		err(EX_IOERR, "failed to open output file.");
	}
	if (-1 == parse()) {
		fprintf(stderr, "Compilation failed.\n");
		backtrace(trace);
		status = EXIT_FAILURE;
		goto exit;
	} else if (-1 == write_program()) {
		fprintf(stderr, "Writing binary failed.\n");
		status = EXIT_FAILURE;
		goto exit;
	}
	printf("Wrote compiled program to %s.\n", prog_file);

exit:
	destroy_compiler();
	return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
leaq 0x194c(%rip), %rax      # 0x30a0
movq %rax, -0x28(%rbp)
callq 0x1940
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x193e(%rip), %rdx      # 0x30a9
callq 0x1100
movl %eax, %ecx
movl %ecx, -0x14(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
je 0x17b5
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
subl $0x6f, %eax
je 0x1795
jmp 0x178b
movl -0x2c(%rbp), %eax
subl $0x74, %eax
je 0x17a5
jmp 0x17ae
movq 0x383c(%rip), %rax      # 0x4fd8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x17b3
movl $0x1, -0x18(%rbp)
jmp 0x17b3
callq 0x1040
jmp 0x175d
movq 0x3814(%rip), %rax      # 0x4fd0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq 0x3803(%rip), %rax      # 0x4fd0
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpl -0x8(%rbp), %eax
jne 0x17fb
movq 0x37d9(%rip), %rax      # 0x4fc8
movq (%rax), %rax
movq %rax, 0x38df(%rip)      # 0x50d8
jmp 0x1878
movl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0x1854
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x189a(%rip), %rdi      # 0x30ad
movb $0x0, %al
callq 0x1080
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x1896(%rip), %rsi      # 0x30be
callq 0x10f0
movq %rax, 0x38a4(%rip)      # 0x50d8
xorl %eax, %eax
cmpq 0x389b(%rip), %rax      # 0x50d8
jne 0x1852
movl $0x4a, %edi
leaq 0x1876(%rip), %rsi      # 0x30c1
movb $0x0, %al
callq 0x10d0
jmp 0x1876
movq 0x379d(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1878(%rip), %rsi      # 0x30dd
movb $0x0, %al
callq 0x10b0
movl $0x40, %edi
callq 0x1120
jmp 0x1878
movq -0x28(%rbp), %rdi
leaq 0x1886(%rip), %rsi      # 0x3109
callq 0x10f0
movq %rax, 0x3851(%rip)      # 0x50e0
xorl %eax, %eax
cmpq 0x3848(%rip), %rax      # 0x50e0
jne 0x18ad
movl $0x4a, %edi
leaq 0x1866(%rip), %rsi      # 0x310c
movb $0x0, %al
callq 0x10d0
callq 0x19d0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x18e6
movq 0x3734(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x185a(%rip), %rsi      # 0x3128
movb $0x0, %al
callq 0x10b0
movl -0x18(%rbp), %edi
callq 0x1ab0
movl $0x1, -0x1c(%rbp)
jmp 0x192b
callq 0x1be0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x1917
movq 0x36fb(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1836(%rip), %rsi      # 0x313d
movb $0x0, %al
callq 0x10b0
movl $0x1, -0x1c(%rbp)
jmp 0x192b
jmp 0x1919
movq -0x28(%rbp), %rsi
leaq 0x1831(%rip), %rdi      # 0x3155
movb $0x0, %al
callq 0x1080
callq 0x1d30
movl -0x1c(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)