// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_compound.c
// Function: subtilis_parser_local
void subtilis_parser_local(subtilis_parser_t *p, subtilis_token_t *t,
			   subtilis_error_t *err)
{
	const char *tbuf;
	subtilis_type_t type;
	bool value_present;
	const subtilis_symbol_t *s;
	subtilis_exp_t *e = NULL;
	char *var_name = NULL;

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

	tbuf = subtilis_token_get_text(t);
	if ((t->type == SUBTILIS_TOKEN_KEYWORD) &&
	    (t->tok.keyword.type == SUBTILIS_KEYWORD_DIM)) {
		subtilis_parser_create_array(p, t, true, err);
		return;
	} else if (t->type != SUBTILIS_TOKEN_IDENTIFIER) {
		subtilis_error_set_id_expected(err, tbuf, p->l->stream->name,
					       p->l->line);
		return;
	}

	if ((p->current == p->main) && (p->level == 0)) {
		s = subtilis_symbol_table_lookup(p->st, tbuf);
		if (s) {
			subtilis_error_set_local_obscures_global(
			    err, tbuf, p->l->stream->name, p->l->line);
			return;
		}
	}

	if (subtilis_symbol_table_lookup(p->local_st, tbuf)) {
		subtilis_error_set_already_defined(
		    err, tbuf, p->l->stream->name, p->l->line);
		return;
	}

	var_name = malloc(strlen(tbuf) + 1);
	if (!var_name) {
		subtilis_error_set_oom(err);
		return;
	}
	strcpy(var_name, tbuf);
	subtilis_type_init_copy(&type, &t->tok.id_type, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		free(var_name);
		return;
	}

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

	tbuf = subtilis_token_get_text(t);
	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		prv_local_array_ref(p, t, var_name, &type, err);
		subtilis_type_free(&type);
		free(var_name);
		return;
	}

	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "{")) {
		prv_local_vector_ref(p, t, var_name, &type, err);
		subtilis_type_free(&type);
		free(var_name);
		return;
	}

	value_present =
	    (t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "=");
	if (subtilis_type_if_is_numeric(&type)) {
		if (!value_present) {
			e = subtilis_type_if_zero(p, &type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		} else {
			e = subtilis_parser_assign_local_num(p, t, var_name,
							     &type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		}
		(void)subtilis_symbol_table_insert_reg(
		    p->local_st, var_name, &type, e->exp.ir_op.reg, err);
	} else if (type.type == SUBTILIS_TYPE_FN) {
		if (!value_present)
			subtilis_parser_zero_local_fn(p, t, var_name, &type,
						      err);
		else
			subtilis_parser_assign_local_fn(p, t, var_name, &type,
							err);
	} else if (subtilis_type_if_is_reference(&type)) {
		s = subtilis_symbol_table_insert(p->local_st, var_name, &type,
						 err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		if (!value_present) {
			subtilis_type_if_zero_ref(
			    p, &type, SUBTILIS_IR_REG_LOCAL, s->loc, true, err);
		} else {
			e = subtilis_parser_expression(p, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			subtilis_type_if_new_ref(
			    p, &type, SUBTILIS_IR_REG_LOCAL, s->loc, e, err);
			e = NULL;
		}
	} else if (type.type == SUBTILIS_TYPE_REC) {
		subtilis_complete_custom_type(p, var_name, &type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		if (value_present) {
			subtilis_parser_rec_init(p, t, &type, var_name, true,
						 true, err);
		} else {
			s = subtilis_symbol_table_insert(p->local_st, var_name,
							 &type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			subtilis_rec_type_zero(p, &type, SUBTILIS_IR_REG_LOCAL,
					       s->loc, true, err);
		}
	} else {
		subtilis_error_set_assertion_failed(err);
	}

cleanup:

	subtilis_type_free(&type);
	subtilis_exp_delete(e);
	free(var_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x12eda
cmpl $0x0, (%r14)
je 0x1da54
addq $0x148, %rsp            # imm = 0x148
jmp 0x1db29
movq %r12, %rdi
callq 0x12ad0
movq %rax, %r13
movl (%r12), %eax
cmpl $0x6, %eax
je 0x1daa2
cmpl $0x1, %eax
jne 0x1daf3
cmpl $0x1f, 0x8(%r12)
jne 0x1da9d
movq %r15, %rdi
movq %r12, %rsi
movl $0x1, %edx
movq %r14, %rcx
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17067
cmpl $0x6, %eax
jne 0x1daf3
movq 0x48(%r15), %rax
cmpq 0x50(%r15), %rax
jne 0x1dab7
cmpq $0x0, 0x78(%r15)
je 0x1dbaa
movq 0x68(%r15), %rdi
movq %r13, %rsi
callq 0x2eec8
testq %rax, %rax
je 0x1db34
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x55b74(%rip), %rax     # 0x7364e
leaq 0x56314(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x20, %esi
movq %r13, %rdx
pushq $0x9e
jmp 0x1db1c
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x55b49(%rip), %rax     # 0x7364e
leaq 0x562e9(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x12, %esi
movq %r13, %rdx
pushq $0x8f
pushq %rax
callq 0x1442a
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x1dbed
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
callq 0x12070
leaq 0x8(%r12), %rsi
movq %rsp, %rdi
movq %r14, %rdx
callq 0x2f72e
cmpl $0x0, (%r14)
jne 0x1db9d
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
je 0x1dc17
xorl %r12d, %r12d
movq %rsp, %rdi
callq 0x2f843
movq %r12, %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x122c0
jmp 0x1da48
movq 0x60(%r15), %rdi
movq %r13, %rsi
callq 0x2eec8
testq %rax, %rax
je 0x1dab7
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x55a7d(%rip), %rax     # 0x7364e
leaq 0x5621d(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x52, %esi
movq %r13, %rdx
pushq $0x97
jmp 0x1db1c
leaq 0x55a5a(%rip), %rdx     # 0x7364e
movq %r14, %rdi
movl $0x1, %esi
movl $0xa4, %ecx
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movq %r12, %rdi
callq 0x12ad0
movl (%r12), %ebp
cmpl $0x2, %ebp
jne 0x1dc7a
movq %rax, %r13
leaq 0x565e0(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x1dd77
cmpl $0x2, %ebp
jne 0x1dc7a
leaq 0x58a03(%rip), %rsi     # 0x76651
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x1ddf2
cmpl $0x2, %ebp
jne 0x1dc7a
leaq 0x5599a(%rip), %rsi     # 0x73604
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
sete %bpl
jmp 0x1dc7c
xorl %ebp, %ebp
movq %rsp, %rdi
callq 0x37676
testb %al, %al
je 0x1dca3
testb %bpl, %bpl
je 0x1dccb
movq %rsp, %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x1803b
jmp 0x1dcd9
cmpl $0x9, (%rsp)
jne 0x1dd05
movq %rsp, %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
testb %bpl, %bpl
je 0x1dd90
callq 0x18197
jmp 0x1db8a
movq %rsp, %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x35f70
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x1db8d
movq 0x68(%r15), %rdi
movq 0x148(%r12), %rcx
movq %rsp, %rdx
movq %rbx, %rsi
movq %r14, %r8
callq 0x2ec2e
jmp 0x1db8d
movq %rsp, %rdi
callq 0x37833
testb %al, %al
je 0x1dd9a
movq 0x68(%r15), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e6e8
cmpl $0x0, (%r14)
jne 0x1db8a
movq %rax, %r13
testb %bpl, %bpl
je 0x1de34
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1eb88
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x1db8d
movq (%r13), %rcx
movq %rsp, %rsi
movl $0x2, %edx
movq %r15, %rdi
movq %r12, %r8
movq %r14, %r9
callq 0x3600f
jmp 0x1db8a
movq %rsp, %r13
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq %r14, %r8
callq 0x1de93
jmp 0x1de09
callq 0x18103
jmp 0x1db8a
cmpl $0x16, (%rsp)
jne 0x1de16
movq %rsp, %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
callq 0x1f7e6
cmpl $0x0, (%r14)
jne 0x1db8a
testb %bpl, %bpl
je 0x1de56
subq $0x8, %rsp
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
movl $0x1, %r8d
movl $0x1, %r9d
pushq %r14
callq 0x29e86
addq $0x10, %rsp
jmp 0x1db8a
movq %rsp, %r13
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq %r14, %r8
callq 0x1dfeb
movq %r13, %rdi
callq 0x2f843
jmp 0x1db9d
leaq 0x55831(%rip), %rdx     # 0x7364e
movq %r14, %rdi
movl $0xf, %esi
movl $0xfa, %ecx
callq 0x145f4
jmp 0x1db8a
movq (%r13), %rcx
movq %rsp, %rsi
movl $0x2, %edx
movq %r15, %rdi
movl $0x1, %r8d
movq %r14, %r9
callq 0x35fa9
jmp 0x1db8a
movq 0x68(%r15), %rdi
movq %rsp, %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2e6e8
cmpl $0x0, (%r14)
jne 0x1db8a
movq (%rax), %rcx
movq %rsp, %rsi
movl $0x2, %edx
movq %r15, %rdi
movl $0x1, %r8d
movq %r14, %r9
callq 0x45cd5
jmp 0x1db8a