// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_array.c
// Function: subtils_parser_read_array_with_type
subtilis_exp_t *subtils_parser_read_array_with_type(subtilis_parser_t *p,
						    subtilis_token_t *t,
						    const subtilis_type_t *type,
						    size_t mem_reg, size_t loc,
						    const char *var_name,
						    subtilis_error_t *err)
/* clang-format on */

{
	subtilis_exp_t *indices[SUBTILIS_MAX_DIMENSIONS];
	size_t i;
	bool rec;
	const char *tbuf;
	subtilis_exp_t *e = NULL;
	size_t dims = 0;

	if (type->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 NULL;

	subtilis_lexer_get(p->l, t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tbuf = subtilis_token_get_text(t);
	rec = (t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, ".");

	if (rec && (type->type != SUBTILIS_TYPE_ARRAY_REC)) {
		subtilis_error_set_expected(err, "Collection of RECs",
					    subtilis_type_name(type),
					    p->l->stream->name, p->l->line);
		goto cleanup;
	}

	if (dims == 0) {
		if (rec) {
			subtilis_error_set_expected(
			    err, "Array of RECs", "Array of RECs reference",
			    p->l->stream->name, p->l->line);
			goto cleanup;
		}
		/* What we have here is an array reference. */
		e = subtilis_exp_new_var_block(p, type, mem_reg, loc, err);
	} else if ((type->params.array.num_dims == 1) && (dims == 2)) {
		if (rec) {
			subtilis_error_set_expected(
			    err, "Array of RECs", "Slice of RECs",
			    p->l->stream->name, p->l->line);
			goto cleanup;
		}
		/* We have a slice. */
		e = subtilis_array_type_slice_array(
		    p, type, mem_reg, loc, indices[0], indices[1], err);
	} else {
		if (rec)
			e = prv_read_rec_el(p, t, type, &indices[0], dims,
					    mem_reg, loc, var_name, err);
		else
			e = subtilis_type_if_indexed_read(p, var_name, type,
							  mem_reg, loc, indices,
							  dims, err);
	}

cleanup:

	for (i = 0; i < dims; i++)
		subtilis_exp_delete(indices[i]);

	return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r15
movq %r8, 0x8(%rsp)
movq %rcx, (%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbp
movq 0xa0(%rsp), %r14
cmpl $0x1, 0x8(%rdx)
jne 0x15b5c
leaq 0x10(%rsp), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x1f4fd
jmp 0x15b74
leaq 0x10(%rsp), %rdx
movl $0xa, %ecx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1f017
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x15b85
xorl %r14d, %r14d
jmp 0x15cb8
movq (%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x15c9b
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x15bc3
leaq 0x5d950(%rip), %rsi     # 0x73504
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
sete %al
jmp 0x15bc5
xorl %eax, %eax
testb %al, %al
je 0x15bd4
cmpl $0xf, (%r13)
jne 0x15c61
testq %rbx, %rbx
je 0x15c2b
cmpl $0x1, 0x8(%r13)
sete %cl
cmpq $0x2, %rbx
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x15cca
testb %al, %al
je 0x15d14
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5d8de(%rip), %rax     # 0x734ec
leaq 0x5d904(%rip), %rdx     # 0x73519
leaq 0x5d923(%rip), %rcx     # 0x7353f
movq %r14, %rdi
movl $0x1d, %esi
pushq $0x86
jmp 0x15c5e
testb %al, %al
je 0x15cfb
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5d8a6(%rip), %rax     # 0x734ec
leaq 0x5d8cc(%rip), %rdx     # 0x73519
leaq 0x5d8d3(%rip), %rcx     # 0x73527
movq %r14, %rdi
movl $0x1d, %esi
pushq $0x7d
pushq %rax
jmp 0x15c92
movq %r13, %rdi
callq 0x2f882
movq (%rbp), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5d870(%rip), %r10     # 0x734ec
leaq 0x5d883(%rip), %rdx     # 0x73506
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x75
pushq %r10
callq 0x1442a
addq $0x10, %rsp
xorl %r14d, %r14d
testq %rbx, %rbx
je 0x15cb8
xorl %r15d, %r15d
movq 0x10(%rsp,%r15,8), %rdi
callq 0x2b4c3
incq %r15
cmpq %r15, %rbx
jne 0x15ca6
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %al, %al
je 0x15d3b
subq $0x8, %rsp
leaq 0x18(%rsp), %rcx
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbx, %r8
movq 0x8(%rsp), %r9
pushq %r14
pushq %r15
pushq 0x20(%rsp)
callq 0x15d66
addq $0x20, %rsp
jmp 0x15d5e
movq %rbp, %rdi
movq %r13, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r14, %r8
callq 0x2b9e2
jmp 0x15d5e
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
subq $0x8, %rsp
movq %rbp, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
pushq %r14
callq 0x42b95
jmp 0x15d5a
leaq 0x10(%rsp), %r9
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq (%rsp), %rcx
movq 0x8(%rsp), %r8
pushq %r14
pushq %rbx
callq 0x366a5
addq $0x10, %rsp
movq %rax, %r14
jmp 0x15c9e