// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/string_type.c
// Function: subtilis_string_type_mid_exp
subtilis_exp_t *subtilis_string_type_mid_exp(subtilis_parser_t *p,
					     subtilis_exp_t *str,
					     subtilis_exp_t *start,
					     subtilis_exp_t *len,
					     subtilis_error_t *err)
{
	size_t const_str_len;
	subtilis_exp_t *ret = NULL;
	size_t len_reg;

	start = subtilis_type_if_to_int(p, start, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (len) {
		len = subtilis_type_if_to_int(p, len, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	switch (str->type.type) {
	case SUBTILIS_TYPE_CONST_STRING:
		const_str_len = subtilis_buffer_get_size(&str->exp.str) - 1;
		if (const_str_len == 0) {
			ret = str;
			str = NULL;
			goto cleanup;
		}
		if (len && len->type.type == SUBTILIS_TYPE_CONST_INTEGER) {
			if (len->exp.ir_op.integer == 0) {
				subtilis_buffer_reset(&str->exp.str);
				if (err->type != SUBTILIS_ERROR_OK)
					goto cleanup;
				subtilis_buffer_zero_terminate(&str->exp.str,
							       err);
				ret = str;
				str = NULL;
				goto cleanup;
			}
			if (len->exp.ir_op.integer < 0)
				len->exp.ir_op.integer = const_str_len;
		}

		if (start->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			return prv_mid_str_cc(p, str, start, len, err);
		if (len) {
			len = subtilis_type_if_exp_to_var(p, len, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			len_reg = len->exp.ir_op.reg;
		} else {
			len_reg = SIZE_MAX;
		}
		ret =
		    prv_mid_str_cv(p, str, start->exp.ir_op.reg, len_reg, err);
		break;
	case SUBTILIS_TYPE_STRING:
		start = subtilis_type_if_exp_to_var(p, start, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		if (len) {
			len = subtilis_type_if_exp_to_var(p, len, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			len_reg = len->exp.ir_op.reg;
		} else {
			len_reg = SIZE_MAX;
		}
		ret =
		    prv_mid_str_vvv(p, str, start->exp.ir_op.reg, len_reg, err);
		break;
	default:
		subtilis_error_set_string_expected(err, p->l->stream->name,
						   p->l->line);
		break;
	}

cleanup:

	subtilis_exp_delete(str);
	subtilis_exp_delete(start);
	subtilis_exp_delete(len);

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %r12
movq %rcx, %r14
movq %rsi, %rbx
movq %rdi, %r13
movq %rdx, %rsi
movq %r8, %rdx
callq 0x367cf
movq %rax, %r15
cmpl $0x0, (%r12)
je 0x4a1d4
movq %rbx, %rdi
xorl %ebx, %ebx
callq 0x2b166
movq %r15, %rdi
callq 0x2b166
movq %r14, %rdi
callq 0x2b166
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x4a1f3
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x367cf
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x4a1a8
jmp 0x4a1f6
xorl %r14d, %r14d
movl (%rbx), %eax
cmpl $0x7, %eax
je 0x4a276
cmpl $0x3, %eax
jne 0x4a2c3
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14b57
decq %rax
je 0x4a414
testq %r14, %r14
je 0x4a2ed
cmpl $0x1, (%r14)
jne 0x4a244
cmpl $0x0, 0x148(%r14)
je 0x4a3f6
jns 0x4a244
movl %eax, 0x148(%r14)
cmpl $0x1, (%r15)
je 0x4a2f7
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x36119
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x4a1a8
movq 0x148(%r14), %rcx
jmp 0x4a3d6
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x36119
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x4a1a8
testq %r14, %r14
je 0x4a398
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x36119
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x4a1a8
movq 0x148(%r14), %rcx
jmp 0x4a3a2
movq (%r13), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2b80b(%rip), %r8      # 0x75ae0
movq %r12, %rdi
movl $0x49, %esi
movl $0x93c, %r9d            # imm = 0x93C
callq 0x145c8
jmp 0x4a1a8
cmpl $0x1, (%r15)
jne 0x4a3cc
movq %rbp, %rdi
callq 0x14b57
decl %eax
movl 0x148(%r15), %edx
xorl %esi, %esi
movl %edx, %ecx
subl $0x1, %ecx
cmovbl %esi, %ecx
testl %ecx, %ecx
setns %sil
movl %eax, %r8d
subl %ecx, %r8d
setg %dil
testb %dil, %sil
je 0x4a3b9
movq %rbp, 0x30(%rsp)
cmpl $0x2, %edx
jb 0x4a35c
movl %r8d, 0x18(%rsp)
movl %ecx, %edx
xorl %ebp, %ebp
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x14c71
cmpl $0x0, (%r12)
jne 0x4a43b
movl 0x18(%rsp), %eax
testq %r14, %r14
movq 0x30(%rsp), %rbp
je 0x4a426
cmpl $0x1, (%r14)
jne 0x4a45b
movslq 0x148(%r14), %rsi
cmpl %esi, %eax
jle 0x4a426
subl %esi, %eax
movslq %eax, %rdx
movq %rbp, %rdi
movq %r12, %rcx
callq 0x14c71
jmp 0x4a426
movq $-0x1, %rcx
xorl %r14d, %r14d
movq 0x148(%r15), %rdx
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %r8
callq 0x4a961
jmp 0x4a3eb
movq %rbp, %rdi
callq 0x14d78
cmpl $0x0, (%r12)
je 0x4a41b
xorl %ebp, %ebp
jmp 0x4a43b
movq $-0x1, %rcx
xorl %r14d, %r14d
movq 0x148(%r15), %rdx
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %r8
callq 0x4a7c1
movq %rbx, %rdi
movq %rax, %rbx
jmp 0x4a1ad
movq %rbp, %rdi
callq 0x14d78
cmpl $0x0, (%r12)
jne 0x4a1a8
movq %rbp, %rdi
movq %r12, %rsi
callq 0x14d01
xorl %edi, %edi
jmp 0x4a1ad
movq %rbp, %rdi
movq %r12, %rsi
callq 0x14d01
xorl %ebp, %ebp
cmpl $0x0, (%r12)
movq %rbx, %rax
cmoveq %rbp, %rax
cmoveq %rbx, %rbp
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2b166
movq %r15, %rdi
callq 0x2b166
movq %r14, %rdi
callq 0x2b166
movq %rbp, %rbx
jmp 0x4a1c2
movq 0x148(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x38(%rsp), %rax
movq $0x0, (%rax)
movq 0x48(%r13), %rdi
movq 0x18(%rdi), %rax
movq %rax, 0x40(%rsp)
incq %rax
movq %rax, 0x18(%rdi)
callq 0x2cc99
movq %rax, 0x18(%rsp)
movq 0x48(%r13), %rdi
callq 0x2cc99
movq %rax, 0x60(%rsp)
movq 0x48(%r13), %rdi
callq 0x2cc99
movq %rax, 0x58(%rsp)
movq 0x48(%r13), %rdi
callq 0x2cc99
movq %rax, 0x50(%rsp)
movq 0x48(%r13), %rdi
callq 0x2cc99
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
callq 0x14b57
movq %rax, %rbp
movq 0x68(%r13), %rdi
leaq 0x2a6c9(%rip), %rsi     # 0x74ba8
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
callq 0x2e6f1
cmpl $0x0, (%r12)
jne 0x4a3c8
movq %rbp, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x48(%r13), %rdi
movl $0x43, %esi
movq 0x10(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %rcx, %rbp
movq 0x18(%rsp), %r8
movq %r12, %r9
callq 0x2bd42
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x2cca6
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x28(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r13, %rdi
movq 0x10(%rsp), %rcx
movq %r12, %r8
callq 0x4d8dd
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x45, %esi
movq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0x2be1f
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2cca6
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x3d, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2bc8f
movq %rax, 0x18(%rsp)
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x20(%rsp), %rbp
decq %rbp
movq 0x48(%r13), %rdi
movq %rbp, 0x20(%rsp)
movl %ebp, %ebp
movl $0x35, %esi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
callq 0x2bc8f
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x26, %esi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %r12, %r8
callq 0x2bc8f
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r8
movq %r12, %r9
callq 0x2bd42
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x2cca6
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x1b, %esi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
callq 0x2be2c
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x2cca6
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movl $0x1d, %esi
movq 0x40(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r12, %r8
callq 0x2be2c
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x30(%rsp), %rdi
callq 0x14db1
movq %r13, %rdi
movq %rax, %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0x4821f
cmpl $0x0, (%r12)
jne 0x4a794
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq 0x10(%rsp), %rbp
andq %rcx, %rbp
movq 0x48(%r13), %rdi
movl %eax, %edx
orq %rbp, %rdx
movl $0x7d, %esi
movq %r12, %rcx
callq 0x2be09
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x28(%rsp), %rcx
movq (%rcx), %rdx
movq %r12, (%rsp)
movl $0x2, %esi
movq %r13, %rdi
movq %rax, %rcx
movq 0x40(%rsp), %r8
movl $0x1, %r9d
callq 0x4849e
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x48(%r13), %rdi
movq 0x58(%rsp), %rsi
movq %r12, %rdx
callq 0x2cca6
cmpl $0x0, (%r12)
jne 0x4a794
movq 0x28(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r13, %rdi
movq %r12, %rcx
callq 0x4d71f
cmpl $0x0, (%r12)
je 0x4a7a3
movq 0x38(%rsp), %rdi
callq 0x122c0
jmp 0x4a3c8
movq 0x38(%rsp), %rdx
leaq 0x2a3f9(%rip), %rdi     # 0x74ba8
movl %eax, %esi
movq %r12, %rcx
callq 0x2b627
movq %rax, %rbp
jmp 0x4a43b