// File: /workspace/github_c_makefile_star2_O3/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 0x12edc
cmpl $0x0, (%r15)
jne 0x1a0e8
movq %r12, 0x8(%rsp)
movq %rbp, %rdi
callq 0x12ad0
movq %rax, %r12
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x19fab
cmpl $0x0, (%r15)
je 0x1a11b
xorl %r12d, %r12d
movq %r12, %rdi
callq 0x2b166
testq %rbx, %rbx
je 0x1a10c
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2b166
incq %r15
cmpq %r15, %rbx
jne 0x1a0fb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
sete %dl
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
setb %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x1a17a
movq (%r13), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59460(%rip), %rax     # 0x735a4
leaq 0x594ab(%rip), %rdx     # 0x735f6
movq %r15, %rdi
movl $0x1d, %esi
movq %r12, %rcx
pushq $0x348                  # imm = 0x348
pushq %rax
callq 0x143da
addq $0x10, %rsp
xorl %edi, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b166
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1ec4c
movq %rax, %r12
cmpl $0x0, (%r15)
jne 0x1a0eb
movq 0x10(%rsp), %rax
cmpl $0x2, %eax
je 0x1a21c
cmpl $0x1, %eax
je 0x1a1f2
testl %eax, %eax
jne 0x1a24d
testq %rbx, %rbx
je 0x1a26b
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 0x363cc
addq $0x20, %rsp
xorl %edi, %edi
callq 0x2b166
jmp 0x1a0f8
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 0x3644f
jmp 0x1a244
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 0x364d2
addq $0x20, %rsp
jmp 0x1a0e8
leaq 0x59350(%rip), %rdx     # 0x735a4
movq %r15, %rdi
movl $0xf, %esi
movl $0x366, %ecx            # imm = 0x366
callq 0x145a4
jmp 0x1a0eb
movq %r13, %rdi
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rcx
movq %r15, %r8
callq 0x16f6c
jmp 0x1a165
nop