// File: rfotino[P]consolite-compiler/src/syntax.cpp
// Function: WhileStatement::parse(Tokenizer*, std::vector<std::shared_ptr<FunctionToken>, std::allocator<std::shared_ptr<FunctionToken>>> const&, std::vector<std::shared_ptr<GlobalVarToken>, std::allocator<std::shared_ptr<GlobalVarToken>>> const&, std::vector<std::shared_ptr<ParamToken>, std::allocator<std::shared_ptr<ParamToken>>> const&, std::vector<std::shared_ptr<LocalVarToken>, std::allocator<std::shared_ptr<LocalVarToken>>> const&, std::vector<std::shared_ptr<LabelStatement>, std::allocator<std::shared_ptr<LabelStatement>>>&, std::vector<std::shared_ptr<GotoStatement>, std::allocator<std::shared_ptr<GotoStatement>>>&, std::shared_ptr<FunctionToken> const&)
bool WhileStatement::parse(
      Tokenizer *tokenizer,
      const std::vector<std::shared_ptr<FunctionToken>>& functions,
      const std::vector<std::shared_ptr<GlobalVarToken>>& globals,
      const std::vector<std::shared_ptr<ParamToken>>& parameters,
      const std::vector<std::shared_ptr<LocalVarToken>>& localVars,
      std::vector<std::shared_ptr<LabelStatement>>& labels,
      std::vector<std::shared_ptr<GotoStatement>>& gotos,
     const std::shared_ptr<FunctionToken>& currentFunc) {
  _lineNum = tokenizer->peekNext().line();
  // First token should be the "while" keyword.
  if (!_expect(tokenizer, "while")) {
    return false;
  }
  // Next token should be an open parenthesis.
  if (!_expect(tokenizer, "(")) {
    return false;
  }
  // Now we parse the conditional expression.
  _condExpr = std::shared_ptr<ExprToken>(new ExprToken());
  if (!_condExpr->parse(tokenizer, functions, globals,
                        parameters, localVars)) {
    return false;
  }
  // Next token should be a closing parenthesis.
  if (!_expect(tokenizer, ")")) {
    return false;
  }
  // Now we make sure the statement exists and is valid.
  _body = StatementToken::parse(tokenizer, functions, globals,
                                parameters, localVars, labels, gotos,
                                currentFunc, true);
  if (!_body) {
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x68(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x6bae0
movq -0x120(%rbp), %rdi
callq 0x32270
movl %eax, -0x114(%rbp)
jmp 0x2c332
movq -0x128(%rbp), %rax
movl -0x114(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq -0x68(%rbp), %rdi
callq 0x99b0
movq -0x18(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x8760
movq -0x130(%rbp), %rdx
leaq 0x43ad2(%rip), %rsi     # 0x6fe49
leaq -0x98(%rbp), %rdi
callq 0xced0
jmp 0x2c385
movq -0x138(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x1, %edx
callq 0x6da60
movb %al, -0x139(%rbp)
jmp 0x2c3a5
movb -0x139(%rbp), %al
xorb $-0x1, %al
movb %al, -0x13a(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8848
leaq -0x99(%rbp), %rdi
callq 0x8460
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0x2c3d7
jmp 0x2c431
movb $0x0, -0x1(%rbp)
jmp 0x2c6fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x99b0
jmp 0x2c709
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2c420
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8848
leaq -0x99(%rbp), %rdi
callq 0x8460
jmp 0x2c709
movq -0x18(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x8760
movq -0x148(%rbp), %rdx
leaq 0x42c50(%rip), %rsi     # 0x6f0ad
leaq -0xc0(%rbp), %rdi
callq 0xced0
jmp 0x2c46b
movq -0x150(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x1, %edx
callq 0x6da60
movb %al, -0x151(%rbp)
jmp 0x2c48b
movb -0x151(%rbp), %al
xorb $-0x1, %al
movb %al, -0x152(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x8848
leaq -0xc1(%rbp), %rdi
callq 0x8460
movb -0x152(%rbp), %al
testb $0x1, %al
jne 0x2c4bd
jmp 0x2c4fd
movb $0x0, -0x1(%rbp)
jmp 0x2c6fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2c4ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x8848
leaq -0xc1(%rbp), %rdi
callq 0x8460
jmp 0x2c709
movl $0x28, %edi
callq 0x83e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x160(%rbp)
callq 0x32670
jmp 0x2c51b
movq -0x160(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x33ab0
movq -0x128(%rbp), %rdi
addq $0x10, %rdi
leaq -0xd8(%rbp), %rsi
callq 0x35810
leaq -0xd8(%rbp), %rdi
callq 0x33b70
movq -0x128(%rbp), %rdi
addq $0x10, %rdi
callq 0x33ae0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
callq 0x1d9b0
testb $0x1, %al
jne 0x2c5ac
movb $0x0, -0x1(%rbp)
jmp 0x2c6fb
movq -0x160(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x28, %esi
callq 0x83f0
jmp 0x2c709
movq -0x18(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x8760
movq -0x168(%rbp), %rdx
leaq 0x44396(%rip), %rsi     # 0x7096e
leaq -0xf8(%rbp), %rdi
callq 0xced0
jmp 0x2c5e6
movq -0x170(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
movl $0x1, %edx
callq 0x6da60
movb %al, -0x171(%rbp)
jmp 0x2c606
movb -0x171(%rbp), %al
xorb $-0x1, %al
movb %al, -0x172(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x8848
leaq -0xf9(%rbp), %rdi
callq 0x8460
movb -0x172(%rbp), %al
testb $0x1, %al
jne 0x2c638
jmp 0x2c678
movb $0x0, -0x1(%rbp)
jmp 0x2c6fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2c667
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x8848
leaq -0xf9(%rbp), %rdi
callq 0x8460
jmp 0x2c709
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
leaq -0x110(%rbp), %rdi
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
callq 0x27d10
movq -0x128(%rbp), %rdi
addq $0x20, %rdi
leaq -0x110(%rbp), %rsi
callq 0x357b0
leaq -0x110(%rbp), %rdi
callq 0xfcd0
movq -0x128(%rbp), %rdi
addq $0x20, %rdi
callq 0x34140
testb $0x1, %al
jne 0x2c6f7
movb $0x0, -0x1(%rbp)
jmp 0x2c6fb
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x8750
nopw %cs:(%rax,%rax)