// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl $0x5, %edi
callq 0x7860
testb $0x1, %al
jne 0x9d1f
jmp 0x9d2e
movq -0x8(%rbp), %rdi
callq 0xd140
movq %rax, -0x8(%rbp)
jmp 0x9d0f
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
xorl %edi, %edi
callq 0x77d0
testb $0x1, %al
jne 0x9d4b
jmp 0x9d79
xorl %edi, %edi
callq 0x7980
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7c10
testb $0x1, %al
jne 0x9d65
jmp 0x9d77
movq -0x58(%rbp), %rdi
leaq 0x6936(%rip), %rsi      # 0x106a6
movb $0x0, %al
callq 0x5d20
jmp 0x9da2
movl $0x1d, %edi
callq 0x7860
testb $0x1, %al
jne 0x9d89
jmp 0x9da0
leaq -0x48(%rbp), %rdi
callq 0x9d00
movq %rax, -0x50(%rbp)
movl $0x1e, %edi
callq 0x7980
jmp 0x9da2
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl $0x21, %edi
callq 0x7860
testb $0x1, %al
jne 0x9dcb
jmp 0x9e32
movl $0x0, -0xa4(%rbp)
movl $0x22, %edi
callq 0x77d0
testb $0x1, %al
jne 0x9df7
movl $0x1, %edi
callq 0x7980
movq 0x10(%rax), %rax
movl %eax, -0xa4(%rbp)
movq -0x8(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0xd180
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
movl $0x22, %edi
callq 0x7980
jmp 0x9dbb
movq -0x90(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1d, %edi
callq 0x7860
testb $0x1, %al
jne 0x9e50
jmp 0x9f38
movq -0x8(%rbp), %rdi
callq 0xd1d0
movq %rax, -0x8(%rbp)
movq $0x0, -0xc8(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x1e, %edi
callq 0x77d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x9e8b
jmp 0x9f1f
movl $0x28, %edi
callq 0x7860
testb $0x1, %al
jne 0x9e9b
jmp 0x9ea5
movq -0x8(%rbp), %rax
movb $0x1, 0x38(%rax)
jmp 0x9f1f
xorl %edi, %edi
callq 0x8b40
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xd370
testb $0x1, %al
jne 0x9ec9
jmp 0x9eeb
movq -0xd8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0xd140
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0xd8(%rbp), %rcx
movq -0xd0(%rbp), %rax
movq %rcx, (%rax)
movq -0xd8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movl $0x23, %edi
callq 0x7860
testb $0x1, %al
jne 0x9f1a
jmp 0x9f1f
jmp 0x9e76
movq -0xc8(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x1e, %edi
callq 0x7980
cmpq $0x0, -0x50(%rbp)
je 0x9f9a
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
leaq -0x48(%rbp), %rcx
cmpq %rcx, 0x8(%rax)
je 0x9f73
movq -0xe0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xe0(%rbp)
jmp 0x9f4e
movq -0x8(%rbp), %rcx
movq -0xe0(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x7fe0
addq $0xe0, %rsp
popq %rbp
retq