// File: /workspace/github_c_makefile_star2_O3/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, %rbx
leaq 0xb0b7(%rip), %rbp      # 0x13228
movq (%rbp), %r15
movl (%r15), %eax
cmpl $0x5, %eax
jne 0x8192
movq 0x8(%r15), %rax
movq %rax, (%rbp)
movq %rbx, %rdi
callq 0xac90
movq %rax, %rbx
jmp 0x8171
cmpl $0x1d, %eax
je 0x81d3
testl %eax, %eax
jne 0x820f
movq 0x8(%r15), %r14
movq %r14, (%rbp)
movq %r15, %rdi
callq 0x62cb
testb %al, %al
je 0x83bf
leaq 0x5488(%rip), %rsi      # 0xd642
movq $0x0, 0x8(%rsp)
movq %r15, %rdi
xorl %eax, %eax
callq 0x52cd
movq (%rbp), %r14
jmp 0x821e
movq 0x8(%r15), %rax
movq %rax, (%rbp)
leaq 0x58(%rsp), %rdi
callq 0x8156
movq %rax, 0x8(%rsp)
movq (%rbp), %rdi
cmpl $0x1e, (%rdi)
je 0x8205
leaq 0x526c(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbp), %rdi
movq 0x8(%rdi), %r14
movq %r14, (%rbp)
jmp 0x821b
movq $0x0, 0x8(%rsp)
movq %r15, %r14
xorl %r15d, %r15d
movq %rbx, 0x20(%rsp)
movl (%r14), %eax
cmpl $0x21, %eax
jne 0x82a9
leaq 0x18(%rsp), %r12
movq 0x8(%r14), %rdi
movq %rdi, (%rbp)
movl (%rdi), %eax
cmpl $0x1, %eax
je 0x825b
movl $0x0, %esi
cmpl $0x22, %eax
je 0x8266
leaq 0x5216(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, (%rbp)
movl 0x10(%rdi), %esi
movq %rbx, %rdi
callq 0xacaf
movq %rax, %r13
movq %rax, 0x8(%r12)
movq (%rbp), %rdi
cmpl $0x22, (%rdi)
je 0x8291
leaq 0x51e0(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbp), %rdi
movq 0x8(%rdi), %r14
movq %r14, (%rbp)
movl (%r14), %eax
movq %r13, %r12
cmpl $0x21, %eax
je 0x8230
movq 0x20(%rsp), %rbx
cmpl $0x1d, %eax
jne 0x8367
movq 0x8(%r14), %rax
movq %rax, (%rbp)
movq %rbx, %rdi
callq 0xacdc
movq %rax, %rbx
leaq 0x10(%rsp), %r14
movq $0x0, (%r14)
movq (%rbp), %rdi
movl (%rdi), %eax
cmpl $0x28, %eax
je 0x8331
cmpl $0x1e, %eax
je 0x8326
xorl %edi, %edi
callq 0x7095
movq %rax, %r12
movq 0x10(%rax), %rdi
callq 0xad7b
testb %al, %al
je 0x830b
movq 0x10(%r12), %rax
movq 0x8(%rax), %rdi
callq 0xac90
movq %rax, 0x10(%r12)
movq %r12, (%r14)
movq (%rbp), %rdi
movl (%rdi), %eax
cmpl $0x23, %eax
jne 0x833f
movq 0x8(%rdi), %rdi
movq %rdi, (%rbp)
movq %r12, %r14
jmp 0x82d5
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rbx)
jmp 0x835f
movq 0x8(%rdi), %rdi
movq %rdi, (%rbp)
movb $0x1, 0x38(%rbx)
movl (%rdi), %eax
movq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rbx)
cmpl $0x1e, %eax
je 0x835f
leaq 0x5112(%rip), %rsi      # 0xd466
xorl %eax, %eax
callq 0x52cd
movq (%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, (%rbp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x8393
movq 0x10(%rsi), %r14
leaq 0x58(%rsp), %rax
movq %r14, %rdx
movq %rdx, %rcx
movq 0x8(%rdx), %rdx
cmpq %rax, %rdx
jne 0x837d
movq %rbx, 0x8(%rcx)
movq 0x8(%rsi), %r15
jmp 0x8396
movq %rbx, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x10d0
movq %r14, 0x10(%rax)
movq %r15, 0x8(%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0x8(%rsp)
jmp 0x821e