// File: /workspace/github_c_makefile_star2_O1/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 0x12eda
cmpl $0x0, (%rbx)
jne 0x17514
movq %r15, %rdi
callq 0x12ad0
cmpl $0x6, (%r15)
jne 0x17430
testb %bpl, %bpl
jne 0x170f2
movq 0x48(%r14), %rcx
cmpb $0x1, 0xe0(%rcx)
je 0x17479
movq %r15, %rdi
callq 0x12ad0
movq %rax, %r12
movq 0x68(%r14), %rdi
movq %rax, %rsi
callq 0x2eec8
testq %rax, %rax
jne 0x17404
testb %bpl, %bpl
jne 0x1712c
movq 0x60(%r14), %rdi
movq %r12, %rsi
callq 0x2eec8
testq %rax, %rax
jne 0x17404
movq %r12, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x1745b
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x12070
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x2f72e
cmpl $0x0, (%rbx)
jne 0x173fc
movl 0x1d0(%rsp), %eax
cmpl $0x16, %eax
je 0x17180
cmpl $0x9, %eax
jne 0x1719c
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1f7e6
cmpl $0x0, (%rbx)
jne 0x173fc
movl $0xa, %ecx
movq %r14, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
leaq 0xf(%rsp), %r8
movq %rbx, %r9
callq 0x16618
movq %rax, %r12
movl (%rbx), %eax
testl %eax, %eax
jne 0x173c3
testb %bpl, %bpl
jne 0x171d6
cmpq $0x0, 0x78(%r14)
jne 0x174af
cmpb $0x1, 0xf(%rsp)
jne 0x17256
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movq %rbx, %rdx
callq 0x41a71
cmpl $0x0, (%rbx)
jne 0x1732b
testq %r12, %r12
je 0x17303
leaq 0x88(%rsp), %rdx
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rcx
callq 0x2e6e8
cmpl $0x0, (%rbx)
jne 0x1731e
movq (%rax), %rsi
movq 0x30(%rsp), %rcx
subq $0x8, %rsp
movq %r14, %rdi
leaq 0x90(%rsp), %rdx
movq 0x20(%rsp), %r8
movl $0x1, %r9d
pushq %rbx
callq 0x41c97
jmp 0x172e4
testq %r12, %r12
je 0x172ea
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 0x41994
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x1732b
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0x2e6e8
cmpl $0x0, (%rbx)
jne 0x1731e
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 0x4172a
addq $0x10, %rsp
jmp 0x1731e
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x1c, %esi
callq 0x145f4
jmp 0x1732b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rbx, %rsi
callq 0x2bb29
movq %rax, 0x30(%rsp)
cmpl $0x0, (%rbx)
je 0x173a7
leaq 0x88(%rsp), %rdi
callq 0x2f843
movq %r13, %rdi
callq 0x2f843
cmpl $0x0, (%rbx)
jne 0x174f1
movl %ebp, %r13d
testq %r12, %r12
je 0x17358
xorl %ebp, %ebp
movq 0x30(%rsp,%rbp,8), %rdi
callq 0x2b4c3
incq %rbp
cmpq %rbp, %r12
jne 0x17346
movq 0x10(%rsp), %rdi
callq 0x122c0
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12eda
cmpl $0x0, (%rbx)
jne 0x173b2
movq %r15, %rdi
callq 0x12ad0
cmpl $0x2, (%r15)
jne 0x173b2
movq %rax, %rdi
leaq 0x5c20b(%rip), %rsi     # 0x73598
callq 0x12160
testl %eax, %eax
movl %r13d, %ebp
leaq 0x1d0(%rsp), %r13
je 0x170b3
jmp 0x173b2
movl $0x1, %r12d
jmp 0x17202
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
jmp 0x174f1
cmpl $0x16, %eax
jne 0x174e4
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c10e(%rip), %rax     # 0x734ec
leaq 0x5ca10(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x36, %esi
movq 0x10(%rsp), %rdx
pushq $0x50a                  # imm = 0x50A
jmp 0x174da
xorl %r12d, %r12d
jmp 0x174f1
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c0d6(%rip), %rax     # 0x734ec
leaq 0x5c9d8(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x20, %esi
movq %r12, %rdx
pushq $0x4f0                  # imm = 0x4F0
pushq %rax
jmp 0x174a4
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5c0aa(%rip), %r10     # 0x734ec
leaq 0x5c9ac(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x12, %esi
movq %rax, %rdx
pushq $0x4e2                  # imm = 0x4E2
jmp 0x174a2
leaq 0x5c08a(%rip), %rdx     # 0x734ec
movq %rbx, %rdi
movl $0x1, %esi
movl $0x4f6, %ecx            # imm = 0x4F6
callq 0x145f4
jmp 0x17514
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5c061(%rip), %r10     # 0x734ec
leaq 0x5c963(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x6c, %esi
movq %rax, %rdx
pushq $0x4e8                  # imm = 0x4E8
pushq %r10
callq 0x1442a
addq $0x10, %rsp
jmp 0x17514
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c02b(%rip), %rax     # 0x734ec
leaq 0x5c92d(%rip), %rcx     # 0x73df5
movq %rbx, %rdi
movl $0x3e, %esi
movq 0x10(%rsp), %rdx
pushq $0x515                  # imm = 0x515
pushq %rax
callq 0x1442a
addq $0x10, %rsp
leaq 0x1d0(%rsp), %rdi
callq 0x2f843
testq %r12, %r12
je 0x1750a
xorl %ebx, %ebx
movq 0x30(%rsp,%rbx,8), %rdi
callq 0x2b4c3
incq %rbx
cmpq %rbx, %r12
jne 0x174f8
movq 0x10(%rsp), %rdi
callq 0x122c0
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq