// File: /workspace/github_cpp_makefile_star2_O3/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 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
testl %edi, %edi
jle 0x1681c
movq %rsi, %rbx
movl %edi, %ebp
movq $0x0, 0x38(%rsp)
leaq 0x11d86(%rip), %r15     # 0x2848e
leaq 0x1ebd1(%rip), %r13     # 0x352e0
movq $0x0, 0x10(%rsp)
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movslq %r14d, %rax
movq (%rbx,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x16787
movzbl 0x1(%rdi), %ecx
cmpl $0x73, %ecx
jg 0x1679d
cmpl $0x65, %ecx
je 0x167b3
cmpl $0x6f, %ecx
jne 0x167c5
movq 0x8(%rbx,%rax,8), %r12
testq %r12, %r12
je 0x168df
movq 0x20(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %r12, %rdi
callq 0x5110
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x53f0
incl %r14d
jmp 0x16793
movq %r15, %rsi
callq 0x52d0
movq %rax, (%r13)
incl %r14d
cmpl %ebp, %r14d
jl 0x1672c
jmp 0x167f3
cmpl $0x76, %ecx
je 0x167bc
cmpl $0x74, %ecx
jne 0x16856
movb $0x1, %al
movq %rax, (%rsp)
jmp 0x16793
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x16793
movb $0x1, %al
movq %rax, 0x8(%rsp)
jmp 0x16793
cmpl $0x53, %ecx
jne 0x16856
incl %r14d
movb $0x1, %al
movq %rax, 0x38(%rsp)
cmpl %ebp, %r14d
jl 0x1672c
testb $0x1, 0x10(%rsp)
je 0x16a2d
leaq 0x28(%rsp), %r15
jmp 0x16806
testb $0x1, 0x38(%rsp)
leaq 0x28(%rsp), %r15
je 0x1681c
testb $0x1, 0x10(%rsp)
je 0x16852
xorl %ebx, %ebx
testb $0x1, (%rsp)
je 0x16869
leaq 0x127ef(%rip), %rdi     # 0x29004
callq 0x53e0
jmp 0x1682a
leaq 0x127bb(%rip), %rdi     # 0x28fde
callq 0x53e0
xorl %ebx, %ebx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x16841
movq 0x28(%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
xorl %ebp, %ebp
jmp 0x16874
leaq 0x1276a(%rip), %rdi     # 0x28fc7
callq 0x53e0
xorl %ebx, %ebx
jmp 0x168ef
movb $0x1, %bpl
movq $0x0, (%rsp)
cmpq $0x0, (%r13)
je 0x168d3
callq 0x1379f
callq 0x5e62
movq (%r13), %rdi
callq 0x5400
testl %eax, %eax
je 0x16880
callq 0x1537a
movl $0x1, %ebx
cmpb $0x0, 0x1eb4d(%rip)     # 0x353f0
jne 0x1682a
testb %bpl, %bpl
je 0x168f9
movq 0x18(%rsp), %rdi
leaq 0x11d33(%rip), %rsi     # 0x285e9
callq 0x52d0
movq 0x1eb26(%rip), %rcx     # 0x353e8
movq 0x18(%rcx), %rdi
movq %rax, %rsi
callq 0x5280
jmp 0x16828
leaq 0x12715(%rip), %rdi     # 0x28fef
jmp 0x16823
leaq 0x126b2(%rip), %rdi     # 0x28f98
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5050
leaq 0x28(%rsp), %r15
jmp 0x1682a
testb $0x1, 0x8(%rsp)
je 0x16931
leaq 0x126aa(%rip), %rdi     # 0x28fb1
leaq 0x11cdb(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
movq 0x1eacb(%rip), %rax     # 0x353e8
movq 0x18(%rax), %rdi
movq %rbx, %rsi
callq 0x5280
movq %rbx, %rdi
callq 0x52c0
movq 0x1eab0(%rip), %rdi     # 0x353e8
addq $0x18, %rdi
callq 0x16b08
callq 0x1ee54
testb $0x1, (%rsp)
je 0x16976
movq 0x18(%rsp), %rdi
leaq 0x11c91(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1ea99(%rip), %rsi     # 0x35400
leaq 0x40(%rsp), %rdi
callq 0x5430
jmp 0x169fd
testb $0x1, 0x8(%rsp)
je 0x169d3
leaq 0x12638(%rip), %rdi     # 0x28fbc
leaq 0x11c5e(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1ea66(%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 0x169cb
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5240
movq %rbx, %rdi
callq 0x52c0
callq 0x236a4
movq 0x18(%rsp), %rdi
leaq 0x11c05(%rip), %rsi     # 0x285e9
callq 0x52d0
movq %rax, %rbx
leaq 0x1eb85(%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 0x16828
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5240
jmp 0x16828
xorl %ebp, %ebp
leaq 0x28(%rsp), %r15
jmp 0x16874
jmp 0x16a43
jmp 0x16a43
jmp 0x16a43
jmp 0x16a43
jmp 0x16a43
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16a62
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x5240
movq %rbx, %rdi
callq 0x54c0
nop