// File: /workspace/github_c_makefile_star2_O2/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, %rbp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
movq 0xb8(%rsp), %rbx
movq (%rdi), %rdi
movq %rbx, %rdx
callq 0x12e0e
pushq $-0x1
popq %rax
cmpl $0x0, (%rbx)
jne 0x15ef1
movq %rbp, 0x10(%rsp)
movq %rax, %rbx
movq %r15, 0x8(%rsp)
movq 0x18(%rsp), %rbp
movq %r14, (%rsp)
movq %r13, %rdi
callq 0x12a25
cmpl $0x2, (%r13)
jne 0x15eb8
cmpb $0x7b, (%rax)
jne 0x15eb8
cmpb $0x0, 0x1(%rax)
je 0x15f00
movq (%r12), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5761d(%rip), %r10     # 0x6d4e8
leaq 0x5a72f(%rip), %rdx     # 0x70601
pushq $0x1d
popq %rsi
movq 0xb8(%rsp), %rdi
movq %rax, %rcx
pushq $0x158                  # imm = 0x158
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
movq %r13, %rsi
movq 0xb8(%rsp), %r15
movq %r15, %rcx
callq 0x1e663
movq %rax, %r13
cmpl $0x0, (%r15)
movq %rbx, %rax
jne 0x15ef1
cmpq $0x2, %r13
jb 0x15f58
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x575a9(%rip), %r8      # 0x6d4e8
pushq $0x67
popq %rsi
movq %r15, %rdi
movl $0x164, %r9d            # imm = 0x164
callq 0x142c0
pushq $-0x1
popq %rbx
jmp 0x15feb
movq 0xb0(%rsp), %rdx
testq %r13, %r13
je 0x15fbc
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %r15, %rcx
callq 0x34108
pushq $-0x1
popq %rbx
cmpl $0x0, (%r15)
jne 0x15feb
leaq 0x20(%rsp), %r9
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq (%rsp), %r8
pushq %r15
pushq $0x1
callq 0x4108f
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x15feb
movq 0x148(%rax), %rbx
movq %rax, %rdi
callq 0x29d88
jmp 0x15feb
movq %rdx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2de8a
cmpl $0x0, (%r15)
jne 0x15f50
movq %r12, %rdi
movq %rbp, %rsi
movq (%rsp), %rdx
movq %r15, %rcx
callq 0x4ab28
movq %rax, %rbx
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x15eee
movq 0x20(%rsp,%r14,8), %rdi
callq 0x29d88
incq %r14
jmp 0x15fee