// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_assignment.c
// Function: prv_assign_array_or_vector_field
static void prv_assign_array_or_vector_field(subtilis_parser_t *p,
					     subtilis_token_t *t,
					     const subtilis_array_desc_t *d,
					     subtilis_exp_t **indices,
					     size_t dims, subtilis_error_t *err)
/* clang-format on */

{
	const char *tbuf;
	size_t i;
	subtilis_exp_t *e = NULL;
	subtilis_assign_type_t at;

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

	tbuf = subtilis_token_get_text(t);
	at = prv_get_ass_op(p, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

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

	switch (at) {
	case SUBTILIS_ASSIGN_TYPE_EQUAL:
		if (dims == 0)
			/* We're assigning an array reference */
			subtilis_parser_array_assign_reference(p, t, d, e, err);
		else
			subtilis_type_if_indexed_write(p, d->name, d->t, d->reg,
						       d->loc, e, indices, dims,
						       err);
		e = NULL;
		break;
	case SUBTILIS_ASSIGN_TYPE_PLUS_EQUAL:
		subtilis_type_if_indexed_add(p, d->name, d->t, d->reg, d->loc,
					     e, indices, dims, err);
		e = NULL;
		break;
	case SUBTILIS_ASSIGN_TYPE_MINUS_EQUAL:
		subtilis_type_if_indexed_sub(p, d->name, d->t, d->reg, d->loc,
					     e, indices, dims, err);
		e = NULL;
		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 $0x18, %rsp
movq %r9, %r15
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r13
movq (%rdi), %rdi
movq %r9, %rdx
callq 0x12eda
cmpl $0x0, (%r15)
jne 0x1a1ba
movq %r12, 0x8(%rsp)
movq %rbp, %rdi
callq 0x12ad0
movq %rax, %r12
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1a046
cmpl $0x0, (%r15)
jne 0x1a1ba
testq %rbx, %rbx
sete %dl
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
setb %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x1a1ed
movq (%r13), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59413(%rip), %rax     # 0x735ac
leaq 0x59464(%rip), %rdx     # 0x73604
movq %r15, %rdi
movl $0x1d, %esi
movq %r12, %rcx
pushq $0x348                  # imm = 0x348
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x2b4c3
testq %rbx, %rbx
je 0x1a1de
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2b4c3
incq %r15
cmpq %r15, %rbx
jne 0x1a1cd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1eb88
movq %rax, %r12
cmpl $0x0, (%r15)
jne 0x1a1bd
movq 0x10(%rsp), %rax
cmpl $0x2, %eax
je 0x1a27d
cmpl $0x1, %eax
je 0x1a253
testl %eax, %eax
jne 0x1a2ae
testq %rbx, %rbx
je 0x1a2cc
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq 0x18(%rax), %r8
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %r9
pushq %r15
pushq %rbx
pushq %r14
callq 0x3651c
jmp 0x1a2a5
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq 0x18(%rax), %r8
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %r9
pushq %r15
pushq %rbx
pushq %r14
callq 0x3659f
jmp 0x1a2a5
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq 0x18(%rax), %r8
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %r9
pushq %r15
pushq %rbx
pushq %r14
callq 0x36622
addq $0x20, %rsp
jmp 0x1a1ba
leaq 0x592f7(%rip), %rdx     # 0x735ac
movq %r15, %rdi
movl $0xf, %esi
movl $0x366, %ecx            # imm = 0x366
callq 0x145f4
jmp 0x1a1bd
movq %r13, %rdi
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x16fff
jmp 0x1a1ba
nop