// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/string_type.c
// Function: prv_left_right_statement
static void prv_left_right_statement(subtilis_parser_t *p, subtilis_exp_t *str,
				     subtilis_exp_t *len, subtilis_exp_t *value,
				     bool left, subtilis_error_t *err)
{
	size_t data_reg;
	subtilis_ir_operand_t end_label;
	subtilis_ir_operand_t strlen_gt0_label;
	subtilis_ir_operand_t to_copy;
	subtilis_ir_operand_t op1;
	size_t str_len_reg;
	size_t value_len_reg;

	end_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;

	op1.integer = SUBTIILIS_STRING_SIZE_OFF;
	str_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;

	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, str_len_reg, 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, left, 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(len);
	subtilis_exp_delete(value);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r15
movl %r8d, 0x4(%rsp)
movq %rcx, %rbx
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r12
movq 0x48(%rdi), %rdi
callq 0x2cc99
movq %rax, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2cc99
movq %rax, %r13
movl (%r14), %esi
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x4afc8
movq %rax, %rbp
cmpl $0x0, (%r15)
sete %al
testq %rbp, %rbp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4ac44
movq 0x48(%r12), %rdi
movq 0x148(%r14), %rdx
movl $0x12, %esi
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2bc8f
cmpl $0x0, (%r15)
jne 0x4ac44
leaq 0x20(%rsp), %r8
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq %rax, 0x8(%rsp)
movq %r15, %r9
callq 0x4b07b
cmpl $0x0, (%r15)
jne 0x4ac44
movq 0x48(%r12), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq %r13, %rcx
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %r8
movq %r15, %r9
callq 0x2bd42
cmpl $0x0, (%r15)
jne 0x4ac44
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2cca6
movq 0x8(%rsp), %rcx
cmpl $0x0, (%r15)
jne 0x4ac44
movq 0x148(%r14), %rsi
movq %r12, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0x4db4f
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rdx
cmpl $0x0, (%r15)
jne 0x4ac44
movq 0x20(%rsp), %rcx
movzbl 0x4(%rsp), %r10d
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, %r9
pushq %r15
pushq %r10
callq 0x4b296
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x4ac44
movq 0x48(%r12), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x2cca6
movq %r14, %rdi
callq 0x2b166
movq %rbp, %rdi
callq 0x2b166
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b166