// File: /workspace/github_c_makefile_star2_O1/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 0xafad(%rip), %rbp      # 0x13228
movq (%rbp), %rax
cmpl $0x5, (%rax)
jne 0x8299
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movq %r15, %rdi
callq 0xadb8
movq %rax, %r15
jmp 0x827b
movq (%rbp), %rax
movl (%rax), %ecx
cmpl $0x1d, %ecx
je 0x82e0
testl %ecx, %ecx
jne 0x831f
movq (%rbp), %r14
movq 0x8(%r14), %rax
movq %rax, (%rbp)
movq %r14, %rdi
callq 0x6311
testb %al, %al
je 0x84c2
leaq 0x533b(%rip), %rsi      # 0xd606
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
xorl %eax, %eax
callq 0x52f9
jmp 0x832b
movq 0x8(%rax), %rax
movq %rax, (%rbp)
leaq 0x58(%rsp), %rdi
callq 0x8260
movq %rax, %rbx
movq (%rbp), %rdi
cmpl $0x1e, (%rdi)
je 0x830c
leaq 0x5125(%rip), %rsi      # 0xd42a
xorl %eax, %eax
callq 0x52f9
movq %rbx, 0x8(%rsp)
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
jmp 0x8328
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
movq (%rbp), %rax
cmpl $0x21, (%rax)
jne 0x83ad
leaq 0x18(%rsp), %rbx
leaq 0x50e5(%rip), %r12      # 0xd42a
movq 0x8(%rax), %rdi
movq %rdi, (%rbp)
movl (%rdi), %eax
cmpl $0x1, %eax
je 0x8368
movl $0x0, %esi
cmpl $0x22, %eax
je 0x8377
movq %r12, %rsi
xorl %eax, %eax
callq 0x52f9
movq (%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, (%rbp)
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0xadd7
movq %rax, %r13
movq %rax, 0x8(%rbx)
movq (%rbp), %rdi
cmpl $0x22, (%rdi)
je 0x8399
movq %r12, %rsi
xorl %eax, %eax
callq 0x52f9
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
cmpl $0x21, (%rax)
movq %r13, %rbx
je 0x8345
movq 0x20(%rsp), %r15
movq (%rbp), %rax
cmpl $0x1d, (%rax)
jne 0x846a
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movq %r15, %rdi
callq 0xae04
movq %rax, %r15
leaq 0x10(%rsp), %rbx
movq $0x0, (%rbx)
movq (%rbp), %rax
movl (%rax), %ecx
cmpl $0x1e, %ecx
je 0x843e
cmpl $0x28, %ecx
je 0x8431
xorl %edi, %edi
callq 0x70e6
movq %rax, %r12
movq 0x10(%rax), %rdi
callq 0xaea7
testb %al, %al
je 0x8418
movq 0x10(%r12), %rax
movq 0x8(%rax), %rdi
callq 0xadb8
movq %rax, 0x10(%r12)
movq %r12, (%rbx)
movq (%rbp), %rax
cmpl $0x23, (%rax)
jne 0x843e
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movq %r12, %rbx
jmp 0x83de
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movb $0x1, 0x38(%r15)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%r15)
movq (%rbp), %rdi
cmpl $0x1e, (%rdi)
je 0x845e
leaq 0x4fd3(%rip), %rsi      # 0xd42a
xorl %eax, %eax
callq 0x52f9
movq (%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, (%rbp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x8496
movq 0x10(%rsi), %rbx
leaq 0x58(%rsp), %rax
movq %rbx, %rdx
movq %rdx, %rcx
movq 0x8(%rdx), %rdx
cmpq %rax, %rdx
jne 0x8480
movq %r15, 0x8(%rcx)
movq 0x8(%rsi), %r14
jmp 0x8499
movq %r15, %rbx
movl $0x1, %edi
movl $0x20, %esi
callq 0x10d0
movq %rbx, 0x10(%rax)
movq %r14, 0x8(%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, 0x8(%rsp)
jmp 0x832b