// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/string_type.c
// Function: prv_mid_str_check
static size_t prv_mid_str_check(subtilis_parser_t *p, size_t start_reg,
				size_t len_reg, subtilis_ir_operand_t to_copy,
				subtilis_ir_operand_t end,
				subtilis_exp_t *str_len,
				const subtilis_symbol_t **s_ret,
				char **tmp_name, subtilis_error_t *err)
{
	subtilis_ir_operand_t start_reg_zero;
	subtilis_ir_operand_t start_reg_not_zero;
	subtilis_ir_operand_t less_zero;
	subtilis_ir_operand_t len_too_big;
	subtilis_ir_operand_t len_below_zero;
	subtilis_ir_operand_t len_ok;
	subtilis_ir_operand_t len_zero;
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t op2;
	subtilis_ir_operand_t empty;
	subtilis_ir_operand_t non_empty;
	subtilis_ir_operand_t zero_reg;
	subtilis_ir_operand_t condee;
	const subtilis_symbol_t *s;
	size_t start_reg_copy;
	subtilis_exp_t *a1 = NULL;
	subtilis_exp_t *a2 = NULL;
	char *local_tmp_name = NULL;

	start_reg_zero.label = subtilis_ir_section_new_label(p->current);
	start_reg_not_zero.label = subtilis_ir_section_new_label(p->current);
	empty.label = subtilis_ir_section_new_label(p->current);
	non_empty.label = subtilis_ir_section_new_label(p->current);
	len_too_big.label = subtilis_ir_section_new_label(p->current);
	len_ok.label = subtilis_ir_section_new_label(p->current);

	s = subtilis_symbol_table_insert_tmp(p->local_st, &subtilis_type_string,
					     &local_tmp_name, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.reg = start_reg;
	start_reg_copy = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOV, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	condee.reg = start_reg;
	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  condee, start_reg_not_zero,
					  start_reg_zero, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, start_reg_not_zero.label,
				      err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op0.reg = start_reg_copy;
	op1.reg = start_reg;
	op2.integer = 1;
	subtilis_ir_section_add_instr_reg(
	    p->current, SUBTILIS_OP_INSTR_SUBI_I32, op0, op1, op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	start_reg = start_reg_copy;

	subtilis_ir_section_add_label(p->current, start_reg_zero.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op0.reg = start_reg;
	op1.integer = 0;
	less_zero.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LTI_I32, op0, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a1 = subtilis_exp_new_int32_var(start_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	a2 = subtilis_type_if_dup(str_len, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a1 = subtilis_type_if_gte(p, a1, a2, err);
	a2 = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	condee.reg =
	    subtilis_ir_section_add_instr(p->current, SUBTILIS_OP_INSTR_OR_I32,
					  less_zero, a1->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	subtilis_exp_delete(a1);
	a1 = NULL;

	if (len_reg != SIZE_MAX) {
		op0.reg = len_reg;
		op1.integer = 0;
		len_zero.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_EQI_I32, op0, op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		condee.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_OR_I32, condee, len_zero,
		    err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  condee, empty, non_empty, 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;

	op1.integer = 0;
	zero_reg.reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_reference_type_set_size(p, SUBTILIS_IR_REG_LOCAL, s->loc,
					 zero_reg.reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * No need to push to the stack as this is a temporary reference
	 * which cannot be assigned to and that owns no data, i.e., it can
	 * never own any data.
	 */

	subtilis_ir_section_add_instr_no_reg(p->current, SUBTILIS_OP_INSTR_JMP,
					     end, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, non_empty.label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a1 = subtilis_exp_new_int32_var(start_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	a1 = subtilis_type_if_sub(p, str_len, a1, err);
	str_len = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_instr_no_reg2(p->current, SUBTILIS_OP_INSTR_MOV,
					      to_copy, a1->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;
	subtilis_exp_delete(a1);
	a1 = NULL;

	if (len_reg != SIZE_MAX) {
		op0.reg = len_reg;
		op1.integer = 0;
		len_below_zero.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_LTI_I32, op0, op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		condee.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_GT_I32, op0, to_copy, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		condee.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_OR_I32, condee,
		    len_below_zero, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_JMPC, condee, len_ok,
		    len_too_big, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_ir_section_add_label(p->current, len_too_big.label,
					      err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		op1.reg = len_reg;
		subtilis_ir_section_add_instr_no_reg2(
		    p->current, SUBTILIS_OP_INSTR_MOV, to_copy, op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		subtilis_ir_section_add_label(p->current, len_ok.label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

	subtilis_exp_delete(str_len);
	*tmp_name = local_tmp_name;
	*s_ret = s;
	return start_reg;

cleanup:

	free(local_tmp_name);
	subtilis_exp_delete(a2);
	subtilis_exp_delete(a1);
	subtilis_exp_delete(str_len);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x8(%rsp)
movq %r8, 0x58(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %r15
movq 0xb0(%rsp), %r14
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
movq 0x48(%rdi), %rdi
callq 0x2b774
movq %rax, (%rsp)
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, 0x60(%rsp)
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %r13
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %r12
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %rbp
movq 0x48(%r15), %rdi
callq 0x2b774
movq %rax, %rbx
movq 0x68(%r15), %rdi
leaq 0x25324(%rip), %rsi     # 0x6eb58
leaq 0x28(%rsp), %rdx
movq %r14, %rcx
callq 0x2cee3
cmpl $0x0, (%r14)
jne 0x49920
movq %r13, 0x50(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0x48(%r15), %rdi
pushq $0x1d
popq %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq %r14, %rcx
callq 0x2a981
cmpl $0x0, (%r14)
jne 0x49920
movq %rax, %r13
movq 0x48(%r15), %rdi
pushq $0x43
popq %rsi
movq %r12, %rdx
movq 0x60(%rsp), %rbp
movq %rbp, %rcx
movq (%rsp), %rbx
movq %rbx, %r8
movq %r14, %r9
callq 0x2a8c1
cmpl $0x0, (%r14)
jne 0x49920
movq 0x48(%r15), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x49920
movq 0x48(%r15), %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %r8
movq %r13, %rdx
movq %r12, %rcx
movq %r14, %r9
callq 0x2a8c1
cmpl $0x0, (%r14)
jne 0x49920
movq 0x48(%r15), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2b781
cmpl $0x0, (%r14)
jne 0x49920
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %r12
movq 0x48(%r15), %rdi
pushq $0x3d
popq %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
je 0x4995d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x28(%rsp), %rdi
callq 0x122c0
movq %rbx, %rdi
callq 0x29d88
movq %rbp, %rdi
callq 0x29d88
movq 0x8(%rsp), %rdi
callq 0x29d88
xorl %r13d, %r13d
movq %r13, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl %r13d, %edi
movq %r14, %rsi
callq 0x2a336
movq %rax, %rbp
cmpl $0x0, (%r14)
jne 0x49922
movq %rbx, 0x20(%rsp)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x341c4
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x49924
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x35259
movq %rax, %rbp
cmpl $0x0, (%r14)
jne 0x49922
movq %r15, (%rsp)
movq 0x48(%r15), %rdi
movq 0x148(%rbp), %rcx
pushq $0x26
popq %rsi
movq 0x20(%rsp), %rdx
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x49922
movq %rax, %rbx
movq %rbp, %rdi
callq 0x29d88
cmpq $-0x1, 0x10(%rsp)
je 0x49a44
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x2d
popq %rsi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
movq 0xb0(%rsp), %r14
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x49920
movq (%rsp), %rcx
movq 0x48(%rcx), %rdi
pushq $0x26
popq %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq 0xb0(%rsp), %r14
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x49920
movq %rax, %rbx
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x43
popq %rsi
movq %rbx, %rdx
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0xb0(%rsp), %rbx
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x49920
movq (%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x50(%rsp), %rsi
movq 0xb0(%rsp), %rbx
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x49920
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x1b
popq %rsi
movq %r12, %rdx
movq 0xb0(%rsp), %rbx
movq %rbx, %rcx
callq 0x2a981
cmpl $0x0, (%rbx)
jne 0x49920
movq 0x40(%rsp), %rcx
movq (%rcx), %rdx
pushq $0x2
popq %rsi
movq (%rsp), %rdi
movq %rax, %rcx
movq 0xb0(%rsp), %rbx
movq %rbx, %r8
callq 0x4acc2
cmpl $0x0, (%rbx)
jne 0x49920
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x45
popq %rsi
movq 0x58(%rsp), %rdx
movq 0xb0(%rsp), %rbx
movq %rbx, %rcx
callq 0x2a997
cmpl $0x0, (%rbx)
jne 0x49920
movq (%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x48(%rsp), %rsi
movq 0xb0(%rsp), %rbx
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x49920
movl %r13d, %edi
movq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x2a336
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x49922
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq 0xb0(%rsp), %rbx
movq %rbx, %rcx
callq 0x34e98
movq %rax, %rbp
cmpl $0x0, (%rbx)
jne 0x49bab
movq (%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x148(%rbp), %rcx
pushq $0x1d
popq %rsi
movq 0x18(%rsp), %rdx
movq 0xb0(%rsp), %rbx
movq %rbx, %r8
callq 0x2a9a4
cmpl $0x0, (%rbx)
je 0x49bb9
movq $0x0, 0x8(%rsp)
jmp 0x49922
movq %rbp, %rdi
callq 0x29d88
cmpq $-0x1, 0x10(%rsp)
je 0x49cff
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x3d
popq %rsi
movq 0x10(%rsp), %rdx
movq %r12, %rcx
movq 0xb0(%rsp), %r14
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x49cf1
movq %rax, %rbx
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x33
popq %rsi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0xb0(%rsp), %r14
movq %r14, %r8
callq 0x2a819
cmpl $0x0, (%r14)
jne 0x49cf1
movq (%rsp), %rcx
movq 0x48(%rcx), %rdi
pushq $0x26
popq %rsi
movq %rax, %rdx
movq %rbx, %rcx
movq 0xb0(%rsp), %rbx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x49cf1
movq (%rsp), %rcx
movq 0x48(%rcx), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0xb0(%rsp), %rbx
movq %rbx, %r9
callq 0x2a8c1
cmpl $0x0, (%rbx)
jne 0x49cf1
movq (%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x30(%rsp), %rsi
movq 0xb0(%rsp), %rbx
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
jne 0x49cf1
movq (%rsp), %rax
movq 0x48(%rax), %rdi
pushq $0x1d
popq %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0xb0(%rsp), %rbx
movq %rbx, %r8
callq 0x2a9a4
cmpl $0x0, (%rbx)
jne 0x49cf1
movq (%rsp), %rax
movq 0x48(%rax), %rdi
movq 0x38(%rsp), %rsi
movq 0xb0(%rsp), %rbx
movq %rbx, %rdx
callq 0x2b781
cmpl $0x0, (%rbx)
je 0x49cff
movq $0x0, 0x8(%rsp)
jmp 0x49920
movq 0xa8(%rsp), %rbx
movq 0xa0(%rsp), %r14
xorl %edi, %edi
callq 0x29d88
movq 0x28(%rsp), %rax
movq %rax, (%rbx)
movq 0x40(%rsp), %rax
movq %rax, (%r14)
jmp 0x4994b