// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movb 0x10(%rbp), %al
movq %r9, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5bbb0
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq %rcx, %rax
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jbe 0x5be76
movq 0x18(%rbp), %rdi
movl $0xf, %esi
leaq 0x50b16(%rip), %rdx     # 0xac97d
movl $0x1ef, %ecx            # imm = 0x1EF
callq 0x158e0
jmp 0x5c06b
movq -0x20(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x5bebf
movq -0x20(%rbp), %rax
cmpl $-0x1, 0xc(%rax)
jne 0x5bebf
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movb -0x31(%rbp), %r9b
movq 0x18(%rbp), %rax
movq -0x8(%rbp), %r8
andb $0x1, %r9b
movzbl %r9b, %r9d
movq %rax, (%rsp)
callq 0x5ca50
jmp 0x5c06b
movq -0x28(%rbp), %rax
addl $0x10, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rcx
movq 0x18(%rbp), %r8
callq 0x5cb60
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5bef8
jmp 0x5c062
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jae 0x5bfac
movl -0x54(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x18(%rbp), %rdx
callq 0x47c10
movq %rax, %rdx
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5bf51
jmp 0x5c062
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %r9
movq 0x148(%rax), %rdx
movq -0x8(%rbp), %rcx
movq -0x48(%rbp), %r8
movl $0x17, %esi
callq 0x38360
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5bf90
jmp 0x5c062
movslq -0x54(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x5bf00
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x18(%rbp), %rcx
callq 0x474f0
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5bfd3
jmp 0x5c062
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq 0x18(%rbp), %rdx
callq 0x47c10
movq %rax, -0x60(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5bff3
jmp 0x5c062
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rcx
movq -0x60(%rbp), %rax
movq 0x148(%rax), %r8
movb -0x31(%rbp), %r9b
movq 0x18(%rbp), %rax
andb $0x1, %r9b
movzbl %r9b, %r9d
movq %rax, (%rsp)
callq 0x6e3e0
movq %rax, -0x40(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5c036
jmp 0x5c062
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x60(%rbp), %rax
movq 0x148(%rax), %rcx
movq -0x40(%rbp), %r9
movq 0x18(%rbp), %rax
movq -0x8(%rbp), %r8
movq %rax, (%rsp)
callq 0x5ce40
movq -0x60(%rbp), %rdi
callq 0x36ee0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)