// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rsi, %r14
movq %rdi, %r13
movq %rdx, %rsi
movq %r8, %rdx
callq 0x3691f
movq %rax, %r15
cmpl $0x0, (%r12)
je 0x4a255
movq %r14, %rdi
xorl %r14d, %r14d
callq 0x2b4c3
movq %r15, %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x4a274
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3691f
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x4a228
jmp 0x4a276
xorl %ebx, %ebx
movl (%r14), %eax
cmpl $0x7, %eax
je 0x4a36c
cmpl $0x3, %eax
jne 0x4a3b2
leaq 0x148(%r14), %rbp
movq %rbp, %rdi
callq 0x14ba1
decq %rax
je 0x4a480
testq %rbx, %rbx
je 0x4a2c2
cmpl $0x1, (%rbx)
jne 0x4a2c2
cmpl $0x0, 0x148(%rbx)
je 0x4a462
jns 0x4a2c2
movl %eax, 0x148(%rbx)
cmpl $0x1, (%r15)
jne 0x4a3dc
movq %rbp, %rdi
callq 0x14ba1
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 0x4a426
movq %rbp, 0x30(%rsp)
cmpl $0x2, %edx
jb 0x4a331
movl %r8d, 0x18(%rsp)
movl %ecx, %edx
xorl %ebp, %ebp
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x14cbb
cmpl $0x0, (%r12)
jne 0x4a4a7
movl 0x18(%rsp), %eax
movl %eax, %ecx
testq %rbx, %rbx
movq 0x30(%rsp), %rdi
je 0x4a351
cmpl $0x1, (%rbx)
jne 0x4a4bf
movl 0x148(%rbx), %ecx
cmpl %eax, %ecx
cmovgel %eax, %ecx
subl %ecx, %eax
jle 0x4a492
movslq %ecx, %rsi
movslq %eax, %rdx
movq %r12, %rcx
callq 0x14cbb
jmp 0x4a492
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x36269
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x4a228
testq %rbx, %rbx
je 0x4a406
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x36269
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x4a228
movq 0x148(%rbx), %rcx
jmp 0x4a40f
movq (%r13), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2b6d8(%rip), %r8      # 0x75a9c
movq %r12, %rdi
movl $0x49, %esi
movl $0x93c, %r9d            # imm = 0x93C
callq 0x14618
jmp 0x4a228
testq %rbx, %rbx
je 0x4a439
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x36269
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x4a228
movq 0x148(%rbx), %rcx
jmp 0x4a442
movq $-0x1, %rcx
xorl %ebx, %ebx
movq 0x148(%r15), %rdx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %r8
callq 0x4a9c8
jmp 0x4a457
movq %rbp, %rdi
callq 0x14dc2
cmpl $0x0, (%r12)
je 0x4a487
xorl %ebp, %ebp
jmp 0x4a4a7
movq $-0x1, %rcx
xorl %ebx, %ebx
movq 0x148(%r15), %rdx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %r8
callq 0x4a828
movq %r14, %rdi
movq %rax, %r14
jmp 0x4a22e
movq %rbp, %rdi
callq 0x14dc2
cmpl $0x0, (%r12)
jne 0x4a228
movq %rbp, %rdi
movq %r12, %rsi
callq 0x14d4b
xorl %edi, %edi
jmp 0x4a22e
movq %rbp, %rdi
movq %r12, %rsi
callq 0x14d4b
xorl %ebp, %ebp
cmpl $0x0, (%r12)
movq %r14, %rax
cmoveq %rbp, %rax
cmoveq %r14, %rbp
movq %rax, %r14
movq %r14, %rdi
callq 0x2b4c3
movq %r15, %rdi
callq 0x2b4c3
movq %rbp, %r14
jmp 0x4a23b
movq 0x148(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rdi, %rbp
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 0x2d00a
movq %rax, 0x18(%rsp)
movq 0x48(%r13), %rdi
callq 0x2d00a
movq %rax, 0x60(%rsp)
movq 0x48(%r13), %rdi
callq 0x2d00a
movq %rax, 0x58(%rsp)
movq 0x48(%r13), %rdi
callq 0x2d00a
movq %rax, 0x50(%rsp)
movq 0x48(%r13), %rdi
callq 0x2d00a
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
callq 0x14ba1
movq %rax, %rbp
movq 0x68(%r13), %rdi
leaq 0x2a642(%rip), %rsi     # 0x74b88
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
callq 0x2ea12
cmpl $0x0, (%r12)
jne 0x4a435
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 0x2c0c2
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x2d017
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x28(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r13, %rdi
movq 0x10(%rsp), %rcx
movq %r12, %r8
callq 0x4d921
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x45, %esi
movq 0x58(%rsp), %rdx
movq %r12, %rcx
callq 0x2c19f
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2d017
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x3d, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2c00f
movq %rax, 0x18(%rsp)
cmpl $0x0, (%r12)
jne 0x4a7fb
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 0x2c00f
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x26, %esi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %r12, %r8
callq 0x2c00f
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r8
movq %r12, %r9
callq 0x2c0c2
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x2d017
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x1b, %esi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
callq 0x2c1ac
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x2d017
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movl $0x1d, %esi
movq 0x40(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r12, %r8
callq 0x2c1ac
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x30(%rsp), %rdi
callq 0x14dfb
movq %r13, %rdi
movq %rax, %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
callq 0x4829f
cmpl $0x0, (%r12)
jne 0x4a7fb
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 0x2c189
cmpl $0x0, (%r12)
jne 0x4a7fb
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 0x4851e
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x48(%r13), %rdi
movq 0x58(%rsp), %rsi
movq %r12, %rdx
callq 0x2d017
cmpl $0x0, (%r12)
jne 0x4a7fb
movq 0x28(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r13, %rdi
movq %r12, %rcx
callq 0x4d763
cmpl $0x0, (%r12)
je 0x4a80a
movq 0x38(%rsp), %rdi
callq 0x122c0
jmp 0x4a435
movq 0x38(%rsp), %rdx
leaq 0x2a372(%rip), %rdi     # 0x74b88
movl %eax, %esi
movq %r12, %rcx
callq 0x2b99d
movq %rax, %rbp
jmp 0x4a4a7