// File: princelab[P]emass/parser.cpp
// Function: Parser::parse()
Parser::ElementListNode * Parser::parse()
{
  Parser::ElementListNode * inner;
  Parser::ElementListNode * outer = new Parser::ElementListNode();
  while(_tokenizer._ttype == LPAREN ||
	_tokenizer._ttype == ELEMENT) {
    if(_tokenizer._ttype == LPAREN) {
      try {
	_tokenizer.get_token();
      } catch (Parser::Error e) {
	delete outer;
	throw e;
      }
      inner = parse();
      if(_tokenizer._ttype != RPAREN) {
	delete outer;
	delete inner;
	_tokenizer.error(L"Expected right parenthesis");
      }
    } else {
      ElemMap::const_iterator i = _elements.find(_tokenizer._tval);
      if(i != _elements.end())
	inner = new ElementListNode((*i).second);
      else {
	delete outer;
	_tokenizer.error(L"\'" + _tokenizer._tval + L"\' is not an element");
      }
    }
    _tokenizer.get_token();
    if(_tokenizer._ttype == NUM) {
      inner->set_count(wcstol(_tokenizer._tval.c_str(), NULL, 0));
      _tokenizer.get_token();
    }
    outer->append(inner);
  }
  return outer;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x28, %edi
callq 0x4390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
callq 0xd770
jmp 0xcbc8
movq -0xc8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0xd0(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x8(%rcx)
movb %al, -0xd1(%rbp)
je 0xcbfc
movq -0xd0(%rbp), %rax
cmpl $0x4, 0x8(%rax)
sete %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0xcc0b
jmp 0xd006
movq -0xd0(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xce0d
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0xc770
jmp 0xcc2e
jmp 0xcd16
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x43b0
jmp 0xd013
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xd013
movq -0x20(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x44a0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x6ca0
jmp 0xcc8f
movq -0xe0(%rbp), %rdi
callq 0x4110
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, %rax
je 0xccb9
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x20, %edi
callq 0x4180
movq %rax, %rdi
movq %rdi, -0xf0(%rbp)
leaq -0x48(%rbp), %rsi
callq 0xd7c0
movq -0xf0(%rbp), %rdi
leaq 0xdfdc(%rip), %rsi      # 0x1acc0
leaq -0x600b(%rip), %rdx     # 0x6ce0
callq 0x45e0
jmp 0xd024
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6ce0
callq 0x45a0
jmp 0xcd11
jmp 0xd013
movq -0xd0(%rbp), %rdi
callq 0xcb90
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x10(%rbp)
cmpl $0x1, 0x8(%rax)
je 0xce08
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0xcd58
movq -0xf8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
je 0xcd76
movq -0x100(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0xd0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x110(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x4150
movq -0x108(%rbp), %rdx
leaq 0x547a(%rip), %rsi      # 0x12220
leaq -0x68(%rbp), %rdi
callq 0xd6c0
jmp 0xcdb1
movq -0x110(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xd030
jmp 0xcdc3
leaq -0x68(%rbp), %rdi
callq 0x4738
leaq -0x69(%rbp), %rdi
callq 0x4640
jmp 0xce08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xcdfa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4738
leaq -0x69(%rbp), %rdi
callq 0x4640
jmp 0xd013
jmp 0xcf8b
movq -0xd0(%rbp), %rsi
movq (%rsi), %rdi
addq $0x8, %rsi
addq $0x8, %rsi
callq 0xd7f0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq (%rax), %rdi
callq 0xd850
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xd820
testb $0x1, %al
jne 0xce51
jmp 0xceb6
movl $0x28, %edi
callq 0x4390
movq %rax, -0x118(%rbp)
movq %rax, -0x120(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xd880
movq -0x118(%rbp), %rdi
movq 0x20(%rax), %rsi
callq 0xd3e0
jmp 0xce84
movq -0x120(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0xcf89
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x43b0
jmp 0xd013
movq -0x18(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x0, %rax
je 0xced4
movq -0x128(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0xd0(%rbp), %rdx
movq %rdx, %rax
addq $0x8, %rax
movq %rax, -0x138(%rbp)
addq $0x10, %rdx
leaq 0x54f0(%rip), %rsi      # 0x123e4
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0xd8f0
movq -0x130(%rbp), %rsi
leaq 0x5377(%rip), %rdx      # 0x1228c
leaq -0xa0(%rbp), %rdi
callq 0xd8a0
jmp 0xcf23
movq -0x138(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xd030
jmp 0xcf38
leaq -0xa0(%rbp), %rdi
callq 0x4738
leaq -0xc0(%rbp), %rdi
callq 0x4738
jmp 0xcf89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xcf78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x4738
leaq -0xc0(%rbp), %rdi
callq 0x4738
jmp 0xd013
jmp 0xcf8b
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0xc770
movq -0xd0(%rbp), %rax
cmpl $0x3, 0x8(%rax)
jne 0xcff4
movq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
addq $0x8, %rdi
addq $0x8, %rdi
callq 0x4440
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4540
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0xda00
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0xc770
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xda20
jmp 0xcbd3
movq -0x18(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x4620
movq %rax, %rdi
callq 0x6cd0
nopw %cs:(%rax,%rax)