// File: /workspace/github_c_makefile_star2_O2/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 0x156f2
leaq 0x10(%rsp), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x1e882
jmp 0x15708
leaq 0x10(%rsp), %rdx
pushq $0xa
popq %rcx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1e437
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x15726
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
je 0x15743
xorl %r14d, %r14d
jmp 0x15888
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x157a0
cmpb $0x2e, (%rax)
jne 0x157a0
movb 0x1(%rax), %cl
testb %cl, %cl
sete %al
jne 0x1576c
cmpl $0xf, (%r13)
jne 0x158a3
testq %rbx, %rbx
jne 0x157a7
testb %cl, %cl
jne 0x157f3
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x57d60(%rip), %rax     # 0x6d4e8
leaq 0x57d84(%rip), %rdx     # 0x6d513
leaq 0x57d8b(%rip), %rcx     # 0x6d521
pushq $0x1d
popq %rsi
movq %r14, %rdi
pushq $0x7d
jmp 0x157ed
testq %rbx, %rbx
je 0x157f3
xorl %eax, %eax
cmpl $0x1, 0x8(%r13)
sete %cl
cmpq $0x2, %rbx
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1580c
testb %al, %al
je 0x1583d
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x57d14(%rip), %rax     # 0x6d4e8
leaq 0x57d38(%rip), %rdx     # 0x6d513
leaq 0x57d57(%rip), %rcx     # 0x6d539
pushq $0x1d
popq %rsi
movq %r14, %rdi
pushq $0x86
pushq %rax
jmp 0x158d2
movq %rbp, %rdi
movq %r13, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r14, %r8
callq 0x2a285
jmp 0x15885
testb %al, %al
je 0x15864
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 0x158de
addq $0x20, %rsp
jmp 0x15885
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 0x404b6
jmp 0x15883
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 0x34571
popq %rcx
popq %rdx
movq %rax, %r14
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x15714
movq 0x10(%rsp,%r15,8), %rdi
callq 0x29d88
incq %r15
jmp 0x1588b
movq %r13, %rdi
callq 0x2dcbb
movq (%rbp), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x57c2a(%rip), %r10     # 0x6d4e8
leaq 0x57c3b(%rip), %rdx     # 0x6d500
pushq $0x1d
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
pushq $0x75
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
jmp 0x1573b