// File: /workspace/github_c_makefile_star2_O3/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 0x12edc
cmpl $0x0, (%rbx)
jne 0x1746a
movq %r15, %rdi
callq 0x12ad0
cmpl $0x6, (%r15)
jne 0x17386
testb %bpl, %bpl
jne 0x1705f
movq 0x48(%r14), %rcx
cmpb $0x1, 0xe0(%rcx)
je 0x173cf
movq %r15, %rdi
callq 0x12ad0
movq %rax, %r12
movq 0x68(%r14), %rdi
movq %rax, %rsi
callq 0x2ebbc
testq %rax, %rax
jne 0x1735a
testb %bpl, %bpl
jne 0x17099
movq 0x60(%r14), %rdi
movq %r12, %rsi
callq 0x2ebbc
testq %rax, %rax
jne 0x1735a
movq %r12, %rdi
callq 0x120f0
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x173b1
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x12070
movq %r13, %rdi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x2f457
cmpl $0x0, (%rbx)
jne 0x17460
movl 0x1d0(%rsp), %eax
cmpl $0x16, %eax
je 0x170ed
cmpl $0x9, %eax
jne 0x17109
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1f81b
cmpl $0x0, (%rbx)
jne 0x17460
movl $0xa, %ecx
movq %r14, %rdi
movq %r15, %rsi
leaq 0x30(%rsp), %rdx
leaq 0xf(%rsp), %r8
movq %rbx, %r9
callq 0x16594
movq %rax, %r12
movl (%rbx), %eax
testl %eax, %eax
jne 0x17321
testb %bpl, %bpl
jne 0x17143
cmpq $0x0, 0x78(%r14)
jne 0x17405
cmpb $0x1, 0xf(%rsp)
jne 0x171c3
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movq %rbx, %rdx
callq 0x41944
cmpl $0x0, (%rbx)
jne 0x1729b
testq %r12, %r12
je 0x17270
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0x2e3cd
cmpl $0x0, (%rbx)
jne 0x1728e
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 0x41b6a
jmp 0x17251
testq %r12, %r12
je 0x17257
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 0x41867
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x1729b
movq 0x20(%rsp), %rax
movq (%r14,%rax), %rdi
movq 0x10(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rcx
callq 0x2e3cd
cmpl $0x0, (%rbx)
jne 0x1728e
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 0x41600
addq $0x10, %rsp
jmp 0x1728e
movq (%r14), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
movq %rbx, %rdi
movl $0x1c, %esi
callq 0x145a4
jmp 0x1729b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movq %rbx, %rsi
callq 0x2b7af
movq %rax, 0x30(%rsp)
cmpl $0x0, (%rbx)
je 0x1730f
xorl %r12d, %r12d
leaq 0x88(%rsp), %rdi
callq 0x2f56e
movq %r13, %rdi
callq 0x2f56e
cmpl $0x0, (%rbx)
jne 0x17447
movl %ebp, %r13d
testq %r12, %r12
je 0x172c8
xorl %ebp, %ebp
movq 0x30(%rsp,%rbp,8), %rdi
callq 0x2b166
incq %rbp
cmpq %rbp, %r12
jne 0x172b6
movq 0x10(%rsp), %rdi
callq 0x122c0
movq (%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x12edc
cmpl $0x0, (%rbx)
jne 0x1731a
movq %r15, %rdi
callq 0x12ad0
cmpl $0x2, (%r15)
jne 0x1731a
cmpb $0x2c, (%rax)
jne 0x1731a
cmpb $0x0, 0x1(%rax)
movl %r13d, %ebp
leaq 0x1d0(%rsp), %r13
je 0x17020
jmp 0x1731a
movl $0x1, %r12d
jmp 0x1716f
xorl %edi, %edi
jmp 0x17465
cmpl $0x16, %eax
jne 0x1743a
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c1ac(%rip), %rax     # 0x734e8
leaq 0x5cad2(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x36, %esi
movq 0x10(%rsp), %rdx
pushq $0x50a                  # imm = 0x50A
jmp 0x17430
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c17c(%rip), %rax     # 0x734e8
leaq 0x5caa2(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x20, %esi
movq %r12, %rdx
pushq $0x4f0                  # imm = 0x4F0
pushq %rax
jmp 0x173fa
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5c150(%rip), %r10     # 0x734e8
leaq 0x5ca76(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x12, %esi
movq %rax, %rdx
pushq $0x4e2                  # imm = 0x4E2
jmp 0x173f8
leaq 0x5c130(%rip), %rdx     # 0x734e8
movq %rbx, %rdi
movl $0x1, %esi
movl $0x4f6, %ecx            # imm = 0x4F6
callq 0x145a4
jmp 0x1746a
movq (%r14), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5c107(%rip), %r10     # 0x734e8
leaq 0x5ca2d(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x6c, %esi
movq %rax, %rdx
pushq $0x4e8                  # imm = 0x4E8
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x1746a
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x5c0d1(%rip), %rax     # 0x734e8
leaq 0x5c9f7(%rip), %rcx     # 0x73e15
movq %rbx, %rdi
movl $0x3e, %esi
movq 0x10(%rsp), %rdx
pushq $0x515                  # imm = 0x515
pushq %rax
callq 0x143da
addq $0x10, %rsp
leaq 0x1d0(%rsp), %rdi
callq 0x2f56e
testq %r12, %r12
je 0x17460
xorl %ebx, %ebx
movq 0x30(%rsp,%rbx,8), %rdi
callq 0x2b166
incq %rbx
cmpq %rbx, %r12
jne 0x1744e
movq 0x10(%rsp), %rdi
callq 0x122c0
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq