// File: /workspace/github_c_makefile_star2_O3/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 0x41654
leaq 0x343d2(%rip), %rdx     # 0x75a06
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 0x145a4
movq %r8, %rbp
movq %rdx, %rbx
movq %rdi, %r15
movb 0x60(%rsp), %r13b
cmpl $0x1, %ecx
jne 0x41671
cmpl $-0x1, 0xc(%rbx)
je 0x41788
movq %r15, %rdi
movq %rbp, %rdx
movq %r14, %r8
callq 0x41f66
cmpl $0x0, (%r14)
jne 0x41851
movq %rax, 0x10(%rsp)
movb %r13b, 0xf(%rsp)
movq %r12, 0x18(%rsp)
cmpl $0x0, 0x8(%rbx)
je 0x41703
movq 0x18(%rsp), %rax
leal 0x10(%rax), %r12d
xorl %r13d, %r13d
movq (%rbp,%r13,8), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x36119
movq %rax, (%rbp,%r13,8)
cmpl $0x0, (%r14)
jne 0x4184c
movq 0x48(%r15), %rdi
movq 0x148(%rax), %rdx
movl %r12d, %r8d
movl $0x17, %esi
movq 0x20(%rsp), %rcx
movq %r14, %r9
callq 0x2bd42
cmpl $0x0, (%r14)
jne 0x4184c
addl $0x4, %r12d
incq %r13
movslq 0x8(%rbx), %rax
cmpq %rax, %r13
jb 0x416aa
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x35ddb
cmpl $0x0, (%r14)
jne 0x41851
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x36119
cmpl $0x0, (%r14)
jne 0x41851
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 0x4ddaa
cmpl $0x0, (%r14)
jne 0x41780
movq 0x148(%r12), %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq %r14, %r8
callq 0x3666c
movq %r12, %rax
jmp 0x41851
movq (%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%r15), %rdi
movq 0xb0(%rdi), %rbp
cmpq $-0x1, %rbp
jne 0x417b5
callq 0x2cc99
movq %rax, %rbp
movq 0x48(%r15), %rdi
movq %rax, 0xb0(%rdi)
callq 0x2cc99
movq %rax, 0x18(%rsp)
movq 0x48(%r15), %rdi
movq 0x10(%rsp), %rax
movq 0x148(%rax), %rdx
movl $0x41, %esi
xorl %ecx, %ecx
movq %r14, %r8
callq 0x2bc8f
cmpl $0x0, (%r14)
jne 0x4183d
movq 0x48(%r15), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x2bd42
cmpl $0x0, (%r14)
jne 0x4183d
movq 0x48(%r15), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x2cca6
cmpl $0x0, (%r14)
jne 0x4183d
movq %r14, (%rsp)
movzbl %r13b, %r9d
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
callq 0x41e3f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b166