// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/parser_array.c
// Function: subtils_parser_array_lvalue
size_t subtils_parser_array_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;
	}

	if (stype->params.array.num_dims == 1)
		dims =
		    subtilis_round_bracketed_slice_have_b(p, t, indices, err);
	else
		dims = subtilis_var_bracketed_int_args_have_b(
		    p, t, indices, SUBTILIS_MAX_DIMENSIONS, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	if (dims == 0) {
		/* What we have here is an array 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;
	} else if ((stype->params.array.num_dims == 1) && (dims == 2)) {
		subtilis_error_set_lvalue_expected(err, p->l->stream->name,
						   p->l->line);
		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, %r13
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbp
movq 0xb8(%rsp), %rbx
movq (%rdi), %rdi
movq %rbx, %rdx
callq 0x12edc
movq $-0x1, %rax
cmpl $0x0, (%rbx)
jne 0x15e79
movq %r13, %rbx
movq %r14, 0x10(%rsp)
movq 0x18(%rsp), %r13
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x15e38
cmpb $0x28, (%rax)
jne 0x15e38
cmpb $0x0, 0x1(%rax)
je 0x15e88
movq (%rbp), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5d69d(%rip), %r10     # 0x734e8
leaq 0x5e3e0(%rip), %rdx     # 0x74232
movq 0xb8(%rsp), %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0xb1
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
movq 0x10(%rsp), %rax
cmpl $0x1, 0x8(%rax)
movq 0xb8(%rsp), %r14
leaq 0x20(%rsp), %rdx
jne 0x15eb0
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x1f552
jmp 0x15ec3
movl $0xa, %ecx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1f0d1
movq %rax, %r12
cmpl $0x0, (%r14)
movq $-0x1, %rax
jne 0x15e79
movq 0xb0(%rsp), %rdx
testq %r12, %r12
je 0x15f32
movq 0x10(%rsp), %rsi
cmpl $0x1, 0x8(%rsi)
sete %al
cmpq $0x2, %r12
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x15f69
movq (%rbp), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x5d5dc(%rip), %r8      # 0x734e8
movq 0xb8(%rsp), %rdi
movl $0x67, %esi
movl $0xc8, %r9d
callq 0x145c8
movq $-0x1, 0x8(%rsp)
jmp 0x15fd0
movq %rdx, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2f78a
movq $-0x1, %rax
cmpl $0x0, (%r14)
jne 0x15e79
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x4d71f
jmp 0x15e79
movq %rbp, %rdi
movq %rsi, %r13
movq %rbp, %r14
movq 0xb8(%rsp), %rbp
movq %rbp, %rcx
callq 0x360be
movq $-0x1, 0x8(%rsp)
cmpl $0x0, (%rbp)
jne 0x15fd0
movq %rbp, %rax
leaq 0x20(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
movq %r15, %r8
pushq %rax
pushq %r12
callq 0x43706
addq $0x10, %rsp
cmpl $0x0, (%rbp)
jne 0x15fd0
movq 0x148(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq %rax, %rdi
callq 0x2b166
xorl %r14d, %r14d
movq 0x20(%rsp,%r14,8), %rdi
callq 0x2b166
incq %r14
cmpq %r14, %r12
jne 0x15fd3
movq 0x8(%rsp), %rax
jmp 0x15e79