// File: /workspace/github_cpp_makefile_star2_O1/lhydave[P]SysYCompilerLab/main.cpp
// Function: main
int main(int argc, char **argv)
{
	bool S = false, e = false, t = false, v = false;
	string output_s;
	// parse args
	for (auto i = 0; i < argc; i++)
	{
		if (argv[i][0] == '-')
		{
			switch (argv[i][1])
			{
			case 'S': S = true; break;
			case 'e': e = true; break;
			case 't': t = true; break;
			case 'v': v = true; break;
			case 'o':
				if (argv[i + 1] == nullptr)
				{
					printf("no output file dedicated");
					return 0;
				}
				output_s = argv[++i];
				break;
			default: printf("unrecognized parameter\n"); return 0;
			}
		}
		else
			yyin = fopen(argv[i], "r");
	}
	if (!S)
	{
		printf("not support yet!\n");
		return 0;
	}
	if (e && t)
	{
		printf("at most one parameter can be dedicated.\n");
		return 0;
	}
	if (!yyin)
	{
		printf("no valid input file!\n");
		return 0;
	}
	sysY_AST::init_tables();
	do
	{
		yyparse();
	} while (!feof(yyin));
	sysY_AST::check_main();
	if (has_err)
		return 1;
	if (e) // generate eeyore
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", sysY_AST::root->code.c_str());
		return 0;
	}
	else if (v) // debug
	{
		auto out_f = fopen("eeyore.out", "w");
		fprintf(out_f, "%s", sysY_AST::root->code.c_str());
		fflush(out_f);
	}
	// generate tigger
	eeyore_AST::build_AST(sysY_AST::root->code);
	no_alloc::gen_code();
	if (t)
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", tigger_dst.str().c_str());
		return 0;
	}
	else if (v)
	{
		auto out_f = fopen("tigger.out", "w");
		fprintf(out_f, "%s", tigger_dst.str().c_str());
		fflush(out_f);
	}
	// generate risc-v code
	riscv::gen_code();
	if (!(e || t))
	{
		auto out_f = fopen(output_s.c_str(), "w");
		fprintf(out_f, "%s", riscv_dst.str().c_str());
		return 0;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
xorl %r14d, %r14d
testl %edi, %edi
jle 0x165e2
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x11f9c(%rip), %r15     # 0x2848e
leaq 0x1ede7(%rip), %r13     # 0x352e0
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x20(%rsp)
movslq %r14d, %rcx
movq (%rbx,%rcx,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x1654e
movzbl 0x1(%rdi), %eax
cmpl $0x6e, %eax
jle 0x16564
cmpl $0x6f, %eax
je 0x1658d
cmpl $0x74, %eax
je 0x1657b
cmpl $0x76, %eax
jne 0x166a6
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0x1655a
movq %r15, %rsi
callq 0x52d0
movq %rax, (%r13)
incl %r14d
cmpl %ebp, %r14d
jl 0x1651d
jmp 0x165c7
cmpl $0x53, %eax
je 0x16584
cmpl $0x65, %eax
jne 0x166a6
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x1655a
movb $0x1, %al
movq %rax, 0x38(%rsp)
jmp 0x1655a
movb $0x1, %al
movq %rax, 0x28(%rsp)
jmp 0x1655a
movq 0x8(%rbx,%rcx,8), %r12
testq %r12, %r12
je 0x166b6
movq 0x8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %r12, %rdi
callq 0x5110
movq %rsp, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x53f0
incl %r14d
jmp 0x1655a
movq 0x20(%rsp), %r14
leaq 0x10(%rsp), %r15
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %rax
jmp 0x165ea
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %eax, %eax
testb $0x1, %al
je 0x16601
movl %r13d, %eax
andb %r12b, %al
testb $0x1, %al
je 0x16636
leaq 0x129d5(%rip), %rdi     # 0x28fd4
jmp 0x16608
leaq 0x129a6(%rip), %rdi     # 0x28fae
callq 0x53e0
xorl %ebx, %ebx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x16625
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5240
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1eca3(%rip), %rbx     # 0x352e0
cmpq $0x0, (%rbx)
je 0x1669a
callq 0x134cb
callq 0x5e72
movq (%rbx), %rdi
callq 0x5400
testl %eax, %eax
je 0x16648
callq 0x15137
movl $0x1, %ebx
cmpb $0x0, 0x1ed86(%rip)     # 0x353f0
jne 0x1660f
testb $0x1, %r13b
je 0x166d0
movq (%rsp), %rdi
leaq 0x11f6c(%rip), %rsi     # 0x285e9
callq 0x52d0
movq 0x1ed5f(%rip), %rcx     # 0x353e8
movq 0x18(%rcx), %rdi
movq %rax, %rsi
callq 0x5280
jmp 0x1660d
leaq 0x1291e(%rip), %rdi     # 0x28fbf
jmp 0x16608
leaq 0x128ea(%rip), %rdi     # 0x28f97
callq 0x53e0
xorl %ebx, %ebx
jmp 0x166c6
leaq 0x128ab(%rip), %rdi     # 0x28f68
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5050
leaq 0x10(%rsp), %r15
jmp 0x1660f
testb $0x1, %r14b
je 0x16707
leaq 0x128a4(%rip), %rdi     # 0x28f81
leaq 0x11f05(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
movq 0x1ecf5(%rip), %rax     # 0x353e8
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x5280
movq %rbx, %rdi
callq 0x52c0
movq 0x1ecda(%rip), %rdi     # 0x353e8
addq $0x18, %rdi
callq 0x168cc
callq 0x1eee0
testb $0x1, %r12b
je 0x1674b
movq (%rsp), %rdi
leaq 0x11ebc(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1ecc4(%rip), %rsi     # 0x35400
leaq 0x40(%rsp), %rdi
callq 0x5430
jmp 0x167d0
testb $0x1, %r14b
je 0x167a7
leaq 0x12834(%rip), %rdi     # 0x28f8c
leaq 0x11e8a(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1ec92(%rip), %rsi     # 0x35400
leaq 0x40(%rsp), %rdi
callq 0x5430
leaq 0x50(%rsp), %r14
movq -0x10(%r14), %rdi
movq %rbx, %rsi
callq 0x5280
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1679f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5240
movq %rbx, %rdi
callq 0x52c0
callq 0x23714
movq (%rsp), %rdi
leaq 0x11e32(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1edb2(%rip), %rsi     # 0x35578
leaq 0x40(%rsp), %rdi
callq 0x5430
leaq 0x50(%rsp), %r14
movq -0x10(%r14), %rdi
movq %rbx, %rsi
callq 0x5280
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1660d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x1660d
jmp 0x1680a
jmp 0x1680a
jmp 0x1680a
jmp 0x1680a
jmp 0x1680a
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x16828
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5240
movq %rbx, %rdi
callq 0x54c0