// File: KJTang[P]SimpleCompiler/Parser.cpp
// Function: Parser::parseVarDeclaration()
ASTNode *Parser::parseVarDeclaration() {
    #ifdef DEBUG
    std::cout<<curToken.second<<"\tparseVarDeclaration"<<std::endl;
    #endif
    Token type = curToken.first;
    getNextToken(); // eat type name
    std::vector<ASTNode*> varList;
    while (true) {
        ASTNode *var = this->parseIdentifier();
        if (curToken.first == static_cast<Token>(',')) {
            getNextToken();
            varList.push_back(new BinaryExprAST('=', var, new NumberAST("0")));
        } else if (curToken.first == static_cast<Token>('=')) {
            getNextToken();
            ASTNode *expr = this->parseExpression();
            varList.push_back(new BinaryExprAST('=', var, expr));
            if (lookAheadToken(-1).first == static_cast<Token>(';')) {
                break;
            }
        } else if (curToken.first == static_cast<Token>(';')) {
            getNextToken();
            varList.push_back(new BinaryExprAST('=', var, new NumberAST("0")));
            break;
        }
    }
    return new AssignmentAST(type, varList);   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
movl 0x58(%rdi), %eax
movl %eax, -0xc(%rbp)
callq 0x10070
leaq -0x28(%rbp), %rdi
callq 0x5680
jmp 0xfc20
movq -0xb8(%rbp), %rdi
callq 0xf6f0
movq %rax, -0xc0(%rbp)
jmp 0xfc35
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, -0x30(%rbp)
cmpl $0x2c, 0x58(%rax)
jne 0xfda7
movq -0xb8(%rbp), %rdi
callq 0x10070
jmp 0xfc5f
movl $0x20, %edi
callq 0x3290
movq %rax, -0xc8(%rbp)
jmp 0xfc72
movb $0x1, -0x6b(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x30, %edi
callq 0x3290
movq %rax, -0xd0(%rbp)
jmp 0xfc94
movb $0x1, -0x6a(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x3480
movq -0xe0(%rbp), %rdx
leaq 0xb7bc(%rip), %rsi      # 0x1b472
leaq -0x68(%rbp), %rdi
callq 0x3390
jmp 0xfcc1
movq -0xd0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x10130
jmp 0xfcd3
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %rdx
movq -0xc8(%rbp), %rdi
movb $0x0, -0x6a(%rbp)
movl $0x3d, %esi
callq 0x103e0
jmp 0xfcf8
movq -0xc8(%rbp), %rax
movb $0x0, -0x6b(%rbp)
movq %rax, -0x48(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x10630
jmp 0xfd16
leaq -0x68(%rbp), %rdi
callq 0x34f8
leaq -0x69(%rbp), %rdi
callq 0x3300
jmp 0xfffc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1005a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xfd8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xfd6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x34f8
leaq -0x69(%rbp), %rdi
callq 0x3300
testb $0x1, -0x6a(%rbp)
jne 0xfd80
jmp 0xfd8c
movq -0xd0(%rbp), %rdi
callq 0x3270
jmp 0xfd8e
testb $0x1, -0x6b(%rbp)
jne 0xfd96
jmp 0xfda2
movq -0xc8(%rbp), %rdi
callq 0x3270
jmp 0x1005a
movq -0xb8(%rbp), %rax
cmpl $0x3d, 0x58(%rax)
jne 0xfe7b
movq -0xb8(%rbp), %rdi
callq 0x10070
jmp 0xfdc6
movq -0xb8(%rbp), %rdi
callq 0xf100
movq %rax, -0xe8(%rbp)
jmp 0xfddb
movq -0xe8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0x20, %edi
callq 0x3290
movq %rax, -0xf0(%rbp)
jmp 0xfdf9
movq -0xf0(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl $0x3d, %esi
callq 0x103e0
jmp 0xfe14
movq -0xf0(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x10630
jmp 0xfe2e
movq -0xb8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x10600
movq %rax, -0xf8(%rbp)
jmp 0xfe48
movq -0xf8(%rbp), %rax
cmpl $0x3b, (%rax)
jne 0xfe76
jmp 0x10001
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x3270
jmp 0x1005a
jmp 0xfffa
movq -0xb8(%rbp), %rax
cmpl $0x3b, 0x58(%rax)
jne 0xfff8
movq -0xb8(%rbp), %rdi
callq 0x10070
jmp 0xfe9a
movl $0x20, %edi
callq 0x3290
movq %rax, -0x100(%rbp)
jmp 0xfead
movb $0x1, -0xab(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
movl $0x30, %edi
callq 0x3290
movq %rax, -0x108(%rbp)
jmp 0xfed2
movb $0x1, -0xaa(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3480
movq -0x118(%rbp), %rdx
leaq 0xb578(%rip), %rsi      # 0x1b472
leaq -0xa8(%rbp), %rdi
callq 0x3390
jmp 0xff08
movq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x10130
jmp 0xff1d
movq -0x108(%rbp), %rcx
movq -0x110(%rbp), %rdx
movq -0x100(%rbp), %rdi
movb $0x0, -0xaa(%rbp)
movl $0x3d, %esi
callq 0x103e0
jmp 0xff45
movq -0x100(%rbp), %rax
movb $0x0, -0xab(%rbp)
movq %rax, -0x88(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x10630
jmp 0xff6c
leaq -0xa8(%rbp), %rdi
callq 0x34f8
leaq -0xa9(%rbp), %rdi
callq 0x3300
jmp 0x10001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xffdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xffba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x34f8
leaq -0xa9(%rbp), %rdi
callq 0x3300
testb $0x1, -0xaa(%rbp)
jne 0xffd1
jmp 0xffdd
movq -0x108(%rbp), %rdi
callq 0x3270
jmp 0xffdf
testb $0x1, -0xab(%rbp)
jne 0xffea
jmp 0xfff6
movq -0x100(%rbp), %rdi
callq 0x3270
jmp 0x1005a
jmp 0xfffa
jmp 0xfffc
jmp 0xfc1e
movl $0x28, %edi
callq 0x3290
movq %rax, -0x120(%rbp)
jmp 0x10014
movq -0x120(%rbp), %rdi
movl -0xc(%rbp), %esi
leaq -0x28(%rbp), %rdx
callq 0x10660
jmp 0x10029
leaq -0x28(%rbp), %rdi
callq 0x57e0
movq -0x120(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x3270
leaq -0x28(%rbp), %rdi
callq 0x57e0
movq -0x38(%rbp), %rdi
callq 0x3470
nopl (%rax)