// File: rfotino[P]consolite-compiler/src/syntax.cpp
// Function: ReturnStatement::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::shared_ptr<FunctionToken> const&)
bool ReturnStatement::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,
      const std::shared_ptr<FunctionToken>& currentFunc) {
  _lineNum = tokenizer->peekNext().line();
  // Make sure the first token is the "return" keyword.
  if (!_expect(tokenizer, "return")) {
    return false;
  }
  // If the next token is not a semicolon, parse the expression.
  if (";" != tokenizer->peekNext().str()) {
    _hasExpr = true;
    if (!_returnExpr.parse(tokenizer, functions, globals,
                           parameters, localVars)) {
      return false;
    }
  } else {
    _hasExpr = false;
  }
  // Check for the trailing semicolon.
  if (!_expect(tokenizer, ";")) {
    return false;
  }
  // Make sure that _hasExpr matches up with the void-ness of the
  // containing function.
  if (_hasExpr && "void" == currentFunc->type().name()) {
    _error("Cannot return a value from a void function.", _lineNum);
    return false;
  } else if (!_hasExpr && "void" != currentFunc->type().name()) {
    _error("Return statement must include a value in a non-void function.",
           _lineNum);
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
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, -0x238(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x68(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x6bae0
movq -0x230(%rbp), %rdi
callq 0x32270
movl %eax, -0x228(%rbp)
jmp 0x2d2fa
movq -0x238(%rbp), %rax
movl -0x228(%rbp), %ecx
movl %ecx, 0x8(%rax)
leaq -0x68(%rbp), %rdi
callq 0x99b0
movq -0x18(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x8760
movq -0x240(%rbp), %rdx
leaq 0x43307(%rip), %rsi     # 0x70646
leaq -0x98(%rbp), %rdi
callq 0xced0
jmp 0x2d34d
movq -0x248(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x1, %edx
callq 0x6da60
movb %al, -0x249(%rbp)
jmp 0x2d36d
movb -0x249(%rbp), %al
xorb $-0x1, %al
movb %al, -0x24a(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8848
leaq -0x99(%rbp), %rdi
callq 0x8460
movb -0x24a(%rbp), %al
testb $0x1, %al
jne 0x2d39f
jmp 0x2d3f9
movb $0x0, -0x1(%rbp)
jmp 0x2d937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x99b0
jmp 0x2d945
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d3e8
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 0x2d945
movq -0x18(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x6bae0
movq -0x258(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
callq 0xd5c0
jmp 0x2d425
leaq 0x42825(%rip), %rdi     # 0x6fc51
leaq -0xc0(%rbp), %rsi
callq 0xd8e0
movb %al, -0x259(%rbp)
jmp 0x2d440
leaq -0xc0(%rbp), %rdi
callq 0x8848
leaq -0xf0(%rbp), %rdi
callq 0x99b0
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x2d464
jmp 0x2d4d2
movq -0x238(%rbp), %rdi
movb $0x1, 0x38(%rdi)
addq $0x10, %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 0x2d4d0
movb $0x0, -0x1(%rbp)
jmp 0x2d937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d4bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x8848
leaq -0xf0(%rbp), %rdi
callq 0x99b0
jmp 0x2d945
jmp 0x2d4dd
movq -0x238(%rbp), %rax
movb $0x0, 0x38(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x8760
movq -0x268(%rbp), %rdx
leaq 0x42748(%rip), %rsi     # 0x6fc51
leaq -0x110(%rbp), %rdi
callq 0xced0
jmp 0x2d517
movq -0x270(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x1, %edx
callq 0x6da60
movb %al, -0x271(%rbp)
jmp 0x2d537
movb -0x271(%rbp), %al
xorb $-0x1, %al
movb %al, -0x272(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x8848
leaq -0x111(%rbp), %rdi
callq 0x8460
movb -0x272(%rbp), %al
testb $0x1, %al
jne 0x2d569
jmp 0x2d5a9
movb $0x0, -0x1(%rbp)
jmp 0x2d937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d598
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x8848
leaq -0x111(%rbp), %rdi
callq 0x8460
jmp 0x2d945
movq -0x238(%rbp), %rax
movb 0x38(%rax), %cl
movb $0x0, -0x171(%rbp)
movb $0x0, -0x172(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x273(%rbp)
je 0x2d639
movq 0x10(%rbp), %rdi
callq 0xd780
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0xd910
movq -0x280(%rbp), %rsi
movb $0x1, -0x171(%rbp)
leaq -0x138(%rbp), %rdi
callq 0xd940
jmp 0x2d609
movb $0x1, -0x172(%rbp)
leaq 0x41a1d(%rip), %rdi     # 0x6f034
leaq -0x138(%rbp), %rsi
callq 0xd590
movb %al, -0x281(%rbp)
jmp 0x2d62b
movb -0x281(%rbp), %al
movb %al, -0x273(%rbp)
jmp 0x2d639
movb -0x273(%rbp), %al
movb %al, -0x282(%rbp)
testb $0x1, -0x172(%rbp)
jne 0x2d650
jmp 0x2d65c
leaq -0x138(%rbp), %rdi
callq 0x8848
testb $0x1, -0x171(%rbp)
jne 0x2d667
jmp 0x2d673
leaq -0x170(%rbp), %rdi
callq 0xd440
movb -0x282(%rbp), %al
testb $0x1, %al
jne 0x2d682
jmp 0x2d770
leaq -0x199(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x8760
movq -0x290(%rbp), %rdx
leaq 0x42981(%rip), %rsi     # 0x70024
leaq -0x198(%rbp), %rdi
callq 0xced0
jmp 0x2d6b1
movq -0x238(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0x198(%rbp), %rdi
callq 0x6d960
jmp 0x2d6c9
leaq -0x198(%rbp), %rdi
callq 0x8848
leaq -0x199(%rbp), %rdi
callq 0x8460
movb $0x0, -0x1(%rbp)
jmp 0x2d937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d71d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
testb $0x1, -0x172(%rbp)
jne 0x2d70f
jmp 0x2d71b
leaq -0x138(%rbp), %rdi
callq 0x8848
jmp 0x2d71d
testb $0x1, -0x171(%rbp)
jne 0x2d728
jmp 0x2d734
leaq -0x170(%rbp), %rdi
callq 0xd440
jmp 0x2d945
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d75f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x8848
leaq -0x199(%rbp), %rdi
callq 0x8460
jmp 0x2d945
movq -0x238(%rbp), %rax
movb 0x38(%rax), %cl
movb $0x0, -0x1f9(%rbp)
movb $0x0, -0x1fa(%rbp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x291(%rbp)
jne 0x2d800
movq 0x10(%rbp), %rdi
callq 0xd780
movq %rax, %rsi
leaq -0x1f8(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0xd910
movq -0x2a0(%rbp), %rsi
movb $0x1, -0x1f9(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0xd940
jmp 0x2d7d0
movb $0x1, -0x1fa(%rbp)
leaq 0x41856(%rip), %rdi     # 0x6f034
leaq -0x1c0(%rbp), %rsi
callq 0xd8e0
movb %al, -0x2a1(%rbp)
jmp 0x2d7f2
movb -0x2a1(%rbp), %al
movb %al, -0x291(%rbp)
jmp 0x2d800
movb -0x291(%rbp), %al
movb %al, -0x2a2(%rbp)
testb $0x1, -0x1fa(%rbp)
jne 0x2d817
jmp 0x2d823
leaq -0x1c0(%rbp), %rdi
callq 0x8848
testb $0x1, -0x1f9(%rbp)
jne 0x2d82e
jmp 0x2d83a
leaq -0x1f8(%rbp), %rdi
callq 0xd440
movb -0x2a2(%rbp), %al
testb $0x1, %al
jne 0x2d849
jmp 0x2d931
leaq -0x221(%rbp), %rdi
movq %rdi, -0x2b0(%rbp)
callq 0x8760
movq -0x2b0(%rbp), %rdx
leaq 0x427e6(%rip), %rsi     # 0x70050
leaq -0x220(%rbp), %rdi
callq 0xced0
jmp 0x2d878
movq -0x238(%rbp), %rax
movl 0x8(%rax), %esi
leaq -0x220(%rbp), %rdi
callq 0x6d960
jmp 0x2d890
leaq -0x220(%rbp), %rdi
callq 0x8848
leaq -0x221(%rbp), %rdi
callq 0x8460
movb $0x0, -0x1(%rbp)
jmp 0x2d937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d8e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
testb $0x1, -0x1fa(%rbp)
jne 0x2d8d6
jmp 0x2d8e2
leaq -0x1c0(%rbp), %rdi
callq 0x8848
jmp 0x2d8e4
testb $0x1, -0x1f9(%rbp)
jne 0x2d8ef
jmp 0x2d8fb
leaq -0x1f8(%rbp), %rdi
callq 0xd440
jmp 0x2d945
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2d923
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x8848
leaq -0x221(%rbp), %rdi
callq 0x8460
jmp 0x2d945
jmp 0x2d933
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x8750
nop