// File: /workspace/github_c_makefile_star2_O2/hsjoihs[P]c-compiler/parse_type.c
// Function: parse_type_specifier
struct Type *parse_type_specifier(const struct Token **ptr_tokvec)
{
	const struct Token *tokvec = *ptr_tokvec;

	skip_consts_or_noreturns(&tokvec);

	enum TokenKind tok = tokvec[0].kind;
	struct TypeNode *ptr = calloc(1, sizeof(struct TypeNode));

	if (tok == RES_CHAR) {
		ptr->type_category = CHAR_;
		++tokvec;
	} else if (tok == RES_INT) {
		ptr->type_category = INT_;
		++tokvec;
	} else if (tok == RES_VOID) {
		ptr->type_category = VOID_;
		++tokvec;
	} else if (tok == RES_STRUCT || tok == RES_UNION) {
		++tokvec;
		expect_and_consume(&tokvec, IDENT_OR_RESERVED,
		                   "identifier after `struct` or `union`");
		const char *ident = tokvec[-1].ident_str;

		ptr->type_category = tok == RES_STRUCT ? STRUCT_NOT_UNION : UNION;
		ptr->s.struct_or_union_tag = ident;
		if (tokvec[0].kind != LEFT_BRACE) {
			ptr->s.struct_or_union_info.ptr_types_and_idents =
			    0; /* crucial; no info */
			skip_consts_or_noreturns(&tokvec);
			*ptr_tokvec = tokvec;
			return ptr;
		}
		++tokvec;
		ptr->s.struct_or_union_info.ptr_types_and_idents = init_vector_();

		while (1) {
			if (tokvec[0].kind == RIGHT_BRACE) {
				++tokvec;
				break;
			}
			const char *ident_str;
			struct Type t = parse_struct_declaration(&tokvec, &ident_str);
			expect_and_consume(
			    &tokvec, SEMICOLON,
			    "semicolon after the declarator inside struct or union");
			struct TypeAndIdent *ptr_t_and_i =
			    calloc(1, sizeof(struct TypeAndIdent));
			ptr_t_and_i->type = t;
			ptr_t_and_i->ident_str = ident_str;

			push_vector(ptr->s.struct_or_union_info.ptr_types_and_idents,
			            ptr_t_and_i);
		}
	} else if (tok == RES_ENUM) {
		++tokvec;
		expect_and_consume(&tokvec, IDENT_OR_RESERVED,
		                   "identifier after `enum`");
		const char *ident = tokvec[-1].ident_str;
		ptr->type_category = ENUM_;
		ptr->e.enum_tag = ident;
		if (tokvec[0].kind != LEFT_BRACE) {
			ptr->e.enum_info.ptr_enumerators = 0; /* crucial; no info */
			skip_consts_or_noreturns(&tokvec);
			*ptr_tokvec = tokvec;
			return ptr;
		}
		++tokvec;

		ptr->e.enum_info.ptr_enumerators = init_vector_();

		do { /* at least one enumerator is needed */
			expect_and_consume(&tokvec, IDENT_OR_RESERVED,
			                   "identifier as a declaration of an enumerator");
			const char *ident_str = tokvec[-1].ident_str;
			push_vector(ptr->e.enum_info.ptr_enumerators, ident_str);

			/* ending without comma */
			if (tokvec[0].kind == RIGHT_BRACE) {
				++tokvec;
				break;
			} else if (tokvec[0].kind == OP_COMMA) {
				++tokvec;
				if (tokvec[0].kind == RIGHT_BRACE) {
					++tokvec;
					break;
				}
			}
		} while (1);

	

	} else {
		error_unexpected_token(
		    tokvec, "type name `int`, `char`, `void`, `struct` or `enum`");
	}

	skip_consts_or_noreturns(&tokvec);
	*ptr_tokvec = tokvec;
	return ptr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r12
movq (%rdi), %rax
leaq -0x30(%rbp), %rbx
movq %rax, (%rbx)
movq %rbx, %rdi
callq 0x8c0b
movq (%rbx), %r15
movl (%r15), %r14d
pushq $0x1
popq %rdi
pushq $0x50
popq %rsi
callq 0x10d0
movq %rax, %r13
leal -0x35(%r14), %eax
cmpl $0x9, %eax
ja 0x87e6
leaq 0x6bdc(%rip), %rcx      # 0xf3ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, (%r13)
jmp 0x88c2
cmpl $0x43, %r14d
je 0x88d8
cmpl $0x4a, %r14d
jne 0x89a9
addq $0x20, %r15
movq %r15, (%rbx)
leaq 0x6bcc(%rip), %rdx      # 0xf3d4
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x8168
xorl %ecx, %ecx
cmpl $0x3a, %r14d
movq (%rbx), %rax
movq -0x18(%rax), %rdx
setne %cl
addl $0x5, %ecx
movl %ecx, (%r13)
movq %rdx, 0x30(%r13)
cmpl $0x1e, (%rax)
jne 0x8984
movq %r12, -0x40(%rbp)
addq $0x20, %rax
leaq -0x30(%rbp), %r15
movq %rax, (%r15)
callq 0x49f5
movq %rax, %r12
movq %r13, -0x38(%rbp)
movq %rax, 0x38(%r13)
leaq -0x98(%rbp), %r13
pushq $0x58
popq %rbx
pushq $0xa
popq %r14
movq -0x30(%rbp), %rax
cmpl $0x1f, (%rax)
je 0x88cf
movq %r13, %rdi
movq %r15, %rsi
leaq -0x48(%rbp), %rdx
callq 0x8c2a
movq %r15, %rdi
pushq $0x1a
popq %rsi
leaq 0x6b70(%rip), %rdx      # 0xf3f9
callq 0x8168
pushq $0x1
popq %rdi
movq %rbx, %rsi
callq 0x10d0
movq %r14, %rcx
movq %rax, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x48(%rbp), %rcx
movq %rcx, 0x50(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x4a57
jmp 0x8864
movl $0x7, (%r13)
addq $0x20, %r15
movq %r15, -0x30(%rbp)
jmp 0x8984
addq $0x20, %rax
jmp 0x8978
addq $0x20, %r15
movq %r15, (%rbx)
leaq 0x6b49(%rip), %rdx      # 0xf42f
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x8168
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0x8, (%r13)
movq %rcx, 0x40(%r13)
cmpl $0x1e, (%rax)
jne 0x8984
movq %r12, -0x40(%rbp)
addq $0x20, %rax
movq %rax, (%rbx)
callq 0x49f5
movq %rax, %r14
movq %r13, -0x38(%rbp)
movq %rax, 0x48(%r13)
leaq 0x6b1c(%rip), %r15      # 0xf447
pushq $0x18
popq %r12
pushq $0x20
popq %r13
movq %rbx, %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x8168
movq -0x30(%rbp), %rax
movq -0x18(%rax), %rsi
movq %r14, %rdi
callq 0x4a57
movq -0x30(%rbp), %rax
movl (%rax), %ecx
cmpl $0xa, %ecx
je 0x8963
cmpl $0x1f, %ecx
jne 0x8933
jmp 0x8975
leaq 0x20(%rax), %rcx
movq %rcx, -0x30(%rbp)
cmpl $0x1f, 0x20(%rax)
jne 0x8933
pushq $0x40
popq %r13
addq %r13, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %r13
leaq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x8c0b
movq (%rbx), %rax
movq %rax, (%r12)
movq %r13, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ac4(%rip), %rsi      # 0xf474
movq %r15, %rdi
callq 0x8084