// File: /workspace/github_cpp_makefile_star2_O2/rfotino[P]consolite-compiler/src/syntax.cpp
// Function: FunctionCallToken::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&)
bool FunctionCallToken::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) {
  _lineNum = tokenizer->peekNext().line();
  // Start by getting the name of the function we are calling.
  AtomToken nameToken = tokenizer->getNext();
  if (nameToken.str().empty()) {
    _error("Unexpected EOF.", nameToken.line());
    return false;
  } else if (!isValidName(nameToken.str())) {
    _error("Invalid name for a function.", nameToken.line());
    return false;
  }
  _funcName = nameToken.str();
  // Next get the pointer to the function so that we know it exists
  // and can validate the arguments with the parameters later on.
  auto function = getFunction(_funcName, functions);
  if (!function) {
    _error("Function '" + _funcName + "' does not exist.", _lineNum);
    return false;
  }
  // The next token should be an open parenthesis.
  if (!_expect(tokenizer, "(")) {
    return false;
  }
  // Now get the comma-separated list of expressions.
  if (")" != tokenizer->peekNext().str()) {
    while (true) {
      std::shared_ptr<ExprToken> expr(new ExprToken());
      if (!expr->parse(tokenizer, functions, globals, parameters, localVars)) {
        return false;
      }
      _arguments.push_back(expr);
      // If the next token is not a comma, we are done. Otherwise consume
      // the comma and continue.
      if ("," != tokenizer->peekNext().str()) {
        break;
      }
      tokenizer->getNext();
    }
  }
  // Consume the closing parenthesis.
  if (!_expect(tokenizer, ")")) {
    return false;
  }
  // Check that the number of parameters is correct.
  if (this->numArgs() != function->numParams()) {
    _error("Invalid function call, expected " +
           std::to_string(function->numParams()) + " arguments but got " +
           std::to_string(this->numArgs()) + ".",
           _lineNum);
    return false;
  }
  // Make sure this is not a call to "void main()", which is illegal.
  if ("main" == function->name() && "void" == function->type().name() &&
      0 == function->numParams()) {
    _error("Illegal call to 'void main()', the entry point cannot be called "
	   "from within the program.",
	   _lineNum);
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %r9, 0xb0(%rsp)
movq %r8, %r13
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x279a6
movl 0x8(%rbx), %eax
movq %r15, 0x8(%rsp)
movl %eax, 0x8(%r15)
movq %rbx, %rdi
callq 0x7b20
leaq 0x118(%rsp), %rdi
movq %r14, %rsi
callq 0x2772c
leaq 0x128(%rsp), %rbx
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x73e0
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %r15
callq 0x75c8
testq %r15, %r15
je 0xfb5e
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x73e0
leaq 0x10(%rsp), %rdi
callq 0x2804b
movl %eax, %r15d
leaq 0x10(%rsp), %rdi
callq 0x75c8
testb %r15b, %r15b
je 0xfb87
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x73e0
movq 0x8(%rsp), %rax
leaq 0x10(%rax), %rbx
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7360
movq %r15, %rdi
callq 0x75c8
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x283f4
cmpq $0x0, 0x88(%rsp)
je 0xfbbf
leaq 0x196d8(%rip), %rsi     # 0x290a9
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x286c3
movl %eax, %ebx
leaq 0x10(%rsp), %rdi
callq 0x75c8
testb %bl, %bl
je 0xfd5f
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x279a6
leaq 0x20(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x73e0
leaq 0x1aeb7(%rip), %rdi     # 0x2a8de
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x9976
movl %eax, %r15d
movq %rbx, %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x7b20
testb %r15b, %r15b
je 0xfc2d
movq %r12, 0xa8(%rsp)
movq %r13, 0xa0(%rsp)
movq 0x8(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x98(%rsp)
leaq 0x68(%rsp), %r15
leaq 0x48(%rsp), %r13
leaq 0x148(%rsp), %rbx
pushq $0x28
popq %rdi
callq 0x72b0
orl $-0x1, 0x8(%rax)
leaq 0x2e5b0(%rip), %rcx     # 0x3e048
movq %rcx, (%rax)
movb $0x1, 0xc(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0xe(%rax)
movups %xmm0, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x25cd0
movq 0x68(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq 0xa8(%rsp), %rcx
movq 0xa0(%rsp), %r8
movq 0xb0(%rsp), %r9
callq 0xe5a8
testb %al, %al
je 0xfc14
movq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x186e8
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x279a6
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x73e0
leaq 0x19ed1(%rip), %rdi     # 0x299e7
movq %r13, %rsi
callq 0x9976
movl %eax, %r12d
movq %r13, %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x7b20
testb %r12b, %r12b
jne 0xfc23
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2772c
movq %rbx, %rdi
callq 0x7b20
leaq 0x70(%rsp), %rdi
callq 0x7a34
jmp 0xfa85
leaq 0x19e72(%rip), %rsi     # 0x299d7
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
movl 0x120(%rsp), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
jmp 0xfbae
leaq 0x19e5b(%rip), %rsi     # 0x299e9
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
movl 0x120(%rsp), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
callq 0x75c8
xorl %ebx, %ebx
jmp 0xfd6e
leaq 0x19e40(%rip), %rsi     # 0x29a06
leaq 0x48(%rsp), %rdi
movq %rbx, %rdx
callq 0x9980
leaq 0x19e37(%rip), %rdx     # 0x29a11
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x9ad4
movq 0x8(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
callq 0x75c8
leaq 0x48(%rsp), %rdi
callq 0x75c8
jmp 0xfd5f
leaq 0x70(%rsp), %rdi
callq 0x7a34
jmp 0xfd5f
leaq 0x70(%rsp), %rdi
callq 0x7a34
leaq 0x1acaa(%rip), %rsi     # 0x2a8de
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x286c3
movl %eax, %ebx
leaq 0x10(%rsp), %rdi
callq 0x75c8
testb %bl, %bl
je 0xfd5f
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
movq 0x88(%rsp), %rsi
movq 0x80(%rsi), %rax
subq 0x78(%rsi), %rax
cmpq %rax, %rcx
jne 0xfd8f
addq $0x58, %rsi
leaq 0x48(%rsp), %rdi
callq 0x73e0
leaq 0x1945a(%rip), %rdi     # 0x290ff
leaq 0x48(%rsp), %rsi
callq 0x97dd
testb %al, %al
je 0xfe8e
movq 0x88(%rsp), %rsi
addq $0x20, %rsi
leaq 0x10(%rsp), %rdi
callq 0x9b54
leaq 0x20(%rsp), %rsi
leaq 0x68(%rsp), %rdi
callq 0x73e0
leaq 0x1934d(%rip), %rdi     # 0x29030
leaq 0x68(%rsp), %rsi
callq 0x97dd
testb %al, %al
je 0xfe7a
movq 0x88(%rsp), %rax
movq 0x80(%rax), %r14
movq 0x78(%rax), %r15
leaq 0x68(%rsp), %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x97a8
leaq 0x48(%rsp), %rdi
callq 0x75c8
movb $0x1, %bl
cmpq %r15, %r14
jne 0xfd61
leaq 0x19d24(%rip), %rsi     # 0x29a58
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x9502
movq 0x8(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
jmp 0xfc0a
xorl %ebx, %ebx
leaq 0x90(%rsp), %rdi
callq 0x7a34
leaq 0x118(%rsp), %rdi
callq 0x7b20
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
sarq $0x4, %rax
leaq 0xd8(%rsp), %rdi
movq %rax, %rsi
callq 0x1877b
leaq 0x19c79(%rip), %rsi     # 0x29a23
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rdx
callq 0x1832f
leaq 0x19c7e(%rip), %rdx     # 0x29a44
leaq 0x68(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x9ad4
movq 0x8(%rsp), %rax
movq 0x38(%rax), %rsi
subq 0x30(%rax), %rsi
sarq $0x4, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x1877b
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x18714
leaq 0x19f2f(%rip), %rdx     # 0x29d43
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x9ad4
movq 0x8(%rsp), %rax
movl 0x8(%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0x285f3
leaq 0x10(%rsp), %rdi
callq 0x75c8
leaq 0x48(%rsp), %rdi
callq 0x75c8
leaq 0xb8(%rsp), %rdi
callq 0x75c8
leaq 0x68(%rsp), %rdi
callq 0x75c8
leaq 0xf8(%rsp), %rdi
callq 0x75c8
leaq 0xd8(%rsp), %rdi
jmp 0xfc0a
leaq 0x68(%rsp), %rdi
callq 0x75c8
leaq 0x10(%rsp), %rdi
callq 0x97a8
leaq 0x48(%rsp), %rdi
callq 0x75c8
movb $0x1, %bl
jmp 0xfd61
jmp 0xff52
jmp 0xff96
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x97a8
jmp 0xff49
jmp 0xff46
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0xfed2
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x75c8
jmp 0xfee1
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x75c8
jmp 0xfef3
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x75c8
jmp 0xff02
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x75c8
leaq 0xd8(%rsp), %rdi
jmp 0xff5a
movq %rax, %rbx
jmp 0xff0f
jmp 0xff96
jmp 0xff96
jmp 0xff52
jmp 0xff96
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7b20
jmp 0xffa8
jmp 0xff96
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0xff49
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0xff5a
jmp 0xff96
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0xffa8
jmp 0xff96
jmp 0xff6f
jmp 0xff91
jmp 0xff91
jmp 0xff91
jmp 0xff6f
jmp 0xff91
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x75c8
jmp 0xffb5
jmp 0xff91
jmp 0xff9b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7b20
jmp 0xff9e
movq %rax, %rbx
jmp 0xffb5
movq %rax, %rbx
jmp 0xffa8
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x7a34
leaq 0x90(%rsp), %rdi
callq 0x7a34
leaq 0x118(%rsp), %rdi
callq 0x7b20
movq %rbx, %rdi
callq 0x7510