// File: /workspace/github_c_makefile_star2_O0/sisshiki1969[P]monocc/src/pp.c
// Function: check_params
void check_params(Macro *m, Token *t, Macro **args) {
  // t->kind == TK_IDENT
  int param_count = 0;
  for (Token *param = m->params; param; param = param->next) param_count++;

  Token *start = t;
  t = t->next;
  if (!t) error_at_token(start, "Expected '('.");
  if (t->kind != TK_OP_PAREN) error_at_token(t, "Expected '('.");
  // t->kind == TK_OP_PAREN
  int arg_count = 0;
  Token anchor;
  while (t->next && t->next->kind != TK_CL_PAREN) {
    // t->next->kind != TK_CL_PAREN
    // invoke function-like macro
    Token *arg_token = t->next;
    while (t->next->kind != TK_CL_PAREN && t->next->kind != TK_COMMA) {
      if (t->next->kind == TK_OP_PAREN) {
        while (t->next->kind != TK_CL_PAREN) {
          t = t->next;
          if (!t->next)
            error_at_token(t, "Improperly terminated macro invocation.");
        }
        // t->next->kind != TK_CL_PAREN
      }
      t = t->next;
      if (!t->next)
        error_at_token(t, "Improperly terminated macro invocation.");
    }
    // t->next->kind == ( TK_CL_PAREN || TK_COMMA )

    Token *next = t->next;
    t->next = NULL;
    anchor.next = next;
    t = &anchor;
    // t->next->kind == ( TK_CL_PAREN || TK_COMMA )
    Macro *arg = calloc(1, sizeof(Macro));
    arg->params = arg_token;
    (*args)->next = arg;
    *args = arg;
    arg_count++;
    if (arg_count > param_count)
      error_at_token(arg_token,
                     "Too many arguments in invocation of macro '%.*s'. "
                     "actual:%d expected:%d",
                     start->len, start->str, arg_count, param_count);
    if (t->next->kind == TK_CL_PAREN) break;
    // t->next->kind == TK_COMMA
    t = t->next;
    // t->kind == TK_COMMA
  }
  // t->next->kind == TK_CL_PAREN or !t->next
  if (!t->next) error_at_token(t, "Expected ')'.");
  // t->next->kind == TK_CL_PAREN
  start->next = t->next->next;

  if (arg_count < param_count)
    error_at_token(start, "Too few arguments for invokation of macro.");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xad08
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xacea
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xad35
movq -0x30(%rbp), %rdi
leaq 0x5b39(%rip), %rsi      # 0x10867
movb $0x0, %al
callq 0x5d20
movq -0x10(%rbp), %rax
cmpl $0x1d, (%rax)
je 0xad50
movq -0x10(%rbp), %rdi
leaq 0x5b1e(%rip), %rsi      # 0x10867
movb $0x0, %al
callq 0x5d20
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, 0x8(%rcx)
movb %al, -0x81(%rbp)
je 0xad7e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x1e, (%rax)
setne %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0xad8d
jmp 0xaeff
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
xorl %eax, %eax
cmpl $0x1e, (%rcx)
movb %al, -0x82(%rbp)
je 0xadc2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x23, (%rax)
setne %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0xadce
jmp 0xae45
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x1d, (%rax)
jne 0xae17
jmp 0xaddd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x1e, (%rax)
je 0xae15
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xae13
movq -0x10(%rbp), %rdi
leaq 0x5a69(%rip), %rsi      # 0x10875
movb $0x0, %al
callq 0x5d20
jmp 0xaddd
jmp 0xae17
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xae40
movq -0x10(%rbp), %rdi
leaq 0x5a3c(%rip), %rsi      # 0x10875
movb $0x0, %al
callq 0x5d20
jmp 0xad99
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x10d0
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq -0x80(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jle 0xaedf
movq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
movl -0x34(%rbp), %r8d
movl -0x1c(%rbp), %r9d
leaq 0x59c5(%rip), %rsi      # 0x1089d
movb $0x0, %al
callq 0x5d20
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x1e, (%rax)
jne 0xaeee
jmp 0xaeff
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0xad57
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xaf1c
movq -0x10(%rbp), %rdi
leaq 0x59d0(%rip), %rsi      # 0x108e5
movb $0x0, %al
callq 0x5d20
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xaf4a
movq -0x30(%rbp), %rdi
leaq 0x59b0(%rip), %rsi      # 0x108f3
movb $0x0, %al
callq 0x5d20
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)