// File: /workspace/github_c_makefile_star2_O2/sisshiki1969[P]monocc/src/parse.c
// Function: parse_declaretor
MemberInfo *parse_declaretor(Type *type) {
  // declarator
  while (consume_if(TK_MUL)) {
    type = new_type_ptr_to(type);
  }

  Type anchor;
  MemberInfo *outer = NULL;
  Token *ident = NULL;
  // direct-declarator
  if (peek(TK_IDENT)) {
    ident = expect(TK_IDENT);
    if (find_lvar_in_scope(ident))
      error_at_token(ident, "Duplicate definition of local variable.");
  } else if (consume_if(TK_OP_PAREN)) {
    outer = parse_declaretor(&anchor);
    expect(TK_CL_PAREN);
  }
  // direct-declarator [ assignment-expression ]
  Type head;
  head.ptr_to = type;
  Type *cursor = &head;
  while (consume_if(TK_OP_BRACKET)) {
    int size = 0;
    if (!peek(TK_CL_BRACKET))
      // this should be assignment-expression
      size = expect(TK_NUM)->num_val;
    cursor->ptr_to = new_type_array(type, size);
    cursor = cursor->ptr_to;
    expect(TK_CL_BRACKET);
  }
  type = head.ptr_to;

  if (consume_if(TK_OP_PAREN)) {
    type = new_type_func(type);
    MemberInfo head;
    head.next = NULL;
    MemberInfo *cursor = &head;
    while (!peek(TK_CL_PAREN)) {
      if (consume_if(TK_ELLIPSIS)) {
        type->variadic = true;
        break;
      }
      MemberInfo *pinfo = parse_decl(false);
      if (is_array(pinfo->type))
        pinfo->type = new_type_ptr_to(pinfo->type->ptr_to);
      cursor->next = pinfo;
      cursor = pinfo;
      if (!consume_if(TK_COMMA)) break;
    }
    type->params = head.next;
    expect(TK_CL_PAREN);
  }

  if (outer) {
    Type *cursor = outer->type;
    while (cursor->ptr_to != &anchor) cursor = cursor->ptr_to;
    cursor->ptr_to = type;
    type = outer->type;
    ident = outer->ident;
  }

  return new_member_info(ident, type);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r15
leaq 0xa07f(%rip), %r14      # 0x11228
movq (%r14), %rax
movl (%rax), %ecx
cmpl $0x5, %ecx
jne 0x71c7
movq 0x8(%rax), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x90cc
movq %rax, %r15
jmp 0x71a9
cmpl $0x1d, %ecx
je 0x720a
testl %ecx, %ecx
jne 0x7229
xorl %edi, %edi
callq 0x5a46
movq %rax, %rbx
movq %rax, %rdi
callq 0x5b71
testb %al, %al
movq %rbx, 0x8(%rsp)
je 0x736c
leaq 0x4434(%rip), %rsi      # 0xb62a
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %eax, %eax
callq 0x48b3
jmp 0x723a
movq 0x8(%rax), %rax
movq %rax, (%r14)
leaq 0x58(%rsp), %rdi
callq 0x718e
movq %rax, (%rsp)
pushq $0x1e
popq %rdi
callq 0x5a46
jmp 0x7231
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x18(%rsp), %rbx
movq %r15, 0x8(%rbx)
pushq $0x22
popq %rbp
pushq $0x1
popq %r12
movq (%r14), %rax
movl (%rax), %ecx
cmpl $0x21, %ecx
jne 0x7288
movq 0x8(%rax), %rax
movq %rax, (%r14)
xorl %esi, %esi
cmpl $0x22, (%rax)
je 0x726d
movl %r12d, %edi
callq 0x5a46
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x90e7
movq %rax, %r13
movq %rax, 0x8(%rbx)
movl %ebp, %edi
callq 0x5a46
movq %r13, %rbx
jmp 0x724a
movq 0x20(%rsp), %r15
cmpl $0x1d, %ecx
jne 0x7303
movq 0x8(%rax), %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x9110
movq %rax, %r15
leaq 0x10(%rsp), %r13
andq $0x0, (%r13)
movq (%r14), %rax
movq (%rsp), %rbx
movl (%rax), %ecx
cmpl $0x1e, %ecx
je 0x7315
cmpl $0x28, %ecx
je 0x7309
xorl %edi, %edi
callq 0x651c
movq %rax, %r12
movq 0x10(%rax), %rdi
callq 0x919f
testb %al, %al
je 0x72eb
movq 0x10(%r12), %rax
movq 0x8(%rax), %rdi
callq 0x90cc
movq %rax, 0x10(%r12)
movq %r12, (%r13)
movq (%r14), %rax
cmpl $0x23, (%rax)
jne 0x7315
movq 0x8(%rax), %rax
movq %rax, (%r14)
movq %r12, %r13
jmp 0x72b5
movq (%rsp), %rbx
jmp 0x7326
movq 0x8(%rax), %rax
movq %rax, (%r14)
movb $0x1, 0x38(%r15)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%r15)
pushq $0x1e
popq %rdi
callq 0x5a46
testq %rbx, %rbx
je 0x734d
movq 0x10(%rbx), %rsi
leaq 0x58(%rsp), %rax
movq %rsi, %rdx
movq %rdx, %rcx
movq 0x8(%rdx), %rdx
cmpq %rax, %rdx
jne 0x7337
movq %r15, 0x8(%rcx)
movq 0x8(%rbx), %rdi
jmp 0x7355
movq %r15, %rsi
movq 0x8(%rsp), %rdi
callq 0x5d40
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, (%rsp)
jmp 0x723a