// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/parser_array.c
// Function: subtilis_parser_get_dim
subtilis_exp_t *subtilis_parser_get_dim(subtilis_parser_t *p,
					subtilis_token_t *t,
					subtilis_error_t *err)
{
	const char *tbuf;
	subtilis_exp_t *dim = NULL;
	subtilis_exp_t *ar = NULL;

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

	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);
		goto cleanup;
	}

	ar = subtilis_parser_expression(p, t, err);
	if (err->type == SUBTILIS_ERROR_NUMERIC_EXPECTED) {
		subtilis_error_not_array(err, "First argument to dim",
					 p->l->stream->name, p->l->line);
		goto cleanup;
	} else if (err->type != SUBTILIS_ERROR_OK) {
		goto cleanup;
	}

	if (!subtilis_type_if_is_array(&ar->type) &&
	    !subtilis_type_if_is_vector(&ar->type)) {
		subtilis_error_not_array(err, "First argument to dim",
					 p->l->stream->name, p->l->line);
		goto cleanup;
	}

	tbuf = subtilis_token_get_text(t);
	if (t->type != SUBTILIS_TOKEN_OPERATOR) {
		subtilis_error_set_expected(err, ") or ,", tbuf,
					    p->l->stream->name, p->l->line);
		goto cleanup;
	}

	if (!strcmp(tbuf, ",")) {
		dim = subtilis_parser_expression(p, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		dim = subtilis_type_if_to_int(p, dim, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		tbuf = subtilis_token_get_text(t);
	}

	if (strcmp(tbuf, ")")) {
		subtilis_error_set_right_bkt_expected(
		    err, tbuf, p->l->stream->name, p->l->line);
		goto cleanup;
	}

	ar = subtilis_array_get_dim(p, ar, dim, err);
	dim = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	return ar;

cleanup:

	subtilis_exp_delete(ar);
	subtilis_exp_delete(dim);

	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x174ff
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x174b6
cmpb $0x28, (%rax)
jne 0x174b6
cmpb $0x0, 0x1(%rax)
je 0x1750e
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5c020(%rip), %r10     # 0x734e8
leaq 0x5cd63(%rip), %rdx     # 0x74232
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x547                  # imm = 0x547
pushq %r10
callq 0x143da
addq $0x10, %rsp
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x2b166
movq %r13, %rdi
callq 0x2b166
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ec4c
movq %rax, %rbx
movl (%r14), %eax
testl %eax, %eax
je 0x1755f
cmpl $0x2c, %eax
jne 0x175d0
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5bfa7(%rip), %rax     # 0x734e8
leaq 0x5c02f(%rip), %rdx     # 0x73577
leaq 0x5c8c6(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x3b, %esi
pushq $0x54e                  # imm = 0x54E
pushq %rax
jmp 0x175c7
movq %rbx, %rdi
callq 0x376b5
testb %al, %al
jne 0x17577
movq %rbx, %rdi
callq 0x376d3
testb %al, %al
je 0x175d8
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1759c
movb (%rax), %cl
cmpb $0x2c, %cl
jne 0x1760a
cmpb $0x0, 0x1(%rax)
je 0x17651
xorl %r13d, %r13d
jmp 0x17618
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5bf3a(%rip), %r10     # 0x734e8
leaq 0x5bfd8(%rip), %rdx     # 0x7358d
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x55e                  # imm = 0x55E
pushq %r10
callq 0x143da
addq $0x10, %rsp
xorl %r13d, %r13d
jmp 0x174ef
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5befe(%rip), %rax     # 0x734e8
leaq 0x5bf86(%rip), %rdx     # 0x73577
leaq 0x5c81d(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x3b, %esi
pushq $0x557                  # imm = 0x557
jmp 0x1755c
xorl %r13d, %r13d
cmpb $0x29, %cl
jne 0x17618
cmpb $0x0, 0x1(%rax)
je 0x17696
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5bebe(%rip), %r10     # 0x734e8
leaq 0x5c7e4(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x16, %esi
movq %rax, %rdx
pushq $0x570                  # imm = 0x570
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x174ef
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1ec4c
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x174ef
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x367cf
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x174ef
movq %r12, %rdi
callq 0x12ad0
movb (%rax), %cl
jmp 0x1760d
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x440f7
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x175d0
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x175d0
jmp 0x17501