// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_allocate
void subtilis_array_type_allocate(subtilis_parser_t *p, const char *var_name,
				  const subtilis_type_t *type, size_t loc,
				  subtilis_exp_t **e,
				  subtilis_ir_operand_t store_reg, bool push,
				  subtilis_error_t *err)
{
	subtilis_ir_operand_t op;
	subtilis_ir_operand_t op1;
	size_t i;
	int32_t offset;
	subtilis_exp_t *sizee = NULL;

	if (loc + subtilis_array_type_size(type) > 0x7fffffff) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	/*
	 * We have a separate allocation path for dynamically sized
	 * 1-dimensional arrays.
	 */

	if ((type->params.array.num_dims == 1) &&
	    (type->params.array.dims[0] == SUBTILIS_DYNAMIC_DIMENSION)) {
		prv_1d_dynamic_alloc(p, loc, type, e[0], store_reg, push, err);
		return;
	}

	offset = ((int32_t)loc) + SUBTIILIS_ARRAY_DIMS_OFF;

	sizee = subtilis_array_size_calc(p, var_name, e,
					 type->params.array.num_dims, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	for (i = 0; i < type->params.array.num_dims; i++) {
		op1.integer = offset;
		e[i] = subtilis_type_if_exp_to_var(p, e[i], err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_STOREO_I32, e[i]->exp.ir_op,
		    store_reg, op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		offset += sizeof(int32_t);
	}

	sizee = subtilis_type_if_data_size(p, type, sizee, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	sizee = subtilis_type_if_exp_to_var(p, sizee, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op.reg = subtilis_reference_type_alloc(p, type, loc, store_reg.reg,
					       sizee->exp.ir_op.reg, push, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_clear_new_array(p, type, loc, sizee->exp.ir_op.reg, store_reg,
			    op.reg, err);

cleanup:

	subtilis_exp_delete(sizee);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x20(%rsp)
movq %rcx, %r12
movq 0x68(%rsp), %r14
movslq 0x8(%rdx), %rcx
leaq (%r12,%rcx,4), %rax
addq $0x10, %rax
shrq $0x1f, %rax
je 0x3f12b
leaq 0x30885(%rip), %rdx     # 0x6f992
pushq $0xf
popq %rsi
movq %r14, %rdi
movl $0x1ef, %ecx            # imm = 0x1EF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movq %r8, %rbp
movq %rdx, %rbx
movq %rdi, %r15
movb 0x60(%rsp), %r13b
cmpl $0x1, %ecx
jne 0x3f148
cmpl $-0x1, 0xc(%rbx)
je 0x3f1d6
movq %r15, %rdi
movq %rbp, %rdx
movq %r14, %r8
callq 0x3f9e9
cmpl $0x0, (%r14)
jne 0x3f2f9
movq %rax, 0x10(%rsp)
movb %r13b, 0xf(%rsp)
movq %r12, 0x18(%rsp)
leal 0x10(%r12), %r13d
xorl %r12d, %r12d
movslq 0x8(%rbx), %rax
cmpq %rax, %r12
jae 0x3f281
movq (%rbp,%r12,8), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x3415f
movq %rax, (%rbp,%r12,8)
cmpl $0x0, (%r14)
jne 0x3f1cc
movq 0x48(%r15), %rdi
movq 0x148(%rax), %rdx
movl %r13d, %r8d
pushq $0x17
popq %rsi
movq 0x20(%rsp), %rcx
movq %r14, %r9
callq 0x2a8c1
cmpl $0x0, (%r14)
jne 0x3f1cc
addl $0x4, %r13d
incq %r12
jmp 0x3f177
movq 0x10(%rsp), %rax
jmp 0x3f2f9
movb %r13b, 0xf(%rsp)
movq (%rbp), %rbp
movq %r15, %rdi
callq 0x3feb4
movq %rax, 0x10(%rsp)
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %r13
movq 0x48(%r15), %rdi
movq %rbp, 0x18(%rsp)
movq 0x148(%rbp), %rdx
pushq $0x41
popq %rsi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x3f272
movq 0x48(%r15), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r8
movq %r14, %r9
callq 0x2a8c1
cmpl $0x0, (%r14)
jne 0x3f272
movq 0x48(%r15), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x3f272
movq %r14, (%rsp)
movzbl 0xf(%rsp), %r9d
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
callq 0x3f8c8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x33e43
cmpl $0x0, (%r14)
jne 0x3f2f9
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x3415f
cmpl $0x0, (%r14)
jne 0x3f2f9
movq 0x148(%rax), %r8
movq %r14, (%rsp)
movzbl 0xf(%rsp), %r9d
movq %r15, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rax, %r12
callq 0x4b101
cmpl $0x0, (%r14)
jne 0x3f2f6
movq 0x148(%r12), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq %r14, %r8
callq 0x3467c
movq %r12, %rax
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29d88