// File: /workspace/github_c_makefile_star2_O0/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
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 0x18070
movq $-0x1, -0x8(%rbp)
jmp 0x182c2
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x180a1
movq -0xb0(%rbp), %rdi
leaq 0x93205(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
je 0x180f3
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 0x931ce(%rip), %rdx     # 0xab29c
leaq 0x92428(%rip), %rax     # 0xaa4fd
movq %rax, (%rsp)
movl $0xb1, 0x8(%rsp)
callq 0x156d0
movq $-0x1, -0x8(%rbp)
jmp 0x182c2
movq -0x20(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x1811e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x259a0
movq %rax, -0xa8(%rbp)
jmp 0x18142
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movq 0x18(%rbp), %r8
movl $0xa, %ecx
callq 0x251f0
movq %rax, -0xa8(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18158
movq $-0x1, -0x8(%rbp)
jmp 0x182c2
cmpq $0x0, -0xa8(%rbp)
jne 0x181a2
movq 0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x3e4f0
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18181
jmp 0x18274
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x6d920
movq %rax, -0xb8(%rbp)
jmp 0x18274
movq -0x20(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x181eb
cmpq $0x2, -0xa8(%rbp)
jne 0x181eb
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 0x92322(%rip), %r8      # 0xaa4fd
movl $0xc8, %r9d
callq 0x15930
jmp 0x18274
jmp 0x181ed
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 0x1820d
jmp 0x18274
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 0x18253
jmp 0x18274
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 0x182b7
movq -0x98(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rdi
callq 0x36ee0
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x1827f
movq -0xb8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nop