// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq (%rdi), %r14
movq %r14, -0x30(%rbp)
movl (%r14), %r15d
movl %r15d, %eax
andl $-0x2, %eax
addq $0x20, %r14
cmpl $0x44, %eax
je 0x97c6
leaq -0x20(%r14), %rbx
movq %rbx, -0x30(%rbp)
movl $0x1, %edi
movl $0x50, %esi
callq 0x10d0
movq %rax, %r12
leal -0x35(%r15), %eax
cmpl $0x9, %eax
ja 0x9818
leaq 0x6bba(%rip), %rcx      # 0x103bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, (%r12)
jmp 0x992b
cmpl $0x43, %r15d
je 0x9966
cmpl $0x4a, %r15d
jne 0x9a6d
leaq -0x30(%rbp), %rbx
movq %r14, (%rbx)
leaq 0x6baa(%rip), %rdx      # 0x103e4
movq %rbx, %rdi
movl $0x18, %esi
callq 0x94af
xorl %ecx, %ecx
cmpl $0x3a, %r15d
movq (%rbx), %rax
movq -0x18(%rax), %rdx
setne %cl
addl $0x5, %ecx
movl %ecx, (%r12)
movq %rdx, 0x30(%r12)
movl (%rax), %edx
cmpl $0x1e, %edx
jne 0x9934
movl %edx, -0x3c(%rbp)
movq %r13, -0x48(%rbp)
addq $0x20, %rax
movq %rax, -0x30(%rbp)
callq 0x5b39
movq %rax, %r15
movq %r12, -0x38(%rbp)
movq %rax, 0x38(%r12)
movq -0x30(%rbp), %rax
cmpl $0x1f, (%rax)
je 0x9904
leaq -0xa0(%rbp), %r12
leaq -0x30(%rbp), %r13
leaq -0x50(%rbp), %rbx
leaq 0x6b5c(%rip), %r14      # 0x10409
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x9c8d
movq %r13, %rdi
movl $0x1a, %esi
movq %r14, %rdx
callq 0x94af
movl $0x1, %edi
movl $0x58, %esi
callq 0x10d0
movl $0xa, %ecx
movq %rax, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x50(%rbp), %rcx
movq %rcx, 0x50(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x5ba7
movq -0x30(%rbp), %rax
cmpl $0x1f, (%rax)
jne 0x98ad
addq $0x20, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %r13
movq -0x38(%rbp), %r12
movl -0x3c(%rbp), %edx
jmp 0x9958
movl $0x4, (%r12)
jmp 0x992b
movl $0x7, (%r12)
movq %r14, -0x30(%rbp)
jmp 0x9a3c
movq $0x0, 0x38(%r12)
addq $-0x20, %rax
movl 0x20(%rax), %ecx
addq $0x20, %rax
andl $-0x2, %ecx
cmpl $0x44, %ecx
je 0x9941
movq %rax, -0x30(%rbp)
movq %rax, (%r13)
cmpl $0x1e, %edx
je 0x9a3c
jmp 0x9a5b
leaq -0x30(%rbp), %rbx
movq %r14, (%rbx)
leaq 0x6acb(%rip), %rdx      # 0x1043f
movq %rbx, %rdi
movl $0x18, %esi
callq 0x94af
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl $0x8, (%r12)
movq %rcx, 0x40(%r12)
movq %r12, %r15
movl (%rax), %r12d
cmpl $0x1e, %r12d
movq %r15, -0x38(%rbp)
jne 0x9a05
addq $0x20, %rax
movq %rax, (%rbx)
callq 0x5b39
movq %rax, %r14
movq %rax, 0x48(%r15)
leaq 0x6a98(%rip), %r15      # 0x10457
movq %rbx, %rdi
movl $0x18, %esi
movq %r15, %rdx
callq 0x94af
movq -0x30(%rbp), %rax
movq -0x18(%rax), %rsi
movq %r14, %rdi
callq 0x5ba7
movq -0x30(%rbp), %rax
movl (%rax), %ecx
cmpl $0xa, %ecx
je 0x99f1
cmpl $0x1f, %ecx
jne 0x99bf
jmp 0x9a2a
leaq 0x20(%rax), %rcx
movq %rcx, -0x30(%rbp)
cmpl $0x1f, 0x20(%rax)
jne 0x99bf
addq $0x40, %rax
jmp 0x9a2e
movq $0x0, 0x48(%r15)
addq $-0x20, %rax
movl 0x20(%rax), %ecx
addq $0x20, %rax
andl $-0x2, %ecx
cmpl $0x44, %ecx
je 0x9a11
movq %rax, -0x30(%rbp)
movq %rax, (%r13)
jmp 0x9a32
addq $0x20, %rax
movq %rax, -0x30(%rbp)
cmpl $0x1e, %r12d
movq -0x38(%rbp), %r12
jne 0x9a5b
movq -0x30(%rbp), %rax
addq $-0x20, %rax
movl 0x20(%rax), %ecx
addq $0x20, %rax
andl $-0x2, %ecx
cmpl $0x44, %ecx
je 0x9a44
movq %rax, -0x30(%rbp)
movq %rax, (%r13)
movq %r12, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6a10(%rip), %rsi      # 0x10484
movq %rbx, %rdi
callq 0x93c4