// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/array_type.c
// Function: subtilis_array_type_slice_vector
subtilis_exp_t *subtilis_array_type_slice_vector(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;
	size_t size_reg;
	const subtilis_symbol_t *s;
	subtilis_ir_operand_t empty;
	subtilis_ir_operand_t not_empty;
	subtilis_exp_t *max_dim = NULL;

	subtilis_ir_operand_t op0;
	char *tmp_name = NULL;

	empty.label = subtilis_ir_section_new_label(p->current);
	not_empty.label = subtilis_ir_section_new_label(p->current);

	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_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;

	s = subtilis_symbol_table_insert_tmp(p->local_st, 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;

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

	op0.reg = size_reg;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  op0, not_empty, empty, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, not_empty.label, 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_ir_section_add_label(p->current, empty.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_exp_delete(max_dim);
	return subtilis_exp_new_tmp_var(type, dest_reg, tmp_name, err);

cleanup:

	subtilis_exp_delete(max_dim);
	free(tmp_name);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
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, -0x78(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5d190
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5cf43
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 0x5d200
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5cf41
movq $0x0, -0x8(%rbp)
jmp 0x5d180
jmp 0x5cf43
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 0x5cf76
movq $0x0, -0x8(%rbp)
jmp 0x5d180
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 0x5cfa5
movq $0x0, -0x8(%rbp)
jmp 0x5d180
cmpq $0x0, -0x38(%rbp)
je 0x5cfd3
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 0x5cff4
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, -0x78(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d00a
movq $0x0, -0x8(%rbp)
jmp 0x5d180
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rcx
leaq -0x88(%rbp), %rdx
callq 0x3c920
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d038
jmp 0x5d163
movq -0x10(%rbp), %rdi
movq -0x60(%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 0x5d063
jmp 0x5d163
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 %rax, -0x58(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d09a
jmp 0x5d163
movq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq 0x10(%rbp), %r9
movq -0x80(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d0d2
jmp 0x5d163
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x70(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d0f2
jmp 0x5d163
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 0x5d11a
jmp 0x5d163
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x68(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x39960
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x5d13a
jmp 0x5d163
movq -0x78(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %esi
movq -0x88(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x375f0
movq %rax, -0x8(%rbp)
jmp 0x5d180
movq -0x78(%rbp), %rdi
callq 0x36ee0
movq -0x88(%rbp), %rdi
callq 0x12290
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)