// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %r8, %r12
movq %rcx, %r14
movq %rsi, %rbx
movq %rdi, %r13
movq %rdx, %rsi
movq %r8, %rdx
callq 0x347d5
movq %rax, %r15
cmpl $0x0, (%r12)
je 0x477da
movq %rbx, %rdi
xorl %ebx, %ebx
callq 0x29d88
movq %r15, %rdi
callq 0x29d88
movq %r14, %rdi
callq 0x29d88
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x477f9
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x347d5
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x477ae
jmp 0x477fc
xorl %r14d, %r14d
movl (%rbx), %eax
cmpl $0x7, %eax
je 0x47881
cmpl $0x3, %eax
jne 0x478d3
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14804
decq %rax
je 0x47cd0
testq %r14, %r14
je 0x478fb
cmpl $0x1, (%r14)
jne 0x4784a
cmpl $0x0, 0x148(%r14)
je 0x47cb2
jns 0x4784a
movl %eax, 0x148(%r14)
cmpl $0x1, (%r15)
je 0x47905
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3415f
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x477ae
movq 0x148(%r14), %rax
movq %rax, 0x40(%rsp)
jmp 0x47b3d
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3415f
movq %rax, %r15
cmpl $0x0, (%r12)
jne 0x477ae
testq %r14, %r14
je 0x479a6
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3415f
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x477ae
movq 0x148(%r14), %rax
movq %rax, 0x18(%rsp)
jmp 0x479b1
movq (%r13), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x28187(%rip), %r8      # 0x6fa6c
pushq $0x49
popq %rsi
movq %r12, %rdi
movl $0x93c, %r9d            # imm = 0x93C
callq 0x142c0
jmp 0x477ae
cmpl $0x1, (%r15)
jne 0x47b32
movq %rbp, %rdi
callq 0x14804
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 0x47b18
movq %rbp, 0x28(%rsp)
cmpl $0x2, %edx
jb 0x4796a
movl %r8d, 0x18(%rsp)
movl %ecx, %edx
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x1491c
cmpl $0x0, (%r12)
jne 0x47cf7
movl 0x18(%rsp), %eax
testq %r14, %r14
movq 0x28(%rsp), %rbp
je 0x47ce2
cmpl $0x1, (%r14)
jne 0x47d17
movslq 0x148(%r14), %rsi
cmpl %esi, %eax
jle 0x47ce2
subl %esi, %eax
movslq %eax, %rdx
movq %rbp, %rdi
movq %r12, %rcx
callq 0x1491c
jmp 0x47ce2
pushq $-0x1
popq %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movq 0x148(%r15), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x48(%r13), %rdi
movq 0x18(%rdi), %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0x18(%rdi)
callq 0x2b774
movq %rax, 0x28(%rsp)
movq 0x48(%r13), %rdi
movq 0x148(%rbx), %rdx
pushq $0x12
popq %rsi
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2a819
xorl %ecx, %ecx
cmpl $0x0, (%r12)
jne 0x47b0d
movl %eax, %edi
movq %r12, %rsi
callq 0x2a336
cmpl $0x0, (%r12)
jne 0x47b0b
movq %r12, 0x10(%rsp)
leaq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x38(%rsp), %rcx
movq %rcx, (%rsp)
movq %r13, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbp, %rcx
movq 0x28(%rsp), %r8
movq %rax, %r9
callq 0x497a3
cmpl $0x0, (%r12)
jne 0x47b0b
movq %rax, 0x18(%rsp)
movq 0x148(%rbx), %rsi
movq %r13, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4a690
cmpl $0x0, (%r12)
jne 0x47b01
movq 0x48(%r13), %rdi
xorl %esi, %esi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %r12, %r8
callq 0x2a819
cmpl $0x0, (%r12)
jne 0x47b01
movq 0x38(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq (%rcx), %rdx
movq 0x148(%rbx), %rcx
movq %r12, (%rsp)
pushq $0x2
popq %rsi
movq %r13, %rdi
movq %rbp, %r8
movq %rax, %r9
callq 0x45a2a
cmpl $0x0, (%r12)
jne 0x47b01
movq 0x48(%r13), %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x47b01
movq 0x18(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r13, %rdi
movq %r12, %rcx
callq 0x4ab28
cmpl $0x0, (%r12)
je 0x48042
movq 0x30(%rsp), %rdi
callq 0x122c0
xorl %ecx, %ecx
movq %rbx, %rdi
movq %rcx, %rbx
jmp 0x477b3
movq %rbp, %rdi
callq 0x14a1a
cmpl $0x0, (%r12)
je 0x47cd7
xorl %ebp, %ebp
jmp 0x47cf7
pushq $-0x1
popq %rax
movq %rax, 0x40(%rsp)
xorl %r14d, %r14d
movq 0x148(%r15), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x48(%r13), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x18(%rsp)
incq %rcx
movq %rcx, 0x18(%rax)
movq %rbp, %rdi
callq 0x14804
movq %rbp, 0x28(%rsp)
movq %rax, %rbp
decq %rbp
movq 0x48(%r13), %rdi
callq 0x2b774
movq %rax, 0x20(%rsp)
movl %ebp, %edi
movq %r12, %rsi
callq 0x2a369
cmpl $0x0, (%r12)
jne 0x47ca5
movq %r12, 0x10(%rsp)
leaq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x38(%rsp), %rcx
movq %rcx, (%rsp)
movq %r13, %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %rax, %r9
callq 0x497a3
cmpl $0x0, (%r12)
jne 0x47ca5
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rdi
callq 0x14a53
movq %r13, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x45901
cmpl $0x0, (%r12)
jne 0x47c9b
movq 0x48(%r13), %rdi
movl %eax, %edx
pushq $0x7d
popq %rsi
movq %r12, %rcx
callq 0x2a981
cmpl $0x0, (%r12)
jne 0x47c9b
movq 0x48(%r13), %rdi
xorl %esi, %esi
movq %rax, %rdx
movq 0x40(%rsp), %rcx
movq %r12, %r8
callq 0x2a819
cmpl $0x0, (%r12)
jne 0x47c9b
movq 0x38(%rsp), %rbp
movq (%rbp), %rdx
movq %r12, (%rsp)
pushq $0x2
popq %rsi
pushq $0x1
popq %r9
movq %r13, %rdi
movq %rax, %rcx
movq 0x18(%rsp), %r8
callq 0x45b72
cmpl $0x0, (%r12)
jne 0x47c9b
movq 0x48(%r13), %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x47c9b
movq (%rbp), %rdx
pushq $0x2
popq %rsi
movq %r13, %rdi
movq %r12, %rcx
callq 0x4ab28
cmpl $0x0, (%r12)
je 0x48060
movq 0x30(%rsp), %rdi
callq 0x122c0
xorl %eax, %eax
movq %rbx, %rdi
movq %rax, %rbx
jmp 0x477b3
movq %rbp, %rdi
callq 0x14a1a
cmpl $0x0, (%r12)
jne 0x477ae
movq %rbp, %rdi
movq %r12, %rsi
callq 0x149a8
xorl %edi, %edi
jmp 0x477b3
movq %rbp, %rdi
movq %r12, %rsi
callq 0x149a8
xorl %ebp, %ebp
cmpl $0x0, (%r12)
movq %rbx, %rax
cmoveq %rbp, %rax
cmoveq %rbx, %rbp
movq %rax, %rbx
movq %rbx, %rdi
callq 0x29d88
movq %r15, %rdi
callq 0x29d88
movq %r14, %rdi
callq 0x29d88
movq %rbp, %rbx
jmp 0x477c8
movq 0x148(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x38(%rsp), %rax
andq $0x0, (%rax)
movq 0x48(%r13), %rdi
movq 0x18(%rdi), %rax
movq %rax, 0x60(%rsp)
incq %rax
movq %rax, 0x18(%rdi)
callq 0x2b774
movq %rax, 0x18(%rsp)
movq 0x48(%r13), %rdi
callq 0x2b774
movq %rax, 0x40(%rsp)
movq 0x48(%r13), %rdi
callq 0x2b774
movq %rax, 0x48(%rsp)
movq 0x48(%r13), %rdi
callq 0x2b774
movq %rax, 0x70(%rsp)
movq 0x48(%r13), %rdi
callq 0x2b774
movq %rax, 0x68(%rsp)
movq %rbp, %rdi
callq 0x14804
movq %rax, %rbp
movq 0x68(%r13), %rdi
leaq 0x26dc0(%rip), %rsi     # 0x6eb58
leaq 0x38(%rsp), %rdx
movq %r12, %rcx
callq 0x2cee3
cmpl $0x0, (%r12)
jne 0x47b2b
movq %rbp, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq 0x48(%r13), %rdi
pushq $0x43
popq %rsi
movq 0x20(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %rcx, %rbp
movq 0x18(%rsp), %r8
movq %r12, %r9
callq 0x2a8c1
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x48033
movq 0x58(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r13, %rdi
movq 0x20(%rsp), %rcx
movq %r12, %r8
callq 0x4acc2
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x45
popq %rsi
movq 0x48(%rsp), %rdx
movq %r12, %rcx
callq 0x2a997
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x3d
popq %rsi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x2a819
movq %rax, 0x18(%rsp)
cmpl $0x0, (%r12)
jne 0x48033
movq 0x50(%rsp), %rbp
decq %rbp
movq 0x48(%r13), %rdi
movq %rbp, 0x50(%rsp)
movl %ebp, %ebp
pushq $0x35
popq %rsi
movq 0x20(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
callq 0x2a819
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x26
popq %rsi
movq %rax, %rdx
movq 0x18(%rsp), %rcx
movq %r12, %r8
callq 0x2a819
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %r8
movq %r12, %r9
callq 0x2a8c1
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
movq 0x70(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x1b
popq %rsi
movq 0x20(%rsp), %rdx
movq %rbp, %rcx
movq %r12, %r8
callq 0x2a9a4
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
movq 0x68(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
pushq $0x1d
popq %rsi
movq 0x60(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %r12, %r8
callq 0x2a9a4
cmpl $0x0, (%r12)
jne 0x48033
movq 0x28(%rsp), %rdi
callq 0x14a53
movq %r13, %rdi
movq %rax, %rsi
movq 0x50(%rsp), %rdx
movq %r12, %rcx
callq 0x45901
cmpl $0x0, (%r12)
jne 0x48033
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq 0x20(%rsp), %rbp
andq %rcx, %rbp
movq 0x48(%r13), %rdi
movl %eax, %edx
orq %rbp, %rdx
pushq $0x7d
popq %rsi
movq %r12, %rcx
callq 0x2a981
cmpl $0x0, (%r12)
jne 0x48033
movq 0x58(%rsp), %rcx
movq (%rcx), %rdx
movq %r12, (%rsp)
pushq $0x2
popq %rsi
pushq $0x1
popq %r9
movq %r13, %rdi
movq %rax, %rcx
movq 0x60(%rsp), %r8
callq 0x45b72
cmpl $0x0, (%r12)
jne 0x48033
movq 0x48(%r13), %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x2b781
cmpl $0x0, (%r12)
jne 0x48033
movq 0x58(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r13, %rdi
movq %r12, %rcx
callq 0x4ab28
cmpl $0x0, (%r12)
je 0x4807b
movq 0x38(%rsp), %rdi
callq 0x122c0
jmp 0x47b2b
movq 0x30(%rsp), %rdx
leaq 0x26b0a(%rip), %rdi     # 0x6eb58
movl %eax, %esi
movq %r12, %rcx
callq 0x2a252
movq %rax, %rcx
jmp 0x47b0d
movq 0x30(%rsp), %rdx
leaq 0x26aec(%rip), %rdi     # 0x6eb58
movl %eax, %esi
movq %r12, %rcx
callq 0x2a252
jmp 0x47ca7
movq 0x38(%rsp), %rdx
leaq 0x26ad1(%rip), %rdi     # 0x6eb58
movl %eax, %esi
movq %r12, %rcx
callq 0x2a252
movq %rax, %rbp
jmp 0x47cf7