// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/parser_assignment.c
// Function: prv_assign_array_or_vector
static void prv_assign_array_or_vector(subtilis_parser_t *p,
				       subtilis_token_t *t, size_t dims,
				       subtilis_exp_t **indices,
				       const char *var_name,
				       const subtilis_type_t *array_type,
				       bool array, subtilis_error_t *err)
{
	const char *tbuf;
	size_t i;
	subtilis_assign_type_t at;
	subtilis_ir_operand_t op1;
	const subtilis_symbol_t *s;
	subtilis_array_desc_t desc;
	subtilis_exp_t *e = NULL;
	bool new_global = false;
	bool local;
	subtilis_type_t el_type;
	char scratch[32];

	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_assign_col_field(p, t, dims, indices, var_name, array_type,
				     err);
		goto cleanup;
	}

	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		/*
		 * We have a procedure call, and not an assignment.
		 */

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

		e = subtilis_type_if_indexed_read(p, var_name, &s->t, op1.reg,
						  s->loc, indices, dims, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		(void)subtilis_parser_call_known_ptr(p, t, &e->type,
						     e->exp.ir_op.reg, err);
		goto cleanup;
	}

	at = prv_get_ass_op(p, t, err);
	if (err->type != SUBTILIS_ERROR_OK) {
		prv_missing_operator_error(p, tbuf, var_name, err);
		goto cleanup;
	}

	if ((dims == 0) && ((at == SUBTILIS_ASSIGN_TYPE_PLUS_EQUAL) ||
			    (at == SUBTILIS_ASSIGN_TYPE_MINUS_EQUAL))) {
		subtilis_error_set_expected(err, ":= or =", tbuf,
					    p->l->stream->name, p->l->line);
		goto cleanup;
	}

	subtilis_parser_lookup_assignment_var(p, t, var_name, &s, &op1.reg,
					      &new_global, err);
	if (err->type == SUBTILIS_ERROR_UNKNOWN_VARIABLE ||
	    err->type == SUBTILIS_ERROR_VARIABLE_BAD_LEVEL) {
		if (at != SUBTILIS_ASSIGN_TYPE_CREATE_EQUAL)
			goto cleanup;
		subtilis_error_init(err);
		if (dims != 0) {
			sprintf(scratch, "%zu", dims);
			subtilis_error_bad_index(
			    err, scratch, p->l->stream->name, p->l->line);
			goto cleanup;
		}
		e = subtilis_parser_expression(p, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_parser_create_array_ref(p, var_name, array_type, e,
						 true, err);
		return;
	} else if (err->type != SUBTILIS_ERROR_OK) {
		goto cleanup;
	}

	if (s && (array != subtilis_type_if_is_array(&s->t))) {
		if (array)
			subtilis_error_set_expected(
			    err, "{", "(", p->l->stream->name, p->l->line);
		else
			subtilis_error_set_expected(
			    err, "(", "{", p->l->stream->name, p->l->line);
		goto cleanup;
	}

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

	/*
	 * Check to see whether we're resetting a structure.
	 */

	tbuf = subtilis_token_get_text(t);
	if (((array_type->type == SUBTILIS_TYPE_ARRAY_REC) ||
	     (array_type->type == SUBTILIS_TYPE_VECTOR_REC)) &&
	    (dims > 0) && !strcmp(tbuf, "(")) {
		e = subtilis_type_if_indexed_address(
		    p, var_name, &s->t, op1.reg, s->loc, indices, dims, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_type_if_element_type(p, &s->t, &el_type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_parser_rec_reset(p, t, &el_type, e->exp.ir_op.reg, 0,
					  err);
		subtilis_type_free(&el_type);
		goto cleanup;
	}

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

	if (new_global) {
		if (dims != 0) {
			subtilis_error_set_unknown_variable(
			    err, var_name, p->l->stream->name, p->l->line);
			goto cleanup;
		}
		local = (at == SUBTILIS_ASSIGN_TYPE_CREATE_EQUAL);
		if (!local && p->current->proc_called) {
			subtilis_error_set_global_after_proc(
			    err, var_name, p->l->stream->name, p->l->line);
			goto cleanup;
		}
		subtilis_parser_create_array_ref(p, var_name, array_type, e,
						 local, err);
		return;
	}

	switch (at) {
	case SUBTILIS_ASSIGN_TYPE_EQUAL:
		if (dims == 0) {
			/* We're assigning an array reference */

			desc.name = s->key;
			desc.loc = s->loc;
			desc.reg = op1.reg;
			desc.t = &s->t;
			subtilis_parser_array_assign_reference(p, t, &desc, e,
							       err);
		} else {
			subtilis_type_if_indexed_write(p, var_name, &s->t,
						       op1.reg, s->loc, e,
						       indices, dims, err);
		}
		e = NULL;
		break;
	case SUBTILIS_ASSIGN_TYPE_PLUS_EQUAL:
		subtilis_type_if_indexed_add(p, var_name, &s->t, op1.reg,
					     s->loc, e, indices, dims, err);
		e = NULL;
		break;
	case SUBTILIS_ASSIGN_TYPE_MINUS_EQUAL:
		subtilis_type_if_indexed_sub(p, var_name, &s->t, op1.reg,
					     s->loc, e, indices, dims, err);
		e = NULL;
		break;
	case SUBTILIS_ASSIGN_TYPE_CREATE_EQUAL:
		subtilis_error_set_already_defined(
		    err, var_name, p->l->stream->name, p->l->line);
		break;
	default:
		subtilis_error_set_assertion_failed(err);
		break;
	}

cleanup:

	subtilis_exp_delete(e);
	for (i = 0; i < dims; i++)
		subtilis_exp_delete(indices[i]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r9, 0x40(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %rbp
movq 0x1d8(%rsp), %r15
movb 0x1d0(%rsp), %r12b
movb $0x0, 0xf(%rsp)
movq (%rdi), %rdi
movq %r15, %rdx
callq 0x12e0e
cmpl $0x0, (%r15)
jne 0x192c6
movb %r12b, 0x30(%rsp)
movq %rbp, 0x10(%rsp)
movq %r13, %rdi
callq 0x12a25
movq %rax, %rbp
cmpl $0x2, (%r13)
jne 0x1924b
movzbl (%rbp), %eax
cmpl $0x28, %eax
je 0x19241
cmpl $0x2e, %eax
jne 0x1924b
cmpb $0x0, 0x1(%rbp)
jne 0x1924b
movq 0x40(%rsp), %rdi
movl (%rdi), %eax
cmpl $0xf, %eax
je 0x191cc
cmpl $0x15, %eax
jne 0x194b1
testq %r14, %r14
movq 0x10(%rsp), %rdi
je 0x194e9
subq $0x8, %rsp
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x27(%rsp), %r9
movq 0x28(%rsp), %r12
movq %r12, %rdx
pushq %r15
callq 0x17d87
popq %rax
popq %rcx
cmpl $0x0, (%r15)
jne 0x192c6
cmpb $0x1, 0x1f(%rsp)
jne 0x1960c
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5437a(%rip), %rax     # 0x6d5a4
leaq 0x54b94(%rip), %rcx     # 0x6ddc5
pushq $0x1b
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
pushq $0xd1
jmp 0x192be
cmpb $0x0, 0x1(%rbp)
je 0x193a5
movq %r13, %r12
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x198e0
cmpl $0x0, (%r15)
je 0x1927c
movq %r13, %rdi
movq %rbp, %rsi
movq 0x20(%rsp), %rdx
movq %r15, %rcx
callq 0x186fa
jmp 0x192c6
testq %r14, %r14
sete %dl
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
setb %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x192f8
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x542fb(%rip), %rax     # 0x6d5a4
leaq 0x54340(%rip), %rdx     # 0x6d5f0
pushq $0x1d
popq %rsi
movq %r15, %rdi
movq %rbp, %rcx
pushq $0x11e                  # imm = 0x11E
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0x29d88
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x192e6
movq (%rbx,%r15,8), %rdi
callq 0x29d88
incq %r15
jmp 0x192d3
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r13
subq $0x8, %rsp
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x17(%rsp), %r9
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq 0x28(%rsp), %rdx
pushq %r15
callq 0x17d87
popq %rax
popq %rcx
movl (%r15), %eax
testl %eax, %eax
je 0x19419
cmpl $0x3e, %eax
je 0x19339
cmpl $0x1b, %eax
jne 0x192c6
cmpl $0x3, %r13d
jne 0x192c6
movq %r15, %rdi
callq 0x140a4
testq %r14, %r14
je 0x19519
leaq 0x54ea9(%rip), %rsi     # 0x6e200
movq %r15, %r12
movq %rbp, %r15
xorl %ebp, %ebp
leaq 0x50(%rsp), %r13
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x12280
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x54221(%rip), %rax     # 0x6d5a4
leaq 0x54a3b(%rip), %rcx     # 0x6ddc5
pushq $0x39
popq %rsi
movq %r12, %rdi
movq %r13, %rdx
pushq $0x12c                  # imm = 0x12C
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
jmp 0x192c8
leaq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x1dc51
cmpl $0x0, (%r15)
jne 0x192c6
movq %rax, %rdx
addq $0x8, %rdx
movq 0x28(%rsp), %rcx
movq (%rax), %r8
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %r9
pushq %r15
pushq %r14
callq 0x34571
popq %rcx
popq %rdx
movq %rax, %rbp
cmpl $0x0, (%r15)
jne 0x192c8
movq 0x148(%rbp), %rcx
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %r8
callq 0x1bae2
jmp 0x192c8
movq 0x48(%rsp), %rcx
testq %rcx, %rcx
movq %rcx, 0x38(%rsp)
je 0x19473
leaq 0x8(%rcx), %rdi
callq 0x357cc
cmpb 0x30(%rsp), %al
je 0x19473
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
cmpb $0x0, 0x30(%rsp)
je 0x19561
leaq 0x5414f(%rip), %rax     # 0x6d5a4
leaq 0x571a5(%rip), %rdx     # 0x70601
leaq 0x54d7f(%rip), %rcx     # 0x6e1e2
pushq $0x1d
popq %rsi
movq %r15, %rdi
pushq $0x13c                  # imm = 0x13C
jmp 0x192be
movq (%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x12e0e
cmpl $0x0, (%r15)
jne 0x192c6
movq %r12, 0x30(%rsp)
movq %r12, %rdi
callq 0x12a25
movq 0x40(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0xf, %ecx
jne 0x19586
testq %r14, %r14
jmp 0x19594
callq 0x2dcbb
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x540d7(%rip), %r10     # 0x6d5a4
leaq 0x5402c(%rip), %rdx     # 0x6d500
pushq $0x1d
popq %rsi
movq %r15, %rdi
movq %rax, %rcx
pushq $0xc0
pushq %r10
jmp 0x192bf
movq (%rdi), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x540a9(%rip), %rax     # 0x6d5a4
leaq 0x53ffe(%rip), %rdx     # 0x6d500
leaq 0x540ef(%rip), %rcx     # 0x6d5f8
pushq $0x1d
popq %rsi
movq %r15, %rdi
pushq $0xc7
jmp 0x192be
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1dfd5
movq %rbp, %rdi
movq %rax, %rbp
cmpl $0x0, (%r15)
jne 0x192c8
pushq $0x1
popq %r8
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbp, %rcx
movq %r15, %r9
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x178d0
leaq 0x5403c(%rip), %rax     # 0x6d5a4
leaq 0x54c73(%rip), %rdx     # 0x6e1e2
leaq 0x5708b(%rip), %rcx     # 0x70601
pushq $0x1d
popq %rsi
movq %r15, %rdi
pushq $0x13f                  # imm = 0x13F
jmp 0x192be
cmpl $0x15, %ecx
sete %cl
testq %r14, %r14
setne %dl
testb %cl, %dl
movq 0x20(%rsp), %r12
je 0x195aa
cmpb $0x28, (%rax)
jne 0x195aa
cmpb $0x0, 0x1(%rax)
je 0x196cc
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x1dccf
movq %rax, %rbp
cmpl $0x0, (%r15)
jne 0x192c8
cmpb $0x1, 0xf(%rsp)
jne 0x19677
testq %r14, %r14
je 0x1978b
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x53fb2(%rip), %rax     # 0x6d5a4
leaq 0x547cc(%rip), %rcx     # 0x6ddc5
pushq $0x1b
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
pushq $0x163                  # imm = 0x163
jmp 0x19398
movq 0x48(%rsp), %rbp
movq 0x28(%rsp), %rcx
movq (%rbp), %r8
addq $0x8, %rbp
movq %r12, %rsi
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %r9
pushq %r15
pushq %r14
callq 0x4108f
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x192c6
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x34108
cmpl $0x0, (%r15)
je 0x19751
movq 0x20(%rsp), %rdi
callq 0x29d88
jmp 0x192c6
cmpl $0x3, %r13d
ja 0x1987c
movl %r13d, %eax
leaq 0x53f09(%rip), %rcx     # 0x6d594
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testq %r14, %r14
je 0x19898
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %r9
pushq %r15
pushq %r14
pushq %rbx
callq 0x343fa
jmp 0x19873
movq 0x28(%rsp), %rcx
movq %r12, %rsi
movq 0x38(%rsp), %r12
movq (%r12), %r8
addq $0x8, %r12
movq %rbp, %rdi
movq %r12, %rdx
movq %rbx, %r9
pushq %r15
pushq %r14
callq 0x346ae
popq %rcx
popq %rdx
movq %rbp, %r13
movq %rax, %rbp
cmpl $0x0, (%r15)
jne 0x192c8
leaq 0x50(%rsp), %rdx
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x34108
cmpl $0x0, (%r15)
jne 0x192c8
movq 0x148(%rbp), %rcx
leaq 0x50(%rsp), %r12
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rdx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x290ba
movq %r12, %rdi
callq 0x2dc7c
jmp 0x192c8
movq 0x20(%rsp), %rbp
movq 0x148(%rbp), %rcx
leaq 0x50(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
movq %rdx, %r12
xorl %r8d, %r8d
movq %r15, %r9
callq 0x1874a
movq %rbp, %rdi
callq 0x29d88
movq %r12, %rdi
callq 0x2dc7c
jmp 0x192c6
cmpl $0x3, %r13d
je 0x197d4
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
cmpb $0x1, 0xe0(%rax)
jne 0x197d4
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x53dea(%rip), %rax     # 0x6d5a4
leaq 0x54604(%rip), %rcx     # 0x6ddc5
pushq $0x6c
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
pushq $0x169                  # imm = 0x169
jmp 0x19398
xorl %r8d, %r8d
cmpl $0x3, %r13d
sete %r8b
movq 0x10(%rsp), %rdi
movq %r12, %rsi
jmp 0x19540
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %r9
pushq %r15
pushq %r14
pushq %rbx
callq 0x344f4
jmp 0x19873
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x53d75(%rip), %rax     # 0x6d5a4
leaq 0x5458f(%rip), %rcx     # 0x6ddc5
pushq $0x20
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
pushq $0x18f                  # imm = 0x18F
jmp 0x19398
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %r9
pushq %r15
pushq %r14
pushq %rbx
callq 0x34477
addq $0x20, %rsp
jmp 0x192c6
leaq 0x53d21(%rip), %rdx     # 0x6d5a4
pushq $0xf
popq %rsi
movq %r15, %rdi
movl $0x192, %ecx            # imm = 0x192
callq 0x1429e
jmp 0x192c8
movq 0x38(%rsp), %r12
movq 0x298(%r12), %rax
leaq 0x50(%rsp), %rdx
movq %rax, (%rdx)
movq (%r12), %rax
movq %rax, 0x18(%rdx)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rdx)
addq $0x8, %r12
movq %r12, 0x8(%rdx)
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rcx
movq %r15, %r8
callq 0x16d6b
jmp 0x192c6