// File: /workspace/github_c_makefile_star2_O1/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 0x4177e
leaq 0x34264(%rip), %rdx     # 0x759c2
movq %r14, %rdi
movl $0xf, %esi
movl $0x1ef, %ecx            # imm = 0x1EF
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145f4
movq %r8, %rbp
movq %rdx, %rbx
movq %rdi, %r15
movb 0x60(%rsp), %r13b
cmpl $0x1, %ecx
jne 0x4179b
cmpl $-0x1, 0xc(%rbx)
je 0x418b2
movq %r15, %rdi
movq %rbp, %rdx
movq %r14, %r8
callq 0x42093
cmpl $0x0, (%r14)
jne 0x4197e
movq %rax, 0x8(%rsp)
movb %r13b, 0x18(%rsp)
movq %r12, 0x10(%rsp)
cmpl $0x0, 0x8(%rbx)
je 0x4182d
movq 0x10(%rsp), %rax
leal 0x10(%rax), %r12d
xorl %r13d, %r13d
movq (%rbp,%r13,8), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x36269
movq %rax, (%rbp,%r13,8)
cmpl $0x0, (%r14)
jne 0x41979
movq 0x48(%r15), %rdi
movq 0x148(%rax), %rdx
movl %r12d, %r8d
movl $0x17, %esi
movq 0x20(%rsp), %rcx
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x41979
addl $0x4, %r12d
incq %r13
movslq 0x8(%rbx), %rax
cmpq %rax, %r13
jb 0x417d4
movq %r15, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
movq %r14, %rcx
callq 0x35f2b
cmpl $0x0, (%r14)
jne 0x4197e
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x36269
cmpl $0x0, (%r14)
jne 0x4197e
movq 0x148(%rax), %r8
movq %r14, (%rsp)
movzbl 0x18(%rsp), %r9d
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rax, %r12
callq 0x4ddee
cmpl $0x0, (%r14)
jne 0x418aa
movq 0x148(%r12), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq %r14, %r8
callq 0x367bc
movq %r12, %rax
jmp 0x4197e
movq (%rbp), %rbp
movq 0x48(%r15), %rdi
movq 0xb0(%rdi), %rax
cmpq $-0x1, %rax
jne 0x418d7
callq 0x2d00a
movq 0x48(%r15), %rcx
movq %rax, 0xb0(%rcx)
movq %rax, 0x10(%rsp)
movq 0x48(%r15), %rdi
callq 0x2d00a
movq %rax, 0x8(%rsp)
movq 0x48(%r15), %rdi
movq %rbp, 0x18(%rsp)
movq 0x148(%rbp), %rdx
movl $0x41, %esi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x2c00f
cmpl $0x0, (%r14)
jne 0x4196a
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %r14, %r9
callq 0x2c0c2
cmpl $0x0, (%r14)
jne 0x4196a
movq 0x48(%r15), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x2d017
cmpl $0x0, (%r14)
jne 0x4196a
movq %r14, (%rsp)
movzbl %r13b, %r9d
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
callq 0x41f6c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b4c3