// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rdx, %rsi
callq 0x13a49
cmpl $0x0, (%rbx)
je 0x14276
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
xorl %r12d, %r12d
movq 0x40(%r15), %rax
cmpq 0x360(%r15), %rax
je 0x142e3
movq 0x368(%r15), %rcx
movb (%rcx,%rax), %r13b
movl %r13d, %eax
andb $-0x21, %al
addb $-0x41, %al
cmpb $0x1a, %al
jb 0x142b0
leal -0x30(%r13), %eax
cmpb $0xa, %al
setae %al
cmpb $0x5f, %r13b
setne %cl
testb %al, %cl
jne 0x142e3
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x13cb6
cmpl $0x0, (%rbx)
jne 0x14268
cmpq $0x3, %r12
ja 0x142ce
movb %r13b, 0xb(%rsp,%r12)
incq %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x13a49
cmpl $0x0, (%rbx)
je 0x14279
jmp 0x14268
movq %r14, %rdi
callq 0x12ad0
cmpq $0x1, %r12
ja 0x14327
movq 0x30(%r15), %r8
movl 0x38(%r15), %r9d
leaq 0x5dd54(%rip), %r10     # 0x72054
leaq 0x5faee(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0xe, %esi
movq %rax, %rdx
pushq $0x249                  # imm = 0x249
pushq %r10
callq 0x1442a
addq $0x20, %rsp
jmp 0x1426c
cmpq $0x4, %r12
movl $0x4, %ecx
cmovbq %r12, %rcx
movb $0x0, 0xb(%rsp,%rcx)
movzwl 0xb(%rsp), %ecx
xorl $0x4552, %ecx           # imm = 0x4552
movzbl 0xd(%rsp), %edx
xorl $0x43, %edx
orw %cx, %dx
je 0x143bf
cmpw $0x4e46, 0xb(%rsp)      # imm = 0x4E46
je 0x1438c
cmpl $0x434f5250, 0xb(%rsp)  # imm = 0x434F5250
je 0x1438c
movq 0x30(%r15), %r8
movl 0x38(%r15), %r9d
leaq 0x5dce1(%rip), %r10     # 0x72054
leaq 0x5fa7b(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0xe, %esi
movq %rax, %rdx
pushq $0x25e                  # imm = 0x25E
jmp 0x14317
movl $0x9, 0x8(%r14)
movq $0x0, 0x18(%r14)
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x143de
movl $0x8, (%rax)
jmp 0x14268
addq $0x8, %r14
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2fe7d
leaq 0x5dc6f(%rip), %rdx     # 0x72054
movq %rbx, %rdi
movl $0x1, %esi
movl $0x267, %ecx            # imm = 0x267
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x145f4