// File: /workspace/github_cpp_makefile_star2_O2/DuoLife-QNL[P]lexical_analysis/main.cpp
// Function: main
int main(int a, char** b){
    argc = a;
    argv = b;
    keyword k;
    operators o;
    delimiter de;
    strings s;
    characters c;
    error e;
    id i;

    if (argc > 1){
        if(!(yyin = fopen(argv[1], "r"))){
            perror(argv[1]);
            return 1;
        }
        if (argc == 2){
            cout << left << setw(30) << "TOKEN_TYPE" << left << setw(30) << "CONTENT" << endl << endl;
        }else if (argc ==3){
            outfile.open(argv[2]);
            outfile << left << setw(30) << "TOKEN_TYPE" << left << setw(30) << "CONTENT" << endl << endl;
        }
    }else{
        cout << "Please input the token" << endl;        
    }

    int d = yylex();
    while(d){
        if (d == KEYWORD){
            k.detected(yytext);
            ch_cnt += yyleng;
        }else if(d == RELOP){
            o.detected(yytext);
            ch_cnt += yyleng;
        }else if(d == DELIMITER){
            de.detected(yytext);
            ch_cnt += yyleng;
        }else if (d == IDENTIFIER){
            ch_cnt += yyleng;
        }else if(d == STRINGS){
            s.display(yytext);
            ch_cnt += yyleng;
        }else if (d == CHARACTERS){
            c.display(yytext);
            ch_cnt += yyleng;
        }else if(d == NUM){
            ch_cnt += yyleng;
        }else if(d == ERROR){
            e.display(yytext, yylineno);
        }
        else{
            ;
        }
        d = yylex();
    }

    if(argc == 2){
        cout << endl << endl << "STATISTICS" << endl << endl;

        cout << left << setw(30) << "ITEM" << left << setw(30) << "COUNT" << endl;
        cout << left << setw(30) << "Identifier" << left << setw(30) << id::id_cnt << endl;
        cout << left << setw(30) << "Number" << left << setw(30) << num::num_cnt << endl;
        cout << left << setw(30) << "Operator" << left << setw(30) << operators::opr_cnt << endl;
        cout << left << setw(30) << "Delimiter" << left << setw(30) << delimiter::dlmt_cnt << endl;
        cout << left << setw(30) << "Keyword" << left << setw(30) << keyword::kw_cnt << endl;
        cout << left << setw(30) << "Line" << left << setw(30) << line::count << endl;
        cout << left << setw(30) << "Total character number" << left << setw(30) << ch_cnt << endl;
    }else if(argc == 3){
        outfile << endl << endl << "STATISTICS" << endl << endl;

        outfile << left << setw(30) << "ITEM" << left << setw(30) << "COUNT" << endl;
        outfile << left << setw(30) << "Identifier" << left << setw(30) << id::id_cnt << endl;
        outfile << left << setw(30) << "Number" << left << setw(30) << num::num_cnt << endl;
        outfile << left << setw(30) << "Operator" << left << setw(30) << operators::opr_cnt << endl;
        outfile << left << setw(30) << "Delimiter" << left << setw(30) << delimiter::dlmt_cnt << endl;
        outfile << left << setw(30) << "Keyword" << left << setw(30) << keyword::kw_cnt << endl;
        outfile << left << setw(30) << "Line" << left << setw(30) << line::count << endl;
        outfile << left << setw(30) << "Total character number" << left << setw(30) << ch_cnt << endl;  

    }
    i.disp_tbl();

    outfile.close();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, 0x7c9c(%rip)      # 0xa1bc
movq %rsi, 0x7c99(%rip)      # 0xa1c0
pushq $0x1e
popq %r15
cmpl $0x2, %edi
jl 0x25b7
movq 0x8(%rsi), %rdi
leaq 0x5302(%rip), %rsi      # 0x7841
callq 0x21d0
leaq 0x7e8d(%rip), %rcx      # 0xa3d8
movq %rax, (%rcx)
testq %rax, %rax
je 0x2abb
movl 0x7c5f(%rip), %eax      # 0xa1bc
cmpl $0x3, %eax
je 0x25cf
cmpl $0x2, %eax
jne 0x2660
movq 0x7a56(%rip), %rdi      # 0x9fc8
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movl $0xffffff4f, %ebx       # imm = 0xFFFFFF4F
movl 0x18(%rdi,%rcx), %edx
andl %ebx, %edx
orl $0x20, %edx
movl %edx, 0x18(%rdi,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rdi,%rax)
leaq 0x3a69(%rip), %rsi      # 0x6004
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
andl 0x18(%rax,%rdx), %ebx
orl $0x20, %ebx
movl %ebx, 0x18(%rax,%rdx)
jmp 0x2638
movq 0x7a0a(%rip), %rdi      # 0x9fc8
leaq 0x3a52(%rip), %rsi      # 0x6017
callq 0x2170
jmp 0x2658
movq 0x7bea(%rip), %rax      # 0xa1c0
movq 0x10(%rax), %rsi
leaq 0x7be7(%rip), %rbx      # 0xa1c8
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2050
movq 0x7bd5(%rip), %rax      # 0xa1c8
movq -0x18(%rax), %rcx
movl $0xffffff4f, %r14d      # imm = 0xFFFFFF4F
movl 0x18(%rcx,%rbx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rcx,%rbx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rax,%rbx)
leaq 0x39e9(%rip), %rsi      # 0x6004
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
andl 0x18(%rax,%rdx), %r14d
orl $0x20, %r14d
movl %r14d, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x39c7(%rip), %rsi      # 0x600f
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
callq 0x2ad0
leaq 0x7d84(%rip), %r14      # 0xa3f0
leaq 0x7d5d(%rip), %r15      # 0xa3d0
leaq -0x2b(%rbp), %r13
leaq 0x7b1a(%rip), %r12      # 0xa198
leaq -0x2a(%rbp), %rbx
cmpl $0x23, %eax
je 0x26fa
cmpl $0x27, %eax
je 0x26cd
cmpl $0x4f, %eax
je 0x26ec
cmpl $0x5f, %eax
je 0x2706
cmpl $0x60, %eax
je 0x2706
cmpl $0x6e, %eax
je 0x26bf
cmpl $0x6f, %eax
je 0x26b2
cmpl $0xc7, %eax
je 0x26db
testl %eax, %eax
jne 0x270f
jmp 0x2719
movq (%r14), %rsi
movq %r13, %rdi
callq 0x4876
jmp 0x2706
movq (%r14), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x478a
jmp 0x2706
movq (%r14), %rsi
leaq -0x2e(%rbp), %rdi
callq 0x44c8
jmp 0x2706
movq (%r14), %rsi
movl (%r12), %edx
movq %rbx, %rdi
callq 0x4962
jmp 0x270f
movq (%r14), %rsi
leaq -0x2d(%rbp), %rdi
callq 0x45e8
jmp 0x2706
movq (%r14), %rsi
leaq -0x2f(%rbp), %rdi
callq 0x4708
movl (%r15), %eax
addl %eax, 0x7cb9(%rip)      # 0xa3c8
callq 0x2ad0
jmp 0x2682
movl 0x7a9d(%rip), %eax      # 0xa1bc
cmpl $0x2, %eax
je 0x273a
cmpl $0x3, %eax
pushq $0x1e
popq %r15
jne 0x2a95
leaq 0x7a90(%rip), %rbx      # 0xa1c8
jmp 0x2745
movq 0x7887(%rip), %rbx      # 0x9fc8
pushq $0x1e
popq %r15
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
leaq 0x38d2(%rip), %rsi      # 0x602e
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0xffffff4f, %r14d      # imm = 0xFFFFFF4F
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x389a(%rip), %rsi      # 0x6039
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x3872(%rip), %rsi      # 0x603e
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x3843(%rip), %rsi      # 0x6044
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x7c1a(%rip), %rcx      # 0xa448
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x37ea(%rip), %rsi      # 0x604f
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x7bee(%rip), %rcx      # 0xa480
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x378d(%rip), %rsi      # 0x6056
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x7b8e(%rip), %rcx      # 0xa484
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x3732(%rip), %rsi      # 0x605f
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x7b2e(%rip), %rcx      # 0xa488
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x36d8(%rip), %rsi      # 0x6069
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x7ace(%rip), %rcx      # 0xa48c
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x367c(%rip), %rsi      # 0x6071
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl %r14d, %esi
orl $0x20, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
leaq 0x777e(%rip), %rcx      # 0xa1a0
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl %r14d, %edx
orl $0x20, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
movq %r15, 0x10(%rbx,%rax)
leaq 0x361d(%rip), %rsi      # 0x6076
movq %rbx, %rdi
callq 0x2170
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
andl 0x18(%rax,%rdx), %r14d
orl $0x20, %r14d
movl %r14d, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq %r15, 0x10(%rax,%rcx)
movl 0x7943(%rip), %esi      # 0xa3c8
movq %rax, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x20e0
leaq -0x29(%rbp), %rdi
callq 0x414c
leaq 0x7723(%rip), %rdi      # 0xa1c8
callq 0x2220
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x76fe(%rip), %rax      # 0xa1c0
movq 0x8(%rax), %rdi
callq 0x2140
pushq $0x1
popq %rax
jmp 0x2aac