// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/parser_array.c
// Function: subtilis_parser_create_array
void subtilis_parser_create_array(subtilis_parser_t *p, subtilis_token_t *t,
				  bool local, subtilis_error_t *err)
{
	const char *tbuf;
	subtilis_exp_t *e[SUBTILIS_MAX_DIMENSIONS];
	subtilis_type_t element_type;

	size_t i;
	subtilis_ir_operand_t local_global;
	bool vec = false;
	size_t dims = 0;
	char *var_name = NULL;

	local_global.reg =
	    local ? SUBTILIS_IR_REG_LOCAL : SUBTILIS_IR_REG_GLOBAL;

	do {
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
		tbuf = subtilis_token_get_text(t);
		if (t->type != SUBTILIS_TOKEN_IDENTIFIER) {
			subtilis_error_set_id_expected(
			    err, tbuf, p->l->stream->name, p->l->line);
			return;
		}

		if (!local && p->current->proc_called) {
			subtilis_error_set_global_after_proc(
			    err, tbuf, p->l->stream->name, p->l->line);
			return;
		}

		tbuf = subtilis_token_get_text(t);
		if (subtilis_symbol_table_lookup(p->local_st, tbuf) ||
		    (!local && subtilis_symbol_table_lookup(p->st, tbuf))) {
			subtilis_error_set_already_defined(
			    err, tbuf, p->l->stream->name, p->l->line);
			return;
		}

		var_name = malloc(strlen(tbuf) + 1);
		if (!var_name) {
			subtilis_error_set_oom(err);
			return;
		}
		strcpy(var_name, tbuf);
		subtilis_type_init_copy(&element_type, &t->tok.id_type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		if ((element_type.type == SUBTILIS_TYPE_FN) ||
		    (element_type.type == SUBTILIS_TYPE_REC)) {
			subtilis_complete_custom_type(p, var_name,
						      &element_type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		}

		dims = parser_array_var_bracketed_int_args(
		    p, t, e, SUBTILIS_MAX_DIMENSIONS, &vec, err);
		if (err->type == SUBTILIS_ERROR_RIGHT_BKT_EXPECTED) {
			subtilis_error_too_many_dims(
			    err, var_name, p->l->stream->name, p->l->line);
			subtilis_type_free(&element_type);
			goto cleanup;
		}
		if (err->type != SUBTILIS_ERROR_OK) {
			subtilis_type_free(&element_type);
			goto cleanup;
		}

		if (!local && (p->level != 0)) {
			subtilis_error_variable_bad_level(
			    err, var_name, p->l->stream->name, p->l->line);
			subtilis_type_free(&element_type);
			goto cleanup;
		}

		if (vec)
			prv_create_vector(p, local_global, &element_type, &dims,
					  e, var_name, local, err);
		else
			prv_create_array(p, local_global, &element_type, dims,
					 e, var_name, local, err);
		subtilis_type_free(&element_type);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		for (i = 0; i < dims; i++)
			subtilis_exp_delete(e[i]);
		dims = 0;

		free(var_name);
		var_name = NULL;

		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		tbuf = subtilis_token_get_text(t);
	} while (t->type == SUBTILIS_TOKEN_OPERATOR && !strcmp(tbuf, ","));

cleanup:
	for (i = 0; i < dims; i++)
		subtilis_exp_delete(e[i]);

	free(var_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
leaq 0xf(%rsp), %rax
movb $0x0, (%rax)
movl %edx, %eax
leaq 0x8(%rsi), %rcx
movq %rcx, 0x28(%rsp)
leaq 0x60(,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
incq %rax
movq %rax, 0x18(%rsp)
leaq 0x1d0(%rsp), %r13
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x17253
movq %r15, %rdi
callq 0x12a25
cmpl $0x6, (%r15)
jne 0x1717d
testb %bpl, %bpl
jne 0x16e5e
movq 0x48(%r14), %rcx
cmpb $0x1, 0xe0(%rcx)
je 0x171c2
movq %r15, %rdi
callq 0x12a25
movq %rax, %r12
movq 0x68(%r14), %rdi
movq %rax, %rsi
callq 0x2d376
testq %rax, %rax
jne 0x17153
testb %bpl, %bpl
jne 0x16e98
movq 0x60(%r14), %rdi
movq %r12, %rsi
callq 0x2d376
testq %rax, %rax
jne 0x17153
movq %r12, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x171a6
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x12070
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x2db73
cmpl $0x0, (%rbx)
jne 0x17146
movl 0x1d0(%rsp), %eax
cmpl $0x16, %eax
je 0x16eec
cmpl $0x9, %eax
jne 0x16f08
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1eb36
cmpl $0x0, (%rbx)
jne 0x17146
movq %r14, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
pushq $0xa
popq %rcx
leaq 0xf(%rsp), %r8
movq %rbx, %r9
callq 0x160ec
movq %rax, %r12
movl (%rbx), %eax
testl %eax, %eax
jne 0x1710c
testb %bpl, %bpl
jne 0x16f40
cmpq $0x0, 0x78(%r14)
jne 0x171f4
cmpb $0x1, 0xf(%rsp)
jne 0x16fbe
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movq %rbx, %rdx
callq 0x3f3e3
cmpl $0x0, (%rbx)
jne 0x17092
testq %r12, %r12
je 0x17065
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0x2cbb7
cmpl $0x0, (%rbx)
jne 0x17085
movq (%rax), %rsi
movq 0x30(%rsp), %rcx
subq $0x8, %rsp
movq %r14, %rdi
leaq 0x90(%rsp), %rdx
movq 0x20(%rsp), %r8
pushq $0x1
popq %r9
pushq %rbx
callq 0x3f601
jmp 0x1704a
testq %r12, %r12
je 0x1704e
movl $0x8, 0x88(%rsp)
subq $0x8, %rsp
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
leaq 0x90(%rsp), %rcx
leaq 0x38(%rsp), %r8
movq %r12, %r9
pushq %rbx
callq 0x3f30f
popq %rax
popq %rcx
cmpl $0x0, (%rbx)
jne 0x17092
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0x2cbb7
cmpl $0x0, (%rbx)
jne 0x17085
movq (%rax), %rcx
movq %r14, %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
leaq 0x30(%rsp), %r8
movq 0x18(%rsp), %r9
pushq %rbx
pushq $0x1
callq 0x3f0d9
popq %rax
popq %rcx
jmp 0x17085
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
pushq $0x1c
popq %rsi
callq 0x1429e
jmp 0x17092
pushq $-0x1
popq %rdi
movq %rbx, %rsi
callq 0x2a369
movq %rax, 0x30(%rsp)
cmpl $0x0, (%rbx)
pushq $0x1
popq %r12
je 0x16f6c
xorl %r12d, %r12d
leaq 0x88(%rsp), %rdi
callq 0x2dc7c
movq %r13, %rdi
callq 0x2dc7c
cmpl $0x0, (%rbx)
jne 0x17149
movl %ebp, %r13d
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x170bc
movq 0x30(%rsp,%rbp,8), %rdi
callq 0x29d88
incq %rbp
jmp 0x170a8
movq 0x10(%rsp), %rdi
callq 0x122c0
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12e0e
cmpl $0x0, (%rbx)
jne 0x17101
movq %r15, %rdi
callq 0x12a25
cmpl $0x2, (%r15)
jne 0x17101
cmpb $0x2c, (%rax)
jne 0x17101
cmpb $0x0, 0x1(%rax)
movl %r13d, %ebp
leaq 0x1d0(%rsp), %r13
je 0x16e1f
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x17235
cmpl $0x16, %eax
movq 0x10(%rsp), %r15
jne 0x17228
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x563bc(%rip), %rax     # 0x6d4e8
leaq 0x56c92(%rip), %rcx     # 0x6ddc5
pushq $0x36
popq %rsi
movq %rbx, %rdi
movq %r15, %rdx
pushq $0x50a                  # imm = 0x50A
jmp 0x17220
xorl %r12d, %r12d
movq 0x10(%rsp), %r15
jmp 0x17235
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x56383(%rip), %rax     # 0x6d4e8
leaq 0x56c59(%rip), %rcx     # 0x6ddc5
pushq $0x20
popq %rsi
movq %rbx, %rdi
movq %r12, %rdx
pushq $0x4f0                  # imm = 0x4F0
pushq %rax
jmp 0x171eb
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56359(%rip), %r10     # 0x6d4e8
leaq 0x56c2f(%rip), %rcx     # 0x6ddc5
pushq $0x12
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
pushq $0x4e2                  # imm = 0x4E2
jmp 0x171e9
leaq 0x5633b(%rip), %rdx     # 0x6d4e8
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x4f6, %ecx            # imm = 0x4F6
callq 0x1429e
jmp 0x17253
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56314(%rip), %r10     # 0x6d4e8
leaq 0x56bea(%rip), %rcx     # 0x6ddc5
pushq $0x6c
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
pushq $0x4e8                  # imm = 0x4E8
pushq %r10
callq 0x140cd
popq %rax
popq %rcx
jmp 0x17253
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x562e2(%rip), %rax     # 0x6d4e8
leaq 0x56bb8(%rip), %rcx     # 0x6ddc5
pushq $0x3e
popq %rsi
movq %rbx, %rdi
movq 0x10(%rsp), %r15
movq %r15, %rdx
pushq $0x515                  # imm = 0x515
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
leaq 0x1d0(%rsp), %rdi
callq 0x2dc7c
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x1724b
movq 0x30(%rsp,%rbx,8), %rdi
callq 0x29d88
incq %rbx
jmp 0x17237
movq %r15, %rdi
callq 0x122c0
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq