// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r12
movq %r8, %r15
movq %rcx, 0x20(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %rbp
movq %rdi, %r14
movq $0x0, 0x30(%rsp)
movq 0x48(%rdi), %rdi
callq 0x2cc99
movq %rax, 0x38(%rsp)
movq 0x48(%r14), %rdi
callq 0x2cc99
movq %rax, 0x40(%rsp)
movq 0x48(%r14), %rdi
movq 0xb0(%rdi), %rbx
cmpq $-0x1, %rbx
jne 0x42181
callq 0x2cc99
movq %rax, %rbx
movq 0x48(%r14), %rdi
movq %rax, 0xb0(%rdi)
movq 0x90(%rsp), %r13
testq %r12, %r12
je 0x42254
cmpl $0x1, (%r15)
jne 0x421e3
cmpl $0x1, (%r12)
jne 0x421e3
movl 0x148(%r15), %edx
movl 0x148(%r12), %ecx
cmpl %ecx, %edx
jle 0x4223e
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x3383e(%rip), %rax     # 0x75a06
movq %rax, (%rsp)
movl $0x23b, 0x8(%rsp)       # imm = 0x23B
movq %r13, %rdi
movl $0x65, %esi
callq 0x14486
jmp 0x4223e
movq %r12, 0x28(%rsp)
movq %rbp, 0x18(%rsp)
callq 0x2cc99
movq %r13, %r12
movq %rax, %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x36182
cmpl $0x0, (%r12)
jne 0x42459
movq %rax, %rbp
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x36182
cmpl $0x0, (%r12)
je 0x422c7
movq %rbp, %rdi
callq 0x2b166
movq 0x18(%rsp), %rbp
movq %r12, %r13
movq 0x28(%rsp), %r12
cmpl $0x0, (%r13)
jne 0x42459
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x4225c
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rbx, %rcx
movq %r13, %r8
callq 0x424b2
cmpl $0x0, (%r13)
jne 0x42459
movq %rbp, 0x18(%rsp)
movq %r14, %rdi
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r13, %rcx
callq 0x4d71f
cmpl $0x0, (%r13)
jne 0x42459
movq %rax, %rbp
testq %r12, %r12
je 0x4233a
movq %r13, (%rsp)
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %rbp, %r8
movq %rbx, %r9
callq 0x425b0
xorl %ebx, %ebx
jmp 0x42356
movq %r14, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0x370d0
cmpl $0x0, (%r12)
jne 0x42459
movq %rax, %rbp
movq 0x48(%r14), %rdi
movq 0x148(%rax), %rdx
movl $0x43, %esi
movq %r13, 0x48(%rsp)
movq %r13, %rcx
movq %rbx, %r8
movq %r12, %r9
callq 0x2bd42
movq %rbp, %rdi
callq 0x2b166
cmpl $0x0, (%r12)
jne 0x42459
movq %r12, %r13
movq 0x48(%r14), %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x2cca6
movq 0x18(%rsp), %rbp
jmp 0x42239
movq 0x18(%rsp), %rax
movl 0xc(%rax), %esi
movq %r14, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x426cd
movq %rax, %rbx
movq %rax, %r12
cmpl $0x0, (%r13)
jne 0x42459
movq 0x68(%r14), %rdi
leaq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq %r13, %rcx
callq 0x2e6f1
cmpl $0x0, (%r13)
jne 0x42447
movq (%rax), %rdx
movl $0x2, %esi
movq %r14, %rdi
movq %r13, %rcx
callq 0x4d71f
cmpl $0x0, (%r13)
jne 0x42447
movq %r13, (%rsp)
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x42740
cmpl $0x0, (%r13)
jne 0x42447
movq 0x48(%r14), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %r13, %r9
callq 0x2bd42
cmpl $0x0, (%r13)
jne 0x42447
movq 0x48(%r14), %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x2cca6
cmpl $0x0, (%r13)
jne 0x42447
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x4294b
cmpl $0x0, (%r13)
jne 0x42447
movq 0x48(%r14), %rdi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x2cca6
movq 0x20(%rsp), %rax
cmpl $0x0, (%r13)
je 0x4246a
movq %rbx, %rdi
callq 0x2b166
movq 0x30(%rsp), %rdi
callq 0x122c0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rax, %rbx
callq 0x2b166
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rdi
movl %ebx, %esi
movq %r13, %rcx
callq 0x2b627
jmp 0x4245b