// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_slice_array
subtilis_exp_t *subtilis_array_type_slice_array(subtilis_parser_t *p,
						const subtilis_type_t *type,
						size_t mem_reg, size_t loc,
						subtilis_exp_t *index1,
						subtilis_exp_t *index2,
						subtilis_error_t *err)
{
	subtilis_ir_operand_t error_label;
	size_t source_reg;
	size_t dest_reg;
	const subtilis_symbol_t *s;
	subtilis_type_t array_type;
	subtilis_exp_t *ret_val;
	subtilis_exp_t *max_dim = NULL;
	char *tmp_name = NULL;

	array_type.type = SUBTILIS_TYPE_VOID;

	error_label = subtilis_array_type_error_label(p);

	/*
	 * index2 may be NULL if the second slice parameter was omitted.
	 */

	/*
	 * Check the indices are sane, i.e., that index1 <= index 2.
	 */

	if (index2) {
		prv_check_slice_array_indices(p, type, index1, index2,
					      error_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return NULL;
	}

	/*
	 * We now know that index1 must be < index2.  We need to check that
	 * index1 is >= 0.
	 */

	prv_check_slice_index1(p, type, index1, index2, error_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	source_reg = subtilis_reference_get_pointer(p, mem_reg, loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	/*
	 * Finally, we need to check that index2 <= max_dim + 1.
	 */

	if (index2) {
		prv_check_slice_index2(p, type, index1, index2, source_reg,
				       error_label, err);
	} else {
		index2 = prv_calc_max_dim(p, type, source_reg, err);
		max_dim = index2;
	}
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	subtilis_type_init_copy(&array_type, type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if ((index1->type.type == SUBTILIS_TYPE_CONST_INTEGER) &&
	    (index2->type.type == SUBTILIS_TYPE_CONST_INTEGER))
		array_type.params.array.dims[0] =
		    (index2->exp.ir_op.integer - index1->exp.ir_op.integer) - 1;
	else
		array_type.params.array.dims[0] = SUBTILIS_DYNAMIC_DIMENSION;
	s = subtilis_symbol_table_insert_tmp(p->local_st, &array_type,
					     &tmp_name, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	dest_reg = subtilis_reference_get_pointer(p, SUBTILIS_IR_REG_LOCAL,
						  s->loc, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	(void)prv_slice_set_sizes(p, type, source_reg, dest_reg, index1, index2,
				  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_slice_set_pointers(p, type, source_reg, dest_reg, index1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(max_dim);

	ret_val =
	    subtilis_exp_new_tmp_var(&array_type, dest_reg, tmp_name, err);
	subtilis_type_free(&array_type);
	return ret_val;

cleanup:

	subtilis_exp_delete(max_dim);
	free(tmp_name);
	subtilis_type_free(&array_type);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r9, %r13
movq %r8, %r14
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movq $0x0, 0x20(%rsp)
movl $0x8, 0x40(%rsp)
movq 0x48(%rdi), %rdi
movq 0xb0(%rdi), %rbp
cmpq $-0x1, %rbp
jne 0x42bf4
callq 0x2d00a
movq %rax, %rbp
movq 0x48(%r12), %rax
movq %rbp, 0xb0(%rax)
movq 0x1c0(%rsp), %r15
testq %r13, %r13
je 0x42d00
cmpl $0x1, (%r14)
movq %r14, 0x38(%rsp)
jne 0x42c5e
cmpl $0x1, (%r13)
jne 0x42c5e
movl 0x148(%r14), %edx
movl 0x148(%r13), %ecx
cmpl %ecx, %edx
jl 0x42cf1
movq (%r12), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x32d82(%rip), %rax     # 0x759c2
movq %rax, (%rsp)
movl $0x3e7, 0x8(%rsp)       # imm = 0x3E7
movq %r15, %rdi
movl $0x65, %esi
callq 0x144d6
jmp 0x42cf1
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0x362d2
cmpl $0x0, (%r15)
jne 0x42cf1
movq %rax, %r14
movq %r13, %rdi
movq %r15, %rsi
callq 0x362d2
cmpl $0x0, (%r15)
je 0x42c9a
movq %r14, %rdi
callq 0x2b4c3
jmp 0x42cf1
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x37258
cmpl $0x0, (%r15)
jne 0x42cf1
movq %rax, %r14
movq 0x48(%r12), %rdi
movq 0x148(%rax), %rdx
movl $0x43, %esi
movq %rbx, %rcx
movq %rbp, %r8
movq %r15, %r9
callq 0x2c0c2
movq %r14, %rdi
callq 0x2b4c3
cmpl $0x0, (%r15)
jne 0x42cf1
movq 0x48(%r12), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
movq 0x38(%rsp), %r14
jne 0x42d80
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x4259e
cmpl $0x0, (%r15)
jne 0x42d80
movq %r14, %rbx
movq %r12, %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
jne 0x42d80
movq %rax, %r14
testq %r13, %r13
je 0x42d61
movq %r15, (%rsp)
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0x4269c
xorl %ebp, %ebp
jmp 0x42d7a
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x427b4
movq %rax, %r13
movq %rax, %rbp
cmpl $0x0, (%r15)
je 0x42d97
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x2f72e
cmpl $0x0, (%r15)
jne 0x42e51
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x1, (%rbx)
jne 0x42dd3
cmpl $0x1, (%r13)
jne 0x42dd3
movl 0x148(%rbx), %eax
notl %eax
addl 0x148(%r13), %eax
leaq 0x40(%rsp), %rsi
movl %eax, 0xc(%rsi)
movq 0x68(%r12), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rcx
callq 0x2ea12
cmpl $0x0, (%r15)
jne 0x42e51
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
jne 0x42e51
movq %r15, (%rsp)
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %rax, %rcx
movq %rbx, %r8
movq %r13, %r9
movq %rax, %r13
callq 0x42828
cmpl $0x0, (%r15)
jne 0x42e51
movq %r13, %rcx
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %r8
movq %r15, %r9
callq 0x42a33
cmpl $0x0, (%r15)
je 0x42e74
movq %rbp, %rdi
callq 0x2b4c3
movq 0x20(%rsp), %rdi
callq 0x122c0
xorl %ebx, %ebx
leaq 0x40(%rsp), %rdi
callq 0x2f843
jmp 0x42d82
movq %rbp, %rdi
movq %r13, %rbx
callq 0x2b4c3
movq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rcx
callq 0x2b99d
movq %rax, %rbx
jmp 0x42e65