// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x1b0(%rbp)
movq $0x0, -0x1b8(%rbp)
movl $0x8, -0x1a0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5d190
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5dc9e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %r8
callq 0x5df00
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5dc9c
movq $0x0, -0x8(%rbp)
jmp 0x5deee
jmp 0x5dc9e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r9
movq -0x40(%rbp), %r8
callq 0x5d390
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5dcd1
movq $0x0, -0x8(%rbp)
jmp 0x5deee
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x6d920
movq %rax, -0x48(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5dd00
movq $0x0, -0x8(%rbp)
jmp 0x5deee
cmpq $0x0, -0x38(%rbp)
je 0x5dd2e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %r8
movq 0x10(%rbp), %rax
movq -0x40(%rbp), %r9
movq %rax, (%rsp)
callq 0x5d520
jmp 0x5dd52
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x5d6b0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5dd68
movq $0x0, -0x8(%rbp)
jmp 0x5deee
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
leaq -0x1a0(%rbp), %rdi
callq 0x3dec0
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5dd8a
jmp 0x5dec2
movq -0x30(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x5ddbb
movq -0x38(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x5ddbb
movq -0x38(%rbp), %rax
movl 0x148(%rax), %eax
movq -0x30(%rbp), %rcx
subl 0x148(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x194(%rbp)
jmp 0x5ddc5
movl $0xffffffff, -0x194(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
movq 0x10(%rbp), %rcx
leaq -0x1a0(%rbp), %rsi
leaq -0x1b8(%rbp), %rdx
callq 0x3c920
movq %rax, -0x58(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5ddf6
jmp 0x5dec2
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rdx
movq 0x10(%rbp), %rcx
movl $0x2, %esi
callq 0x6d920
movq %rax, -0x50(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5de21
jmp 0x5dec2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %rax
movq %rax, (%rsp)
callq 0x5d780
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5de51
jmp 0x5dec2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %r9
callq 0x5da00
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5de79
jmp 0x5dec2
movq -0x1b0(%rbp), %rdi
callq 0x36ee0
movq -0x50(%rbp), %rax
movl %eax, %esi
movq -0x1b8(%rbp), %rdx
movq 0x10(%rbp), %rcx
leaq -0x1a0(%rbp), %rdi
callq 0x375f0
movq %rax, -0x1a8(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x3e100
movq -0x1a8(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5deee
movq -0x1b0(%rbp), %rdi
callq 0x36ee0
movq -0x1b8(%rbp), %rdi
callq 0x12290
leaq -0x1a0(%rbp), %rdi
callq 0x3e100
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopl (%rax,%rax)