// File: /workspace/github_cpp_makefile_star2_O2/waltersharpWEI[P]CommentEliminator/main.cpp
// Function: removeComment(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void removeComment(string FilePath) {
    //FILE handle of the input file, read-only
    FILE * Input = fopen(FilePath.c_str(),"r");
    //If fail to open the file, show the message and leave funtion
    if (Input == NULL) {
        cout << "Can not open this file, path:"  << FilePath << "\n";
        return ;
    }
    //This Buffer is used to store the content of entire output file
    //Initialized as empty string
    string Buffer = "";
    //Previous is the last character readed
    //Now is the current character from input file
    char Previous = 0,Now = 0,PoP = 0;
    //0 for code, 1 for string, 2 for one line comment, 3 for multiline comment
    //The
    int Status = 0;
    int es = 0;
    //keep read the input stream until End of File
    //one character each time
    while (fscanf(Input, "%c",&Now) != EOF) {
        switch (Status) {
            //if cursor is in the normal code area
            case 0:{
                if (Previous == '/') {
                    if (Now == '/') {
                        Status = 2;
                    } else if (Now == '*') {
                        Status = 3;
                    } else {
                        Buffer += Previous;
                        Buffer += Now;
                    }
                } else if (Now != '/') {
                    Buffer += Now;
                    if (Previous != '\\' && Previous != '\'' && Now == '"') {
                        Status = 1;
                    }
                }
            }break;
            //if cursor is in a string
            case 1:{
                //if there is a single \ to continue the line, just put it into Buffer,
                //together with the \r or \n in Now
                if (Previous == '\\') {
                    if (es != 1) {
                        Buffer += Previous;
                        Buffer += Now;
                        es = 0;
                    } else {
                        Buffer += Now;
                        if (Now == '"') {
                            Status = 0;
                        }
                        es = 0;
                    }
                    if (Now == '\\') {
                        es = 1;
                    }
                //otherwise just add Now to Buffer
                } else if (Now != '\\') {
                    Buffer += Now;
                    if (Now == '"') {
                        Status = 0;

                    }
                }
            }break;
            //if cursor is in a single line comment
            case 2:{
                //if there is no single \ to continue the line, then stop single lien comment, add /n into Buffer
                if (Previous != '\\' && (Now == '\n' || Now == '\r')) {
                    Buffer += Now;
                    Now = 0;
                    Status = 0;
                }
            }break;
            //if cursor is in a multiple line comment
            case 3:{
                if (Previous == '*' && Now == '/') {
                    Status = 0;
                    Now = 0;
                }
            }break;
            default: {

            }break;
        }
        //update the Previous character, move forward to next character
        PoP = Previous;
        Previous = Now;
    }
    //close the input file
    fclose(Input);
    //open the input file in write mode
    ofstream fout(FilePath.c_str());
    //write the Buffer content into the file
    fout << Buffer;
    //close the file
    fout.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rdi, %rbx
movq (%rdi), %rdi
leaq 0x2b47(%rip), %rsi      # 0x5014
callq 0x21e0
testq %rax, %rax
je 0x26c8
movq %rax, %r14
movq %rbx, -0x58(%rbp)
leaq 0x2d39(%rip), %rsi      # 0x5222
leaq -0x50(%rbp), %rdi
leaq -0x258(%rbp), %rdx
callq 0x32d0
leaq -0x29(%rbp), %rax
movb $0x0, (%rax)
xorl %r12d, %r12d
leaq 0x2afa(%rip), %rbx      # 0x5004
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r14, %rdi
leaq 0x2b1a(%rip), %rsi      # 0x5034
leaq -0x29(%rbp), %rdx
xorl %eax, %eax
callq 0x2310
cmpl $-0x1, %eax
je 0x2667
movl %r13d, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movzbl -0x29(%rbp), %eax
cmpb $0x2f, %r12b
jne 0x25e4
cmpl $0x2f, %eax
je 0x25dc
cmpl $0x2a, %eax
je 0x25e0
leaq -0x50(%rbp), %rdi
pushq $0x2f
popq %rsi
callq 0x2120
xorl %r13d, %r13d
movsbl -0x29(%rbp), %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
jmp 0x265e
cmpb $0x5c, %r12b
je 0x25dc
movzbl -0x29(%rbp), %eax
cmpl $0xd, %eax
je 0x258f
cmpl $0xa, %eax
jne 0x25dc
movsbl %al, %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
jmp 0x25a9
cmpb $0x2a, %r12b
jne 0x25e0
cmpb $0x2f, -0x29(%rbp)
jne 0x25e0
movb $0x0, -0x29(%rbp)
xorl %r13d, %r13d
jmp 0x265e
cmpb $0x5c, %r12b
jne 0x260f
cmpl $0x1, %r15d
jne 0x261c
movsbl -0x29(%rbp), %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
movb -0x29(%rbp), %al
xorl %r13d, %r13d
cmpb $0x22, %al
setne %r13b
jmp 0x263c
pushq $0x2
jmp 0x2618
pushq $0x3
jmp 0x2618
xorl %r13d, %r13d
cmpl $0x2f, %eax
je 0x265e
movsbl %al, %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
cmpb $0x22, -0x29(%rbp)
jne 0x265e
cmpb $0x27, %r12b
je 0x265e
movzbl %r12b, %eax
cmpl $0x5c, %eax
je 0x265e
jmp 0x2616
movb -0x29(%rbp), %al
cmpb $0x5c, %al
jne 0x2647
pushq $0x1
popq %r13
jmp 0x265e
leaq -0x50(%rbp), %rdi
pushq $0x5c
popq %rsi
callq 0x2120
movsbl -0x29(%rbp), %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
movb -0x29(%rbp), %al
pushq $0x1
popq %r13
xorl %r15d, %r15d
cmpb $0x5c, %al
sete %r15b
jmp 0x265e
movsbl %al, %esi
leaq -0x50(%rbp), %rdi
callq 0x2120
xorl %r13d, %r13d
cmpb $0x22, -0x29(%rbp)
setne %r13b
movb -0x29(%rbp), %r12b
jmp 0x2510
movq %r14, %rdi
callq 0x21a0
movq -0x58(%rbp), %rax
movq (%rax), %rsi
leaq -0x258(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x21d0
leaq -0x258(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2140
leaq -0x258(%rbp), %rdi
callq 0x2230
leaq -0x258(%rbp), %rdi
callq 0x2260
leaq -0x50(%rbp), %rdi
callq 0x20a0
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58f9(%rip), %rdi      # 0x7fc8
leaq 0x2940(%rip), %rsi      # 0x5016
callq 0x2190
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2140
leaq 0x2b34(%rip), %rsi      # 0x5221
movq %rax, %rdi
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2190
jmp 0x2719
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x2260
jmp 0x271c
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x22e0