// File: /workspace/github_c_makefile_star2_O1/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 0x12eda
movq $-0x1, %rdi
cmpl $0x0, (%rbx)
jne 0x163e1
movq %rbp, %rbx
movq %r15, 0x8(%rsp)
movq 0x18(%rsp), %rbp
movq %r14, 0x10(%rsp)
movq %r13, %rdi
callq 0x12ad0
movq %rax, %r14
cmpl $0x2, (%r13)
jne 0x163a1
leaq 0x602bc(%rip), %rsi     # 0x76651
movq %r14, %rdi
callq 0x12160
testl %eax, %eax
je 0x163f3
movq (%r12), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5d138(%rip), %rax     # 0x734ec
leaq 0x60296(%rip), %rdx     # 0x76651
movq 0xb8(%rsp), %rdi
movl $0x1d, %esi
movq %r14, %rcx
pushq $0x158                  # imm = 0x158
pushq %rax
callq 0x1442a
addq $0x10, %rsp
movq $-0x1, %rdi
movq %rdi, %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 0x1f29b
cmpl $0x0, (%r15)
movq $-0x1, %rdi
jne 0x163e1
movq %rax, %r13
cmpq $0x2, %rax
jb 0x16455
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x5d0b6(%rip), %r8      # 0x734ec
movq %r15, %rdi
movl $0x67, %esi
movl $0x164, %r9d            # imm = 0x164
callq 0x14618
movq $-0x1, %rdi
jmp 0x164f9
movq 0xb0(%rsp), %rdx
testq %r13, %r13
je 0x164c6
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %r15, %rcx
callq 0x3620e
movq $-0x1, %rdi
cmpl $0x0, (%r15)
movq 0x10(%rsp), %r8
jne 0x164f9
leaq 0x20(%rsp), %r9
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
pushq %r15
pushq $0x1
callq 0x437b3
movq $-0x1, %rdi
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x164f9
movq 0x148(%rax), %rbx
movq %rax, %rdi
callq 0x2b4c3
movq %rbx, %rdi
jmp 0x164f9
movq %rdx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2fa5f
movq $-0x1, %rdi
cmpl $0x0, (%r15)
movq 0x10(%rsp), %rdx
jne 0x164f9
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x4d763
movq %rax, %rdi
testq %r13, %r13
je 0x163e1
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x20(%rsp,%r14,8), %rdi
callq 0x2b4c3
incq %r14
cmpq %r14, %r13
jne 0x16508
movq %rbx, %rdi
jmp 0x163e1