// File: /workspace/github_c_makefile_star2_O3/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), %r15
movl (%r15), %r14d
movl %r14d, %eax
andl $-0x2, %eax
addq $0x20, %r15
cmpl $0x44, %eax
je 0x9876
movl $0x1, %edi
movl $0x50, %esi
callq 0x10d0
movq %rax, %r13
leal -0x35(%r14), %eax
cmpl $0x9, %eax
ja 0x98bd
leaq 0x6ae2(%rip), %rcx      # 0x1038c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %eax
jmp 0x99b9
cmpl $0x43, %r14d
je 0x99e8
cmpl $0x4a, %r14d
jne 0x9ae3
leaq -0x30(%rbp), %rbx
movq %r15, (%rbx)
leaq 0x6ad5(%rip), %rdx      # 0x103b4
movq %rbx, %rdi
movl $0x18, %esi
callq 0x9563
xorl %eax, %eax
cmpl $0x3a, %r14d
movq (%rbx), %r15
movq -0x18(%r15), %rcx
setne %al
addl $0x5, %eax
movl %eax, (%r13)
movq %rcx, 0x30(%r13)
movl (%r15), %ecx
cmpl $0x1e, %ecx
jne 0x99c2
movl %ecx, -0x34(%rbp)
movq %r12, -0x40(%rbp)
addq $0x20, %r15
movq %r15, -0x30(%rbp)
callq 0x5d33
movq %r13, -0x48(%rbp)
movq %rax, 0x38(%r13)
movq -0x30(%rbp), %r15
cmpl $0x1f, (%r15)
je 0x99a3
movq %rax, %r12
leaq -0xa0(%rbp), %r13
leaq 0x6a8f(%rip), %r14      # 0x103d9
movq %r13, %rdi
movq %rbx, %rsi
leaq -0x50(%rbp), %rdx
callq 0x9cf0
movq %rbx, %rdi
movl $0x1a, %esi
movq %r14, %rdx
callq 0x9563
movl $0x1, %edi
movl $0x58, %esi
callq 0x10d0
movl $0xa, %ecx
movq %rax, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x50(%rbp), %rcx
movq %rcx, 0x50(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x5d9b
movq -0x30(%rbp), %r15
cmpl $0x1f, (%r15)
jne 0x994a
addq $0x20, %r15
movq -0x40(%rbp), %r12
movq -0x48(%rbp), %r13
movl -0x34(%rbp), %ecx
jmp 0x99da
movl $0x7, %eax
movl %eax, (%r13)
jmp 0x9ab9
addq $-0x20, %r15
movl 0x20(%r15), %eax
addq $0x20, %r15
andl $-0x2, %eax
cmpl $0x44, %eax
je 0x99c6
movq %r15, (%r12)
cmpl $0x1e, %ecx
je 0x9ab9
jmp 0x9ad1
leaq -0x30(%rbp), %rbx
movq %r15, (%rbx)
leaq 0x6a19(%rip), %rdx      # 0x1040f
movq %rbx, %rdi
movl $0x18, %esi
callq 0x9563
movq (%rbx), %r15
movq -0x18(%r15), %rax
movl $0x8, (%r13)
movq %rax, 0x40(%r13)
movl (%r15), %ecx
cmpl $0x1e, %ecx
movq %r13, -0x48(%rbp)
jne 0x9a8b
movl %ecx, -0x34(%rbp)
movq %r12, -0x40(%rbp)
addq $0x20, %r15
movq %r15, (%rbx)
callq 0x5d33
movq %rax, %r14
movq %rax, 0x48(%r13)
leaq 0x69e4(%rip), %r12      # 0x10427
movq %rbx, %rdi
movl $0x18, %esi
movq %r12, %rdx
callq 0x9563
movq -0x30(%rbp), %rax
movq -0x18(%rax), %rsi
movq %r14, %rdi
callq 0x5d9b
movq -0x30(%rbp), %r15
movl (%r15), %eax
cmpl $0xa, %eax
je 0x9a76
cmpl $0x1f, %eax
jne 0x9a43
jmp 0x9aa5
leaq 0x20(%r15), %rax
movq %rax, -0x30(%rbp)
cmpl $0x1f, 0x20(%r15)
jne 0x9a43
addq $0x40, %r15
jmp 0x9aa9
addq $-0x20, %r15
movl 0x20(%r15), %eax
addq $0x20, %r15
andl $-0x2, %eax
cmpl $0x44, %eax
je 0x9a8f
movq %r15, (%r12)
jmp 0x9ab0
addq $0x20, %r15
movq -0x40(%rbp), %r12
movl -0x34(%rbp), %ecx
cmpl $0x1e, %ecx
movq -0x48(%rbp), %r13
jne 0x9ad1
addq $-0x20, %r15
movl 0x20(%r15), %eax
addq $0x20, %r15
andl $-0x2, %eax
cmpl $0x44, %eax
je 0x9abd
movq %r15, (%r12)
movq %r13, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $-0x20, %r15
leaq 0x6966(%rip), %rsi      # 0x10454
movq %r15, %rdi
callq 0x9478