// File: /workspace/github_c_makefile_star2_O2/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 $0x298, %rsp            # imm = 0x298
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x12e0e
cmpl $0x0, (%r14)
je 0x1cfd8
addq $0x298, %rsp            # imm = 0x298
jmp 0x1d09e
movq %r12, %rdi
callq 0x12a25
movq %rax, %r13
movl (%r12), %eax
cmpl $0x6, %eax
je 0x1d044
cmpl $0x1, %eax
jne 0x1d01b
cmpl $0x1f, 0x8(%r12)
jne 0x1d01b
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x16dd3
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5060f(%rip), %rax     # 0x6d63c
leaq 0x50d91(%rip), %rcx     # 0x6ddc5
pushq $0x12
popq %rsi
movq %r14, %rdi
movq %r13, %rdx
pushq $0x8f
jmp 0x1d091
movq 0x48(%r15), %rax
cmpq 0x50(%r15), %rax
jne 0x1d059
cmpq $0x0, 0x78(%r15)
je 0x1d123
movq 0x68(%r15), %rdi
movq %r13, %rsi
callq 0x2d376
testq %rax, %rax
je 0x1d0a9
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x505c0(%rip), %rax     # 0x6d63c
leaq 0x50d42(%rip), %rcx     # 0x6ddc5
pushq $0x20
popq %rsi
movq %r14, %rdi
movq %r13, %rdx
pushq $0x9e
pushq %rax
callq 0x140cd
addq $0x2a8, %rsp            # imm = 0x2A8
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 0x1d164
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
callq 0x12070
leaq 0x8(%r12), %rsi
leaq 0x8(%rsp), %rdi
movq %r14, %rdx
callq 0x2db73
cmpl $0x0, (%r14)
jne 0x1d116
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
je 0x1d18c
xorl %r12d, %r12d
leaq 0x8(%rsp), %rdi
callq 0x2dc7c
movq %r12, %rdi
callq 0x29d88
movq %rbx, %rdi
callq 0x122c0
jmp 0x1cfcc
movq 0x60(%r15), %rdi
movq %r13, %rsi
callq 0x2d376
testq %rax, %rax
je 0x1d059
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x504f2(%rip), %rax     # 0x6d63c
leaq 0x50c74(%rip), %rcx     # 0x6ddc5
pushq $0x52
popq %rsi
movq %r14, %rdi
movq %r13, %rdx
pushq $0x97
jmp 0x1d091
leaq 0x504d1(%rip), %rdx     # 0x6d63c
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0xa4, %ecx
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1d22a
movzbl (%rax), %ecx
cmpl $0x7b, %ecx
je 0x1d220
cmpl $0x3d, %ecx
je 0x1d216
cmpl $0x28, %ecx
jne 0x1d22a
cmpb $0x0, 0x1(%rax)
jne 0x1d22a
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1d40b
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1d1ed
cmpb $0x29, (%rax)
jne 0x1d1ed
cmpb $0x0, 0x1(%rax)
je 0x1d4d3
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5043d(%rip), %r10     # 0x6d63c
leaq 0x50bbf(%rip), %rcx     # 0x6ddc5
pushq $0x16
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
pushq $0x2e
jmp 0x1d402
cmpb $0x0, 0x1(%rax)
sete %bpl
jmp 0x1d22c
cmpb $0x0, 0x1(%rax)
je 0x1d3ac
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x35655
testb %al, %al
je 0x1d257
testb %bpl, %bpl
je 0x1d282
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
callq 0x179c7
jmp 0x1d292
cmpl $0x9, 0x8(%rsp)
jne 0x1d2c0
leaq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %r8
testb %bpl, %bpl
je 0x1d332
callq 0x17b1f
jmp 0x1d101
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x33e86
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x1d104
movq 0x68(%r15), %rdi
movq 0x148(%r12), %rcx
leaq 0x8(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %r8
callq 0x2d0fe
jmp 0x1d104
leaq 0x8(%rsp), %rdi
callq 0x35808
testb %al, %al
je 0x1d33c
movq 0x68(%r15), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2cbb7
cmpl $0x0, (%r14)
jne 0x1d101
movq %rax, %r13
testb %bpl, %bpl
je 0x1d41a
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dfd5
movq %rax, %r12
cmpl $0x0, (%r14)
jne 0x1d104
movq (%r13), %rcx
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r12, %r8
movq %r14, %r9
callq 0x33f1f
jmp 0x1d101
callq 0x17a8b
jmp 0x1d101
cmpl $0x16, 0x8(%rsp)
jne 0x1d390
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
callq 0x1eb36
cmpl $0x0, (%r14)
jne 0x1d101
testb %bpl, %bpl
je 0x1d43a
subq $0x8, %rsp
leaq 0x10(%rsp), %rdx
pushq $0x1
popq %r8
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
movl %r8d, %r9d
pushq %r14
callq 0x288d1
popq %rax
popq %rcx
jmp 0x1d101
leaq 0x502a5(%rip), %rdx     # 0x6d63c
pushq $0xf
popq %rsi
movq %r14, %rdi
movl $0xfa, %ecx
callq 0x1429e
jmp 0x1d101
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1d40b
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1d3de
cmpb $0x7d, (%rax)
jne 0x1d3de
cmpb $0x0, 0x1(%rax)
je 0x1d477
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5024c(%rip), %r10     # 0x6d63c
leaq 0x50260(%rip), %rdx     # 0x6d657
pushq $0x1d
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
pushq $0x5b
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
leaq 0x8(%rsp), %rdi
callq 0x2dc7c
jmp 0x1d116
movq (%r13), %rcx
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
pushq $0x1
popq %r8
movq %r15, %rdi
movq %r14, %r9
callq 0x33ebd
jmp 0x1d101
movq 0x68(%r15), %rdi
leaq 0x8(%rsp), %rdx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x2cbb7
cmpl $0x0, (%r14)
jne 0x1d101
movq (%rax), %rcx
leaq 0x8(%rsp), %rsi
pushq $0x2
popq %rdx
pushq $0x1
popq %r8
movq %r15, %rdi
movq %r14, %r9
callq 0x433f5
jmp 0x1d101
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1d40b
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1d4a9
cmpb $0x3d, (%rax)
jne 0x1d4a9
cmpb $0x0, 0x1(%rax)
je 0x1d533
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x50181(%rip), %rax     # 0x6d63c
leaq 0x50d08(%rip), %rdx     # 0x6e1ca
leaq 0x508fc(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %r14, %rdi
pushq $0x67
jmp 0x1d52d
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1d40b
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1d505
cmpb $0x3d, (%rax)
jne 0x1d505
cmpb $0x0, 0x1(%rax)
je 0x1d576
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x50125(%rip), %rax     # 0x6d63c
leaq 0x50cac(%rip), %rdx     # 0x6e1ca
leaq 0x508a0(%rip), %rcx     # 0x6ddc5
pushq $0x15
popq %rsi
movq %r14, %rdi
pushq $0x3a
pushq %rax
jmp 0x1d404
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dfd5
cmpl $0x0, (%r14)
jne 0x1d40b
movq %rax, %r12
leaq 0x8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
movq %r14, %rdx
callq 0x34066
cmpl $0x0, (%r14)
je 0x1d5b0
movq %r12, %rdi
callq 0x29d88
jmp 0x1d40b
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dfd5
cmpl $0x0, (%r14)
jne 0x1d40b
movq %rax, %r12
leaq 0x8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
movq %r14, %rdx
callq 0x34015
cmpl $0x0, (%r14)
jne 0x1d40b
leaq 0x150(%rsp), %r13
pushq $0x1
popq %r8
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r14, %r9
callq 0x178d0
movq %r13, %rdi
callq 0x2dc7c
jmp 0x1d40b