// File: /workspace/github_c_makefile_star2_O1/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 0x2d00a
movq %rax, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %r13
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x4b02f
movq %rax, %rbp
cmpl $0x0, (%r15)
sete %al
testq %rbp, %rbp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x4acab
movq 0x48(%r12), %rdi
movq 0x148(%r14), %rdx
movl $0x12, %esi
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x4acab
leaq 0x20(%rsp), %r8
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq %rax, 0x8(%rsp)
movq %r15, %r9
callq 0x4b0e2
cmpl $0x0, (%r15)
jne 0x4acab
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 0x2c0c2
cmpl $0x0, (%r15)
jne 0x4acab
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2d017
movq 0x8(%rsp), %rcx
cmpl $0x0, (%r15)
jne 0x4acab
movq 0x148(%r14), %rsi
movq %r12, %rdi
xorl %edx, %edx
movq %r15, %r8
callq 0x4db93
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rdx
cmpl $0x0, (%r15)
jne 0x4acab
movq 0x20(%rsp), %rcx
movzbl 0x4(%rsp), %r10d
movq %r12, %rdi
movq %rax, %rsi
movq %rbx, %r9
pushq %r15
pushq %r10
callq 0x4b2e4
addq $0x10, %rsp
cmpl $0x0, (%r15)
jne 0x4acab
movq 0x48(%r12), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
movq %r14, %rdi
callq 0x2b4c3
movq %rbp, %rdi
callq 0x2b4c3
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b4c3