// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/array_type.c
// Function: prv_slice_set_sizes
static size_t prv_slice_set_sizes(subtilis_parser_t *p,
				  const subtilis_type_t *type,
				  size_t source_reg, size_t dest_reg,
				  subtilis_exp_t *index1,
				  subtilis_exp_t *index2, subtilis_error_t *err)
{
	size_t size_reg;
	size_t orig_size_reg;
	subtilis_exp_t *one = NULL;
	subtilis_exp_t *size = NULL;
	subtilis_exp_t *index1_dup = NULL;
	subtilis_exp_t *index2_dup = NULL;
	subtilis_exp_t *size_dup = NULL;
	subtilis_exp_t *el_count = NULL;

	index1_dup = subtilis_type_if_dup(index1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	index2_dup = subtilis_type_if_dup(index2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size = subtilis_type_if_sub(p, index2_dup, index1_dup, err);
	index1_dup = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size_dup = subtilis_type_if_dup(size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	one = subtilis_exp_new_int32(1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	el_count = subtilis_type_if_sub(p, size_dup, one, err);
	size_dup = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size = subtilis_type_if_data_size(p, type, size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size = subtilis_type_if_exp_to_var(p, size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	size_reg = size->exp.ir_op.reg;
	subtilis_exp_delete(size);
	size = NULL;

	subtilis_reference_type_set_size(p, dest_reg, 0, size_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	orig_size_reg =
	    subtilis_reference_type_get_orig_size(p, source_reg, 0, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_reference_type_set_orig_size(p, dest_reg, 0, orig_size_reg,
					      err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_type_if_assign_to_mem(p, dest_reg, SUBTIILIS_ARRAY_DIMS_OFF,
				       el_count, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	return size_reg;

cleanup:
	subtilis_exp_delete(el_count);
	subtilis_exp_delete(size);
	subtilis_exp_delete(size_dup);
	subtilis_exp_delete(index1_dup);

	return SIZE_MAX;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r12
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
movq 0x60(%rsp), %rbp
movq %r8, %rdi
movq %rbp, %rsi
callq 0x341c4
movq %rax, %rcx
pushq $-0x1
popq %rax
cmpl $0x0, (%rbp)
jne 0x40247
movq %rcx, %rbp
movq %r15, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq %r12, %rdi
movq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x341c4
cmpl $0x0, (%r15)
je 0x401cb
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebx, %ebx
jmp 0x40224
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x34e98
cmpl $0x0, (%r15)
je 0x401f3
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %rax, %r13
jmp 0x40224
movq %rax, (%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x341c4
movq %rax, %r12
cmpl $0x0, (%r15)
jne 0x4021c
pushq $0x1
popq %rdi
movq %r15, %rsi
callq 0x2a369
cmpl $0x0, (%r15)
je 0x40256
xorl %ebp, %ebp
xorl %ebx, %ebx
movq (%rsp), %r13
movq %rbx, %rdi
callq 0x29d88
movq %r13, %rdi
callq 0x29d88
movq %r12, %rdi
callq 0x29d88
movq %rbp, %rdi
callq 0x29d88
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x34e98
movq %rax, %rbx
cmpl $0x0, (%r15)
je 0x40277
xorl %ebp, %ebp
xorl %r12d, %r12d
jmp 0x40220
movq %r14, %rdi
movq 0x20(%rsp), %rsi
movq (%rsp), %rdx
movq %r15, %rcx
callq 0x33e43
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x402f6
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3415f
movq %rax, %r13
cmpl $0x0, (%r15)
jne 0x402f6
movq 0x148(%r13), %r12
movq %r13, %rdi
callq 0x29d88
xorl %r13d, %r13d
movq %r14, %rdi
movq 0x8(%rsp), %rbp
movq %rbp, %rsi
xorl %edx, %edx
movq %r12, %rcx
movq %r15, %r8
callq 0x4acc2
cmpl $0x0, (%r15)
jne 0x402f6
xorl %r13d, %r13d
movq %r14, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4b0e9
cmpl $0x0, (%r15)
je 0x40300
xorl %ebp, %ebp
xorl %r12d, %r12d
jmp 0x40224
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
movq %rax, %rcx
movq %r15, %r8
callq 0x4aeaf
cmpl $0x0, (%r15)
je 0x40326
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x40224
pushq $0x10
popq %rdx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rcx
movq 0x60(%rsp), %r14
movq %r14, %r8
callq 0x34300
xorl %ebx, %ebx
cmpl (%r14), %ebx
sbbq %rbx, %rbx
orq %r12, %rbx
movq %rbx, %rax
jmp 0x40247