// File: /workspace/github_cpp_makefile_star2_O3/KJTang[P]SimpleCompiler/Parser.cpp
// Function: Parser::parseFuncDeclaration()
ASTNode *Parser::parseFuncDeclaration() {
    #ifdef DEBUG
    std::cout<<curToken.second<<"\tparseFuncDeclaration"<<std::endl;
    #endif
    Token type = curToken.first;
    getNextToken(); // eat function return value type
    std::string name = curToken.second;
    getNextToken(); // eat function name
    std::vector<std::pair<Token, std::string>> args;
    // if function has argument
    if (lookAheadToken(1).first != static_cast<Token>(')')) {
        do {
            getNextToken(); // eat '(' or ','
            Token varType = curToken.first;
            getNextToken(); // eat type name
            std::string varName = curToken.second;
            getNextToken(); // eat arg name
            args.push_back(std::make_pair(varType, varName));
        } while (curToken.first != static_cast<Token>(')'));
    }
    // else function has no argument
    else {
        getNextToken(); // eat '('
    }
    getNextToken(); // eat ')'
    ASTNode *block = this->parseBlock();
    return new FunctionAST(std::make_pair(type, name), args, block);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movl 0x58(%rdi), %r15d
movslq 0x80(%rdi), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rdi)
movq (%rdi), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rdi)
leaq 0x60(%rdi), %r14
movq %r14, %rdi
callq 0x3130
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x42b0
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
movl %r15d, -0x2c(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movslq 0x80(%rbx), %rcx
movq (%rbx), %rax
leaq (%rcx,%rcx,4), %rdx
cmpl $0x29, (%rax,%rdx,8)
jne 0xa69b
incl %ecx
movl %ecx, 0x80(%rbx)
movl $0x29, 0x58(%rbx)
leaq (%rax,%rdx,8), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x3130
jmp 0xa79e
leaq -0xa0(%rbp), %r12
leaq -0x40(%rbp), %r13
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
movl 0x58(%rbx), %r15d
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
movq %r12, -0xb0(%rbp)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x42b0
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
movl %r15d, -0x58(%rbp)
movq %r13, -0x50(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x42b0
leaq -0x70(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x5a16
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xa783
callq 0x31c0
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0xa794
callq 0x31c0
cmpl $0x29, 0x58(%rbx)
jne 0xa6a6
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
movq %rbx, %rdi
callq 0xa488
movq %rax, %rbx
movl $0x58, %edi
callq 0x31e0
movq %rax, %r14
leaq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %eax
movl %eax, -0x8(%rdi)
leaq -0x40(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
callq 0x42b0
leaq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0xad64
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0xa829
callq 0x31c0
leaq -0x70(%rbp), %rdi
callq 0x39cc
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa847
callq 0x31c0
movq %r14, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0xa872
callq 0x31c0
jmp 0xa872
movq %rax, %rbx
movq %r14, %rdi
jmp 0xa8ad
movq %rax, %rbx
jmp 0xa8bb
jmp 0xa884
jmp 0xa884
jmp 0xa884
jmp 0xa884
movq %rax, %rbx
jmp 0xa8b2
jmp 0xa88b
movq %rax, %rbx
jmp 0xa8a1
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xa8a1
callq 0x31c0
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0xa8b2
callq 0x31c0
leaq -0x70(%rbp), %rdi
callq 0x39cc
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa8d0
callq 0x31c0
movq %rbx, %rdi
callq 0x3330