// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r15
movq 0x1d8(%rsp), %r12
movb 0x1d0(%rsp), %bpl
movb $0x0, 0xf(%rsp)
movq (%rdi), %rdi
movq %r12, %rdx
callq 0x12eda
cmpl $0x0, (%r12)
jne 0x19b87
movb %bpl, 0xe(%rsp)
movq %r15, 0x10(%rsp)
movq %r13, %rdi
callq 0x12ad0
movq %rax, %rbp
movl (%r13), %r15d
cmpl $0x2, %r15d
jne 0x198d1
leaq 0x59c60(%rip), %rsi     # 0x73504
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x19950
cmpl $0x2, %r15d
jne 0x198d1
leaq 0x5a951(%rip), %rsi     # 0x74212
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x19ada
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1a046
cmpl $0x0, (%r12)
je 0x19903
movq %r15, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rcx
callq 0x18d3a
jmp 0x19b87
testq %r14, %r14
sete %dl
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
setb %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x199e4
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59c78(%rip), %rax     # 0x735ac
leaq 0x59cc3(%rip), %rdx     # 0x735fe
movq %r12, %rdi
movl $0x1d, %esi
movq %rbp, %rcx
pushq $0x11e                  # imm = 0x11E
jmp 0x19b7d
movq 0x38(%rsp), %rdi
movl (%rdi), %eax
cmpl $0xf, %eax
je 0x19965
cmpl $0x15, %eax
jne 0x19aa0
testq %r14, %r14
movq %r12, %r15
movq 0x10(%rsp), %rdi
je 0x19b50
subq $0x8, %rsp
leaq 0x48(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x2f(%rsp), %r9
movq 0x20(%rsp), %r12
movq %r12, %rdx
pushq %r15
callq 0x1840a
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x19b87
cmpb $0x1, 0x27(%rsp)
jne 0x19c56
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59be4(%rip), %rax     # 0x735ac
leaq 0x5a426(%rip), %rcx     # 0x73df5
movq %r15, %rdi
movl $0x1b, %esi
movq %r12, %rdx
pushq $0xd1
jmp 0x19b7d
movq %rax, 0x48(%rsp)
subq $0x8, %rsp
leaq 0x48(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x17(%rsp), %r9
movq 0x18(%rsp), %r15
movq %r15, %rdi
movq 0x20(%rsp), %rbp
movq %rbp, %rdx
pushq %r12
callq 0x1840a
addq $0x10, %rsp
movl (%r12), %eax
testl %eax, %eax
je 0x19bbc
cmpl $0x3e, %eax
je 0x19a31
cmpl $0x1b, %eax
jne 0x19b87
cmpl $0x3, 0x48(%rsp)
jne 0x19b87
movq %r12, %rdi
callq 0x14404
testq %r14, %r14
je 0x19cc1
leaq 0x5a7dc(%rip), %rsi     # 0x74230
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 0x59b32(%rip), %rax     # 0x735ac
leaq 0x5a374(%rip), %rcx     # 0x73df5
movq %r12, %rdi
movl $0x39, %esi
movq %r13, %rdx
pushq $0x12c                  # imm = 0x12C
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x19b89
callq 0x2f882
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x59af0(%rip), %r10     # 0x735ac
leaq 0x59a43(%rip), %rdx     # 0x73506
movq %r12, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0xc0
pushq %r10
jmp 0x19b7e
leaq 0x28(%rsp), %rdx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rcx
callq 0x1e7ed
movq %rax, 0x40(%rsp)
cmpl $0x0, (%r12)
jne 0x19b87
movq %rax, %rdx
addq $0x8, %rdx
movq 0x28(%rsp), %rcx
movq (%rax), %r8
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %r9
pushq %r12
pushq %r14
callq 0x366a5
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%r12)
jne 0x19b89
movq 0x148(%rbp), %rcx
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r12, %r8
callq 0x1c019
jmp 0x19b89
movq (%rdi), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59a4a(%rip), %rax     # 0x735ac
leaq 0x5999d(%rip), %rdx     # 0x73506
leaq 0x59a96(%rip), %rcx     # 0x73606
movq %r15, %rdi
movl $0x1d, %esi
pushq $0xc7
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0x2b4c3
testq %r14, %r14
je 0x19baa
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x2b4c3
incq %r15
cmpq %r15, %r14
jne 0x19b99
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rsp), %rcx
testq %rcx, %rcx
movq %rcx, 0x30(%rsp)
je 0x19c17
leaq 0x8(%rcx), %rdi
callq 0x377f7
cmpb 0xe(%rsp), %al
je 0x19c17
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
cmpb $0x0, 0xe(%rsp)
je 0x19d0c
leaq 0x599b5(%rip), %rax     # 0x735ac
leaq 0x5ca53(%rip), %rdx     # 0x76651
leaq 0x5a60d(%rip), %rcx     # 0x74212
movq %r12, %rdi
movl $0x1d, %esi
pushq $0x13c                  # imm = 0x13C
jmp 0x19b7d
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
cmpl $0x0, (%r12)
jne 0x19b87
movq %r13, %rdi
callq 0x12ad0
movq 0x38(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0xf, %ecx
jne 0x19d33
testq %r14, %r14
jne 0x19d43
jmp 0x19d5a
movq %r12, %rsi
movq 0x40(%rsp), %rbp
movq 0x28(%rsp), %rcx
movq (%rbp), %r8
addq $0x8, %rbp
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %r9
pushq %r15
pushq %r14
callq 0x437b3
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x19b87
movq %rax, 0x18(%rsp)
leaq 0x50(%rsp), %rdx
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x3620e
cmpl $0x0, (%r15)
je 0x19dc4
movq 0x18(%rsp), %rdi
callq 0x2b4c3
jmp 0x19b87
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1eb88
movq %rax, %rbp
cmpl $0x0, (%r12)
jne 0x19b89
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %rcx
movl $0x1, %r8d
movq %r12, %r9
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17f38
leaq 0x59899(%rip), %rax     # 0x735ac
leaq 0x5a4f8(%rip), %rdx     # 0x74212
leaq 0x5c930(%rip), %rcx     # 0x76651
movq %r12, %rdi
movl $0x1d, %esi
pushq $0x13f                  # imm = 0x13F
jmp 0x19b7d
cmpl $0x15, %ecx
sete %cl
testq %r14, %r14
setne %dl
testb %cl, %dl
je 0x19d5a
leaq 0x5a4c8(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x19dfe
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1e874
movq %rax, %rbp
cmpl $0x0, (%r12)
jne 0x19b89
cmpb $0x1, 0xf(%rsp)
jne 0x19e85
testq %r14, %r14
movq 0x48(%rsp), %rcx
je 0x19edf
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59806(%rip), %rax     # 0x735ac
leaq 0x5a048(%rip), %rcx     # 0x73df5
movq %r12, %rdi
movl $0x1b, %esi
movq 0x18(%rsp), %rdx
pushq $0x163                  # imm = 0x163
jmp 0x19a91
movq 0x18(%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 0x18d8e
movq %rbp, %rdi
callq 0x2b4c3
movq %r12, %rdi
callq 0x2f843
jmp 0x19b87
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
movq %r15, %rdi
movq %rbp, %rsi
movq %rdx, 0x30(%rsp)
movq %rbx, %r9
pushq %r12
pushq %r14
callq 0x367f0
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%r12)
jne 0x19b89
leaq 0x50(%rsp), %rdx
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movq %r12, %rcx
callq 0x3620e
cmpl $0x0, (%r12)
jne 0x19b89
movq 0x148(%rbp), %rcx
leaq 0x50(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
movq %rdx, %r15
xorl %r8d, %r8d
movq %r12, %r9
callq 0x2a721
movq %r15, %rdi
callq 0x2f843
jmp 0x19b89
movq 0x48(%rsp), %rax
cmpl $0x3, %eax
ja 0x19fe4
movl %eax, %eax
leaq 0x59700(%rip), %rcx     # 0x7359c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testq %r14, %r14
je 0x1a002
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %r9
pushq %r12
pushq %r14
pushq %rbx
callq 0x3651c
jmp 0x19fdb
cmpl $0x3, %ecx
je 0x19f2b
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rax
cmpb $0x1, 0xe0(%rax)
jne 0x19f2b
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5969f(%rip), %rax     # 0x735ac
leaq 0x59ee1(%rip), %rcx     # 0x73df5
movq %r12, %rdi
movl $0x6c, %esi
movq 0x18(%rsp), %rdx
pushq $0x169                  # imm = 0x169
jmp 0x19a91
xorl %r8d, %r8d
cmpl $0x3, %ecx
sete %r8b
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %rcx
jmp 0x19cf3
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %r9
pushq %r12
pushq %r14
pushq %rbx
callq 0x36622
jmp 0x19fdb
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5961b(%rip), %rax     # 0x735ac
leaq 0x59e5d(%rip), %rcx     # 0x73df5
movq %r12, %rdi
movl $0x20, %esi
movq 0x18(%rsp), %rdx
pushq $0x18f                  # imm = 0x18F
jmp 0x19a91
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
movq (%rdx), %r8
addq $0x8, %rdx
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %r9
pushq %r12
pushq %r14
pushq %rbx
callq 0x3659f
addq $0x20, %rsp
jmp 0x19b87
leaq 0x595c1(%rip), %rdx     # 0x735ac
movq %r12, %rdi
movl $0xf, %esi
movl $0x192, %ecx            # imm = 0x192
callq 0x145f4
jmp 0x19b89
movq 0x30(%rsp), %rcx
movq 0x298(%rcx), %rax
leaq 0x50(%rsp), %rdx
movq %rax, (%rdx)
movq (%rcx), %rax
movq %rax, 0x18(%rdx)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rdx)
addq $0x8, %rcx
movq %rcx, 0x8(%rdx)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rcx
movq %r12, %r8
callq 0x16fff
jmp 0x19b87