// File: /workspace/github_c_makefile_star2_O3/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 0x15ad4
leaq 0x10(%rsp), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x1f552
jmp 0x15aec
leaq 0x10(%rsp), %rdx
movl $0xa, %ecx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %r8
callq 0x1f0d1
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x15afd
xorl %r14d, %r14d
jmp 0x15c53
movq (%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
je 0x15b23
xorl %r14d, %r14d
testq %rbx, %rbx
jne 0x15c3e
jmp 0x15c53
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x15bad
cmpb $0x2e, (%rax)
jne 0x15bad
movb 0x1(%rax), %al
testb %al, %al
jne 0x15b49
cmpl $0xf, (%r13)
jne 0x15c65
testq %rbx, %rbx
je 0x15bec
cmpl $0x1, 0x8(%r13)
sete %cl
cmpq $0x2, %rbx
sete %dl
testb %dl, %cl
je 0x15c10
testb %al, %al
jne 0x15bc5
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5d968(%rip), %rax     # 0x734e8
leaq 0x5d98c(%rip), %rdx     # 0x73513
leaq 0x5d9ab(%rip), %rcx     # 0x73539
movq %r14, %rdi
movl $0x1d, %esi
pushq $0x86
pushq %rax
callq 0x143da
addq $0x10, %rsp
xorl %r14d, %r14d
jmp 0x15c3e
testq %rbx, %rbx
je 0x15bf4
cmpl $0x1, 0x8(%r13)
sete %al
cmpq $0x2, %rbx
sete %cl
testb %cl, %al
je 0x15c18
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 0x42aad
jmp 0x15c37
testb %al, %al
je 0x15ca4
movq %rbp, %rdi
movq %r13, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r14, %r8
callq 0x2b668
movq %rax, %r14
jmp 0x15c53
testb %al, %al
je 0x15cde
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 0x36555
addq $0x10, %rsp
movq %rax, %r14
xorl %r15d, %r15d
movq 0x10(%rsp,%r15,8), %rdi
callq 0x2b166
incq %r15
cmpq %r15, %rbx
jne 0x15c41
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x2f5ad
movq (%rbp), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5d868(%rip), %r10     # 0x734e8
leaq 0x5d879(%rip), %rdx     # 0x73500
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x75
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x15b12
movq (%rbp), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5d831(%rip), %rax     # 0x734e8
leaq 0x5d855(%rip), %rdx     # 0x73513
leaq 0x5d85c(%rip), %rcx     # 0x73521
movq %r14, %rdi
movl $0x1d, %esi
pushq $0x7d
pushq %rax
callq 0x143da
addq $0x10, %rsp
jmp 0x15af5
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 0x15d0e
addq $0x20, %rsp
jmp 0x15c3b