// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x175b5
movq %r12, %rdi
callq 0x12ad0
movq %rax, %rbx
cmpl $0x2, (%r12)
jne 0x1756d
leaq 0x5ccb1(%rip), %rsi     # 0x74212
movq %rbx, %rdi
callq 0x12160
testl %eax, %eax
je 0x175c9
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5bf6d(%rip), %rax     # 0x734ec
leaq 0x5cc8c(%rip), %rdx     # 0x74212
movq %r14, %rdi
movl $0x1d, %esi
movq %rbx, %rcx
pushq $0x547                  # imm = 0x547
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x2b4c3
movq %r13, %rdi
callq 0x2b4c3
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1eb88
movq %rax, %rbx
movl (%r14), %eax
testl %eax, %eax
je 0x1761c
cmpl $0x2c, %eax
jne 0x17715
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5bef0(%rip), %rax     # 0x734ec
leaq 0x5bf7a(%rip), %rdx     # 0x7357d
leaq 0x5c7eb(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x3b, %esi
pushq $0x54e                  # imm = 0x54E
jmp 0x1770b
movq %rbx, %rdi
callq 0x377f7
testb %al, %al
jne 0x17638
movq %rbx, %rdi
callq 0x37815
testb %al, %al
je 0x176de
movq %r12, %rdi
callq 0x12ad0
movq %rax, %rbp
cmpl $0x2, (%r12)
jne 0x176b3
leaq 0x5bf47(%rip), %rsi     # 0x73598
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x1771d
xorl %r13d, %r13d
leaq 0x5c482(%rip), %rsi     # 0x73aed
movq %rbp, %rdi
callq 0x12160
testl %eax, %eax
je 0x17763
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5be5f(%rip), %rax     # 0x734ec
leaq 0x5c761(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x16, %esi
movq %rbp, %rdx
pushq $0x570                  # imm = 0x570
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x175a5
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5be27(%rip), %rax     # 0x734ec
leaq 0x5bec7(%rip), %rdx     # 0x73593
movq %r14, %rdi
movl $0x1d, %esi
movq %rbp, %rcx
pushq $0x55e                  # imm = 0x55E
jmp 0x1770b
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5bdfc(%rip), %rax     # 0x734ec
leaq 0x5be86(%rip), %rdx     # 0x7357d
leaq 0x5c6f7(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x3b, %esi
pushq $0x557                  # imm = 0x557
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r13d, %r13d
jmp 0x175a5
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1eb88
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x175a5
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x3691f
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x175a5
movq %r12, %rdi
callq 0x12ad0
movq %rax, %rbp
jmp 0x17664
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x4419d
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x17715
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x17715
jmp 0x175b7