// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/parser_exp.c
// Function: prv_lookup_var
static subtilis_exp_t *prv_lookup_var(subtilis_parser_t *p, subtilis_token_t *t,
				      const char *tbuf, subtilis_error_t *err)
{
	const subtilis_symbol_t *s;
	subtilis_exp_t *e = NULL;
	subtilis_exp_t *e1 = NULL;
	char *var_name = NULL;
	size_t mem_reg = SUBTILIS_IR_REG_LOCAL;

	tbuf = subtilis_token_get_text(t);
	var_name = malloc(strlen(tbuf) + 1);
	if (!var_name) {
		subtilis_error_set_oom(err);
		return NULL;
	}
	strcpy(var_name, tbuf);

	subtilis_lexer_get(p->l, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	s = subtilis_parser_get_symbol(p, var_name, &mem_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tbuf = subtilis_token_get_text(t);
	if ((s->t.type == SUBTILIS_TYPE_FN) &&
	    (t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		if (s->t.params.fn.ret_val->type == SUBTILIS_TYPE_VOID) {
			subtilis_error_set_expected(
			    err, "function", "procedure", p->l->stream->name,
			    p->l->line);
			goto cleanup;
		}
		e = subtilis_parser_call_ptr(p, t, s, var_name, mem_reg, err);
	} else if ((s->t.type == SUBTILIS_TYPE_REC) &&
		   (t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, ".")) {
		e = subtilis_parser_rec_exp(p, t, &s->t, mem_reg, s->loc, err);
	} else if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		e = subtils_parser_read_array(p, t, var_name, err);
	} else if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "{")) {
		e = subtils_parser_read_vector(p, t, var_name, err);
	} else {
		e = subtilis_var_lookup_var(p, var_name, err);
	}

	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * If our expression evaluates to a function pointer, which
	 * can be called, or a container type like an array or a
	 * record, we need to check to see whether we're performing
	 * a chained operation on the expression.
	 */

	while ((e->type.type == SUBTILIS_TYPE_FN) ||
	       (e->type.type == SUBTILIS_TYPE_REC) ||
	       subtilis_type_if_is_array(&e->type) ||
	       subtilis_type_if_is_vector(&e->type)) {
		tbuf = subtilis_token_get_text(t);
		if ((e->type.type == SUBTILIS_TYPE_FN) &&
		    (t->type == SUBTILIS_TOKEN_OPERATOR) &&
		    !strcmp(tbuf, "(")) {
			e1 = subtilis_parser_call_known_ptr(
			    p, t, &e->type, e->exp.ir_op.reg, err);
			if ((err->type == SUBTILIS_ERROR_OK) && !e1) {
				subtilis_error_set_expected(
				    err, "function", "procedure",
				    p->l->stream->name, p->l->line);
				goto cleanup;
			}
		} else if ((e->type.type == SUBTILIS_TYPE_REC) &&
			   (t->type == SUBTILIS_TOKEN_OPERATOR) &&
			   !strcmp(tbuf, ".")) {
			e1 = subtilis_parser_rec_exp(p, t, &e->type,
						     e->exp.ir_op.reg, 0, err);
		} else if (subtilis_type_if_is_array(&e->type) &&
			   (t->type == SUBTILIS_TOKEN_OPERATOR) &&
			   !strcmp(tbuf, "(")) {
			e1 = subtils_parser_read_array_with_type(
			    p, t, &e->type, e->exp.ir_op.reg, 0, "temporary",
			    err);
		} else if (subtilis_type_if_is_vector(&e->type) &&
			   (t->type == SUBTILIS_TOKEN_OPERATOR) &&
			   !strcmp(tbuf, "{")) {
			e1 = subtils_parser_read_vector_with_type(
			    p, t, &e->type, e->exp.ir_op.reg, 0, "temporary",
			    err);
		} else {
			break;
		}

		subtilis_exp_delete(e);
		if (err->type != SUBTILIS_ERROR_OK) {
			e = NULL;
			goto cleanup;
		}
		e = e1;
	}

cleanup:

	free(var_name);

	return e;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x2, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x120d0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x121b0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2732c
movq -0x28(%rbp), %rdi
movl $0x1, %esi
leaq 0x835d7(%rip), %rdx     # 0xaa8ec
movl $0x102, %ecx            # imm = 0x102
callq 0x158e0
movq $0x0, -0x8(%rbp)
jmp 0x27795
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x12060
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x133f0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2735b
jmp 0x27784
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rcx
leaq -0x50(%rbp), %rdx
callq 0x24480
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x27382
jmp 0x27784
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x9, 0x8(%rax)
jne 0x2743c
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2743c
movq -0x20(%rbp), %rdi
leaq 0x83ee7(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x2743c
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x8, (%rax)
jne 0x27416
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x8354a(%rip), %rdx     # 0xaa93c
leaq 0x8354c(%rip), %rcx     # 0xaa945
leaq 0x834ec(%rip), %rax     # 0xaa8ec
movq %rax, (%rsp)
movl $0x115, 0x8(%rsp)       # imm = 0x115
callq 0x156d0
jmp 0x27784
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x28(%rbp), %r9
callq 0x20090
movq %rax, -0x38(%rbp)
jmp 0x2751e
movq -0x30(%rbp), %rax
cmpl $0x16, 0x8(%rax)
jne 0x27491
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x27491
movq -0x20(%rbp), %rdi
leaq 0x830bb(%rip), %rsi     # 0xaa515
callq 0x12140
cmpl $0x0, %eax
jne 0x27491
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq -0x28(%rbp), %r9
callq 0x349a0
movq %rax, -0x38(%rbp)
jmp 0x2751c
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x274ca
movq -0x20(%rbp), %rdi
leaq 0x83df7(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x274ca
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x17a70
movq %rax, -0x38(%rbp)
jmp 0x2751a
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x27503
movq -0x20(%rbp), %rdi
leaq 0x8612d(%rip), %rsi     # 0xad60b
callq 0x12140
cmpl $0x0, %eax
jne 0x27503
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x182d0
movq %rax, -0x38(%rbp)
jmp 0x27518
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x47240
movq %rax, -0x38(%rbp)
jmp 0x2751a
jmp 0x2751c
jmp 0x2751e
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2752c
jmp 0x27784
jmp 0x2752e
movq -0x38(%rbp), %rcx
movb $0x1, %al
cmpl $0x9, (%rcx)
movb %al, -0x51(%rbp)
je 0x2756b
movq -0x38(%rbp), %rcx
movb $0x1, %al
cmpl $0x16, (%rcx)
movb %al, -0x51(%rbp)
je 0x2756b
movq -0x38(%rbp), %rdi
callq 0x49ff0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x51(%rbp)
jne 0x2756b
movq -0x38(%rbp), %rdi
callq 0x4a040
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x27577
jmp 0x27782
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x9, (%rax)
jne 0x2763a
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2763a
movq -0x20(%rbp), %rdi
leaq 0x83cf3(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x2763a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rcx
movq -0x28(%rbp), %r8
callq 0x1fc30
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x27635
cmpq $0x0, -0x40(%rbp)
jne 0x27635
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x8332b(%rip), %rdx     # 0xaa93c
leaq 0x8332d(%rip), %rcx     # 0xaa945
leaq 0x832cd(%rip), %rax     # 0xaa8ec
movq %rax, (%rsp)
movl $0x13b, 0x8(%rsp)       # imm = 0x13B
callq 0x156d0
jmp 0x27784
jmp 0x27759
movq -0x38(%rbp), %rax
cmpl $0x16, (%rax)
jne 0x2768f
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2768f
movq -0x20(%rbp), %rdi
leaq 0x82ebe(%rip), %rsi     # 0xaa515
callq 0x12140
cmpl $0x0, %eax
jne 0x2768f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rcx
movq -0x28(%rbp), %r9
xorl %eax, %eax
movl %eax, %r8d
callq 0x349a0
movq %rax, -0x40(%rbp)
jmp 0x27757
movq -0x38(%rbp), %rdi
callq 0x49ff0
testb $0x1, %al
jne 0x2769e
jmp 0x276f0
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x276f0
movq -0x20(%rbp), %rdi
leaq 0x83bea(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x276f0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rcx
movq -0x28(%rbp), %rax
xorl %r8d, %r8d
leaq 0x8326e(%rip), %r9      # 0xaa94f
movq %rax, (%rsp)
callq 0x17b50
movq %rax, -0x40(%rbp)
jmp 0x27755
movq -0x38(%rbp), %rdi
callq 0x4a040
testb $0x1, %al
jne 0x276ff
jmp 0x27751
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x27751
movq -0x20(%rbp), %rdi
leaq 0x85ef8(%rip), %rsi     # 0xad60b
callq 0x12140
cmpl $0x0, %eax
jne 0x27751
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rcx
movq -0x28(%rbp), %rax
xorl %r8d, %r8d
leaq 0x8320d(%rip), %r9      # 0xaa94f
movq %rax, (%rsp)
callq 0x183b0
movq %rax, -0x40(%rbp)
jmp 0x27753
jmp 0x27782
jmp 0x27755
jmp 0x27757
jmp 0x27759
movq -0x38(%rbp), %rdi
callq 0x36ee0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x27775
movq $0x0, -0x38(%rbp)
jmp 0x27784
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x2752e
jmp 0x27784
movq -0x48(%rbp), %rdi
callq 0x12290
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nop