// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/string_type.c
// Function: prv_left_right_calc_len
static size_t prv_left_right_calc_len(subtilis_parser_t *p, subtilis_exp_t *len,
				      subtilis_exp_t *value, size_t str_len_reg,
				      size_t *value_len_reg,
				      subtilis_error_t *err)
{
	subtilis_ir_operand_t op0;
	subtilis_ir_operand_t op1;
	subtilis_ir_operand_t len_op;
	subtilis_ir_operand_t str_len;
	subtilis_ir_operand_t gt_len;
	subtilis_ir_operand_t less_zero;
	subtilis_ir_operand_t condee;
	subtilis_ir_operand_t value_len;
	size_t to_comp_reg;
	size_t to_copy_reg = p->current->reg_counter++;

	str_len.reg = str_len_reg;
	if ((len->type.type == SUBTILIS_TYPE_CONST_INTEGER) &&
	    (len->exp.ir_op.integer < 0)) {
		to_comp_reg = str_len.reg;
	} else {
		to_comp_reg = p->current->reg_counter++;
		if (len->type.type == SUBTILIS_TYPE_INTEGER) {
			op1.integer = 0;
			less_zero.reg = subtilis_ir_section_add_instr(
			    p->current, SUBTILIS_OP_INSTR_LTI_I32,
			    len->exp.ir_op, op1, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return SIZE_MAX;

			gt_len.reg = subtilis_ir_section_add_instr(
			    p->current, SUBTILIS_OP_INSTR_GTE_I32,
			    len->exp.ir_op, str_len, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return SIZE_MAX;

			condee.reg = subtilis_ir_section_add_instr(
			    p->current, SUBTILIS_OP_INSTR_OR_I32, less_zero,
			    gt_len, err);
			len_op = len->exp.ir_op;
		} else {
			len_op.reg = subtilis_ir_section_add_instr2(
			    p->current, SUBTILIS_OP_INSTR_MOVI_I32,
			    len->exp.ir_op, err);
			if (err->type != SUBTILIS_ERROR_OK)
				return SIZE_MAX;
			condee.reg = subtilis_ir_section_add_instr(
			    p->current, SUBTILIS_OP_INSTR_LT_I32, str_len,
			    len_op, err);
		}
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;

		op0.reg = to_comp_reg;
		subtilis_ir_section_add_instr4(p->current,
					       SUBTILIS_OP_INSTR_CMOV_I32, op0,
					       condee, str_len, len_op, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return SIZE_MAX;
	}

	if (value->type.type == SUBTILIS_TYPE_CONST_STRING) {
		op1.integer = subtilis_buffer_get_size(&value->exp.str) - 1;
		value_len.reg = subtilis_ir_section_add_instr2(
		    p->current, SUBTILIS_OP_INSTR_MOVI_I32, op1, err);
	} else {
		op1.integer = SUBTIILIS_STRING_SIZE_OFF;
		value_len.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_LOADO_I32, value->exp.ir_op,
		    op1, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op1.reg = to_comp_reg;
	condee.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_GT_I32, value_len, op1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	op0.reg = to_copy_reg;
	op1.reg = to_comp_reg;

	subtilis_ir_section_add_instr4(p->current, SUBTILIS_OP_INSTR_CMOV_I32,
				       op0, condee, op1, value_len, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return SIZE_MAX;

	*value_len_reg = value_len.reg;

	return to_copy_reg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x69e8c
movq -0x18(%rbp), %rax
cmpl $0x0, 0x148(%rax)
jge 0x69e8c
movq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x6a029
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq 0x18(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rcx)
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x69f6c
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x48(%rbp), %rcx
movl $0x3d, %esi
callq 0x38230
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69efa
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x58(%rbp), %rcx
movl $0x3f, %esi
callq 0x38230
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69f39
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %r8
movq -0x68(%rbp), %rdx
movq -0x60(%rbp), %rcx
movl $0x26, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x69fc9
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x148(%rax), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69fa7
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %r8
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
movl $0x3b, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x69fdf
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x80(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x58(%rbp), %r8
movq -0x50(%rbp), %r9
movl $0x8a, %esi
movq %rax, (%rsp)
callq 0x386c0
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6a027
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
jmp 0x6a029
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x6a069
movq -0x20(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x16270
subq $0x1, %rax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rdx
movl $0x1b, %esi
callq 0x38490
movq %rax, -0x78(%rbp)
jmp 0x6a099
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %r8
movq 0x148(%rax), %rdx
movq -0x48(%rbp), %rcx
movl $0x12, %esi
callq 0x38230
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6a0af
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %r8
movq -0x78(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl $0x33, %esi
callq 0x38230
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6a0ec
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x88(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rdx
movq -0x70(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x78(%rbp), %r9
movl $0x8a, %esi
movq %rax, (%rsp)
callq 0x386c0
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6a13c
movq $-0x1, -0x8(%rbp)
jmp 0x6a152
movq -0x78(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nop