// File: /workspace/github_c_makefile_star2_O2/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 0x12e0e
cmpl $0x0, (%r14)
jne 0x172e4
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1729f
cmpb $0x28, (%rax)
jne 0x1729f
cmpb $0x0, 0x1(%rax)
je 0x172f3
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56237(%rip), %r10     # 0x6d4e8
leaq 0x56f2a(%rip), %rdx     # 0x6e1e2
pushq $0x1d
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
pushq $0x547                  # imm = 0x547
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x29d88
movq %r13, %rdi
callq 0x29d88
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 0x1dfd5
movq %rax, %rbx
movl (%r14), %eax
testl %eax, %eax
je 0x17342
cmpl $0x2c, %eax
jne 0x173af
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x561c2(%rip), %rax     # 0x6d4e8
leaq 0x5624a(%rip), %rdx     # 0x6d577
leaq 0x56a91(%rip), %rcx     # 0x6ddc5
pushq $0x3b
popq %rsi
movq %r14, %rdi
pushq $0x54e                  # imm = 0x54E
pushq %rax
jmp 0x173a8
movq %rbx, %rdi
callq 0x357cc
testb %al, %al
jne 0x1735a
movq %rbx, %rdi
callq 0x357ea
testb %al, %al
je 0x173b7
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1737f
movb (%rax), %cl
cmpb $0x2c, %cl
jne 0x173e7
cmpb $0x0, 0x1(%rax)
je 0x1742a
xorl %r13d, %r13d
jmp 0x173f5
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56157(%rip), %r10     # 0x6d4e8
leaq 0x561f5(%rip), %rdx     # 0x6d58d
pushq $0x1d
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
pushq $0x55e                  # imm = 0x55E
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
xorl %r13d, %r13d
jmp 0x172d4
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5611f(%rip), %rax     # 0x6d4e8
leaq 0x561a7(%rip), %rdx     # 0x6d577
leaq 0x569ee(%rip), %rcx     # 0x6ddc5
pushq $0x3b
popq %rsi
movq %r14, %rdi
pushq $0x557                  # imm = 0x557
jmp 0x1733f
xorl %r13d, %r13d
cmpb $0x29, %cl
jne 0x173f5
cmpb $0x0, 0x1(%rax)
je 0x1746f
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x560e1(%rip), %r10     # 0x6d4e8
leaq 0x569b7(%rip), %rcx     # 0x6ddc5
pushq $0x16
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
pushq $0x570                  # imm = 0x570
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
jmp 0x172d4
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1dfd5
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x172d4
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x347d5
movq %rax, %r13
cmpl $0x0, (%r14)
jne 0x172d4
movq %r12, %rdi
callq 0x12a25
movb (%rax), %cl
jmp 0x173ea
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x419c9
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x173af
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x173af
jmp 0x172e6