// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $-0x1, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x133f0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x186e0
movq $-0x1, -0x8(%rbp)
jmp 0x188f6
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x18711
movq -0xb0(%rbp), %rdi
leaq 0x94f04(%rip), %rsi     # 0xad60b
callq 0x12140
cmpl $0x0, %eax
je 0x18763
movq 0x18(%rbp), %rdi
movq -0xb0(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x94ecd(%rip), %rdx     # 0xad60b
leaq 0x91db8(%rip), %rax     # 0xaa4fd
movq %rax, (%rsp)
movl $0x158, 0x8(%rsp)       # imm = 0x158
callq 0x156d0
movq $-0x1, -0x8(%rbp)
jmp 0x188f6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x255f0
movq %rax, -0xa8(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18798
movq $-0x1, -0x8(%rbp)
jmp 0x188f6
cmpq $0x1, -0xa8(%rbp)
jbe 0x187d7
movq 0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %ecx
movl $0x67, %esi
leaq 0x91d36(%rip), %r8      # 0xaa4fd
movl $0x164, %r9d            # imm = 0x164
callq 0x15930
jmp 0x188a8
cmpq $0x0, -0xa8(%rbp)
jne 0x18821
movq 0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x3e4f0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18800
jmp 0x188a8
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x6d920
movq %rax, -0xb8(%rbp)
jmp 0x188a8
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x47b70
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18841
jmp 0x188a8
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %r8
leaq -0x90(%rbp), %r9
movq -0xa8(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x5edb0
movq %rax, -0xa0(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18887
jmp 0x188a8
movq -0xa0(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x36ee0
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jae 0x188eb
movq -0x98(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rdi
callq 0x36ee0
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x188b3
movq -0xb8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)