// File: /workspace/github_cpp_makefile_star2_O1/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 0x42ce
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), %rax
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rdx
cmpl $0x29, (%rcx,%rdx,8)
jne 0xa6d6
incl %eax
movl %eax, 0x80(%rbx)
leaq (%rcx,%rdx,8), %rsi
addq $0x8, %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r14, %rdi
callq 0x3130
jmp 0xa7d9
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 0x42ce
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 0x42ce
leaq -0x70(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x599a
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xa7be
callq 0x31c0
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0xa7cf
callq 0x31c0
cmpl $0x29, 0x58(%rbx)
jne 0xa6e1
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 0xa4c4
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 0x42ce
leaq -0x58(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0xada0
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0xa864
callq 0x31c0
leaq -0x70(%rbp), %rdi
callq 0x39cc
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa882
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 0xa8ad
callq 0x31c0
jmp 0xa8ad
movq %rax, %rbx
movq %r14, %rdi
jmp 0xa8e8
movq %rax, %rbx
jmp 0xa8f6
jmp 0xa8bf
jmp 0xa8bf
jmp 0xa8bf
jmp 0xa8bf
movq %rax, %rbx
jmp 0xa8ed
jmp 0xa8c6
movq %rax, %rbx
jmp 0xa8dc
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0xa8dc
callq 0x31c0
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0xa8ed
callq 0x31c0
leaq -0x70(%rbp), %rdi
callq 0x39cc
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xa90b
callq 0x31c0
movq %rbx, %rdi
callq 0x3330
nop