// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/string_type.c
// Function: subtilis_string_type_mid
void subtilis_string_type_mid(subtilis_parser_t *p, subtilis_exp_t *str,
			      subtilis_exp_t *start, subtilis_exp_t *len,
			      subtilis_exp_t *value, subtilis_error_t *err)
{
	size_t data_reg;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t start_gt0_label;
	subtilis_ir_operand_t start_lt_str_len_label;
	subtilis_ir_operand_t strlen_gt0_label;
	subtilis_ir_operand_t to_copy;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t condee;
	size_t str_len_reg;
	size_t orig_len_reg;
	size_t value_len_reg;

	end_label.label = subtilis_ir_section_new_label(p->current);
	start_gt0_label.label = subtilis_ir_section_new_label(p->current);
	start_lt_str_len_label.label =
	    subtilis_ir_section_new_label(p->current);
	strlen_gt0_label.label = subtilis_ir_section_new_label(p->current);

	len = prv_left_right_check_args(p, str, len, value, err);
	if (err->type != SUBTILIS_ERROR_OK || !len)
		goto cleanup;

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

	if (start->type.type == SUBTILIS_TYPE_CONST_INTEGER) {
		if (start->exp.ir_op.integer < 0)
			goto cleanup;
	} else {
		op1.integer = 0;
		condee.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_GTEI_I32, start->exp.ir_op,
		    op1, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		subtilis_ir_section_add_instr_reg(
		    p->current, SUBTILIS_OP_INSTR_JMPC, condee, start_gt0_label,
		    end_label, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

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

	op1.integer = SUBTIILIS_STRING_SIZE_OFF;
	orig_len_reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LOADO_I32, str->exp.ir_op, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.reg = orig_len_reg;
	condee.reg = subtilis_ir_section_add_instr(
	    p->current, (start->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			    ? SUBTILIS_OP_INSTR_GTI_I32
			    : SUBTILIS_OP_INSTR_GT_I32,
	    op1, start->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

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

	op1.reg = orig_len_reg;
	str_len_reg = subtilis_ir_section_add_instr(
	    p->current, (start->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			    ? SUBTILIS_OP_INSTR_SUBI_I32
			    : SUBTILIS_OP_INSTR_SUB_I32,
	    op1, start->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	to_copy.reg = prv_left_right_calc_len(p, len, value, str_len_reg,
					      &value_len_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	/*
	 * If to_copy is 0 there's nothing to do.
	 */

	subtilis_ir_section_add_instr_reg(p->current, SUBTILIS_OP_INSTR_JMPC,
					  to_copy, strlen_gt0_label, end_label,
					  err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

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

	data_reg = subtilis_reference_type_copy_on_write(p, str->exp.ir_op.reg,
							 0, orig_len_reg, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	op1.reg = data_reg;
	data_reg = subtilis_ir_section_add_instr(
	    p->current, (start->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			    ? SUBTILIS_OP_INSTR_ADDI_I32
			    : SUBTILIS_OP_INSTR_ADD_I32,
	    op1, start->exp.ir_op, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	prv_left_right_copy(p, data_reg, str_len_reg, value_len_reg, to_copy,
			    value, true, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_ir_section_add_label(p->current, end_label.label, err);

cleanup:

	subtilis_exp_delete(str);
	subtilis_exp_delete(start);
	subtilis_exp_delete(len);
	subtilis_exp_delete(value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39940
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x69cf0
movq %rax, -0x20(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x69964
cmpq $0x0, -0x20(%rbp)
jne 0x69969
jmp 0x69cc1
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x488b0
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6998c
jmp 0x69cc1
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x699ac
movq -0x18(%rbp), %rax
cmpl $0x0, 0x148(%rax)
jge 0x699a7
jmp 0x69cc1
jmp 0x69a3f
movl $0x0, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x68(%rbp), %rcx
movl $0x41, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x699ea
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r9
movq -0x70(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69a1a
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x39960
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69a3d
jmp 0x69cc1
jmp 0x69a3f
movl $0x0, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x68(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69a7d
jmp 0x69cc1
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movl $0x33, %esi
movl $0x35, %eax
cmpl $0x1, %ecx
cmovel %eax, %esi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %r8
movq -0x68(%rbp), %rdx
movq 0x148(%rax), %rcx
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69acd
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r9
movq -0x70(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69afd
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x39960
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69b20
jmp 0x69cc1
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movl $0x2, %esi
movl $0xb, %eax
cmpl $0x1, %ecx
cmovel %eax, %esi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %r8
movq -0x68(%rbp), %rdx
movq 0x148(%rax), %rcx
callq 0x38230
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69b70
jmp 0x69cc1
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x30(%rbp), %r9
leaq -0x88(%rbp), %r8
callq 0x69e20
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69ba2
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r9
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x43, %esi
callq 0x38360
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69bd2
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x39960
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69bf5
jmp 0x69cc1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x80(%rbp), %rcx
movq -0x30(%rbp), %r8
xorl %eax, %eax
movl %eax, %edx
callq 0x6e000
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69c27
jmp 0x69cc1
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
xorl %esi, %esi
movl $0x9, %eax
cmpl $0x1, %ecx
cmovel %eax, %esi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %r8
movq -0x68(%rbp), %rdx
movq 0x148(%rax), %rcx
callq 0x38230
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69c71
jmp 0x69cc1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0x28(%rbp), %r9
movq -0x30(%rbp), %rax
movq -0x60(%rbp), %r8
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x6a160
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69cac
jmp 0x69cc1
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x39960
movq -0x10(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x28(%rbp), %rdi
callq 0x36ee0
addq $0xa0, %rsp
popq %rbp
retq
nop