// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/common/lexer.c
// Function: prv_complete_custom_type
static void prv_complete_custom_type(subtilis_lexer_t *l, subtilis_token_t *t,
				     subtilis_error_t *err)
{
	char ch;
	char prefix[5];
	size_t i = 0;
	const char *tbuf;

	for (;;) {
		prv_ensure_input(l, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
		if (l->index == l->buf_end)
			break;

		ch = l->buffer[l->index];
		if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||
		      (ch >= '0' && ch <= '9') || (ch == '_')))
			break;
		prv_set_next_with_err(l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		if (i < 4)
			prefix[i] = ch;
		i++;
	}

	tbuf = subtilis_token_get_text(t);
	if (i < 2) {
		subtilis_error_set_bad_type_name(err, tbuf, l->stream->name,
						 l->line);
		return;
	}
	if (i > 4)
		i = 4;
	prefix[i] = 0;

	/*
	 * The lexer doesn't know the complete type of the token as this
	 * information is stored in the symbol table to which it doesn't have
	 * access.  It does know however, that we have a custom type and the
	 * type is either a record, a function or a procedure.
	 */

	if (!strncmp(prefix, "REC", 3)) {
		subtilis_type_init_rec(&t->tok.id_type, tbuf, err);
		return;
	}

	if (strncmp(prefix, "FN", 2) && strncmp(prefix, "PROC", 4)) {
		subtilis_error_set_bad_type_name(err, tbuf, l->stream->name,
						 l->line);
		return;
	}

	t->tok.id_type.type = SUBTILIS_TYPE_FN;
	t->tok.id_type.params.fn.num_params = 0;
	t->tok.id_type.params.fn.ret_val =
	    calloc(1, sizeof(*t->tok.id_type.params.fn.ret_val));
	if (!t->tok.id_type.params.fn.ret_val) {
		subtilis_error_set_oom(err);
		return;
	}
	t->tok.id_type.params.fn.ret_val->type = SUBTILIS_TYPE_VOID;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x13890
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x153f7
jmp 0x15626
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x360(%rcx), %rax
jne 0x15411
jmp 0x154ad
movq -0x8(%rbp), %rax
movq 0x368(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
movsbl -0x19(%rbp), %eax
cmpl $0x41, %eax
jl 0x1543c
movsbl -0x19(%rbp), %eax
cmpl $0x5a, %eax
jle 0x1546b
movsbl -0x19(%rbp), %eax
cmpl $0x61, %eax
jl 0x1544e
movsbl -0x19(%rbp), %eax
cmpl $0x7a, %eax
jle 0x1546b
movsbl -0x19(%rbp), %eax
cmpl $0x30, %eax
jl 0x15460
movsbl -0x19(%rbp), %eax
cmpl $0x39, %eax
jle 0x1546b
movsbl -0x19(%rbp), %eax
cmpl $0x5f, %eax
je 0x1546b
jmp 0x154ad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x14700
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1548a
jmp 0x15626
cmpq $0x4, -0x28(%rbp)
jae 0x1549c
movb -0x19(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, -0x1e(%rbp,%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x153dc
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x30(%rbp)
cmpq $0x2, -0x28(%rbp)
jae 0x15502
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movl 0x38(%rax), %r9d
movl $0xe, %esi
leaq 0x95d91(%rip), %rcx     # 0xab276
leaq 0x93b98(%rip), %rax     # 0xa9084
movq %rax, (%rsp)
movl $0x249, 0x8(%rsp)       # imm = 0x249
callq 0x156d0
jmp 0x15626
cmpq $0x4, -0x28(%rbp)
jbe 0x15511
movq $0x4, -0x28(%rbp)
movq -0x28(%rbp), %rax
movb $0x0, -0x1e(%rbp,%rax)
leaq -0x1e(%rbp), %rdi
leaq 0x97270(%rip), %rsi     # 0xac795
movl $0x3, %edx
callq 0x12050
cmpl $0x0, %eax
jne 0x1554e
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x3ebc0
jmp 0x15626
leaq -0x1e(%rbp), %rdi
leaq 0x94fa1(%rip), %rsi     # 0xaa4fa
movl $0x2, %edx
callq 0x12050
cmpl $0x0, %eax
je 0x155c0
leaq -0x1e(%rbp), %rdi
leaq 0x94aa8(%rip), %rsi     # 0xaa01b
movl $0x4, %edx
callq 0x12050
cmpl $0x0, %eax
je 0x155c0
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movl 0x38(%rax), %r9d
movl $0xe, %esi
leaq 0x95cd0(%rip), %rcx     # 0xab276
leaq 0x93ad7(%rip), %rax     # 0xa9084
movq %rax, (%rsp)
movl $0x25e, 0x8(%rsp)       # imm = 0x25E
callq 0x156d0
jmp 0x15626
movq -0x10(%rbp), %rax
movl $0x9, 0x8(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12130
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x15618
movq -0x18(%rbp), %rdi
movl $0x1, %esi
leaq 0x93a78(%rip), %rdx     # 0xa9084
movl $0x267, %ecx            # imm = 0x267
callq 0x158e0
jmp 0x15626
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x8, (%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)