// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/parser_array.c
// Function: subtils_parser_vector_lvalue
size_t subtils_parser_vector_lvalue(subtilis_parser_t *p, subtilis_token_t *t,
				    const subtilis_type_t *stype, size_t loc,
				    const char *var_name, size_t mem_reg,
				    subtilis_type_t *type,
				    subtilis_error_t *err)
{
	subtilis_exp_t *indices[SUBTILIS_MAX_DIMENSIONS];
	size_t i;
	subtilis_exp_t *e;
	size_t dims;
	const char *tbuf;
	size_t ret_val = SIZE_MAX;

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

	tbuf = subtilis_token_get_text(t);
	if ((t->type != SUBTILIS_TOKEN_OPERATOR) || (strcmp(tbuf, "{"))) {
		subtilis_error_set_expected(err, "{", tbuf, p->l->stream->name,
					    p->l->line);
		return SIZE_MAX;
	}

	dims = subtilis_curly_bracketed_slice_have_b(p, t, indices, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	if (dims > 1) {
		/* It's a slice which is not allowed. */

		subtilis_error_set_lvalue_expected(err, p->l->stream->name,
						   p->l->line);
		goto cleanup;
	}

	if (dims == 0) {
		/* What we have here is a vector reference. */

		subtilis_type_copy(type, stype, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		ret_val = subtilis_reference_get_pointer(p, mem_reg, loc, err);
		goto cleanup;
	}

	/*
	 * Otherwise we have an array element.  We need to compute its
	 * address.
	 */

	subtilis_type_if_element_type(p, stype, type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_array_index_calc(p, var_name, stype, mem_reg, loc, indices,
				      dims, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	ret_val = e->exp.ir_op.reg;
	subtilis_exp_delete(e);

cleanup:

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

	return ret_val;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x18(%rsp)
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r12
movq 0xb8(%rsp), %rbp
movq (%rdi), %rdi
movq %rbp, %rdx
callq 0x12edc
movq $-0x1, %rax
cmpl $0x0, (%rbp)
jne 0x1637c
movq %r12, %rbp
movq %r14, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x18(%rsp), %r12
movq %r15, (%rsp)
movq %r13, %rdi
callq 0x12ad0
cmpl $0x2, (%r13)
jne 0x1633b
cmpb $0x7b, (%rax)
jne 0x1633b
cmpb $0x0, 0x1(%rax)
je 0x1638b
movq (%rbp), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5d19a(%rip), %r10     # 0x734e8
leaq 0x6033c(%rip), %rdx     # 0x76691
movq 0xb8(%rsp), %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x158                  # imm = 0x158
pushq %r10
callq 0x143da
addq $0x10, %rsp
movq $-0x1, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rdx
movq %rbp, %rdi
movq %r13, %rsi
movq 0xb8(%rsp), %r14
movq %r14, %rcx
callq 0x1f325
cmpl $0x0, (%r14)
jne 0x16375
movq %rax, %r13
cmpq $0x2, %rax
jb 0x163e3
movq (%rbp), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x5d121(%rip), %r8      # 0x734e8
movq %r14, %rdi
movl $0x67, %esi
movl $0x164, %r9d            # imm = 0x164
callq 0x145c8
movq $-0x1, %r15
jmp 0x16449
movq 0xb0(%rsp), %rdx
testq %r13, %r13
je 0x16466
movq %rbp, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rcx
callq 0x360be
movq $-0x1, %r15
cmpl $0x0, (%r14)
jne 0x16449
movq %r12, %rcx
leaq 0x20(%rsp), %r9
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
movq (%rsp), %r8
pushq %r14
pushq $0x1
callq 0x43706
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x16449
movq 0x148(%rax), %r15
movq %rax, %rdi
callq 0x2b166
xorl %r14d, %r14d
movq 0x20(%rsp,%r14,8), %rdi
callq 0x2b166
incq %r14
cmpq %r14, %r13
jne 0x1644c
movq %r15, %rax
jmp 0x1637c
movq %rdx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x2f78a
cmpl $0x0, (%r14)
movq $-0x1, %rax
jne 0x1637c
movq %r12, %rsi
movq %rbp, %rdi
movq (%rsp), %rdx
movq %r14, %rcx
callq 0x4d71f
jmp 0x1637c