// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/string_type.c
// Function: subtilis_string_type_right_exp
subtilis_exp_t *subtilis_string_type_right_exp(subtilis_parser_t *p,
					       subtilis_exp_t *str,
					       subtilis_exp_t *len,
					       subtilis_error_t *err)
{
	size_t const_str_len;
	subtilis_exp_t *ret = NULL;
	bool right_const = false;

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

	switch (str->type.type) {
	case SUBTILIS_TYPE_CONST_STRING:
		const_str_len = subtilis_buffer_get_size(&str->exp.str) - 1;
		if (const_str_len == 0) {
			subtilis_exp_delete(len);
			return str;
		}
		if (len->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			return prv_left_right_const_str(str, len, 0, err);

		ret =
		    prv_right_const(p, &str->exp.str, len->exp.ir_op.reg, err);
		subtilis_exp_delete(str);
		subtilis_exp_delete(len);
		return ret;
	case SUBTILIS_TYPE_STRING:
		if (len->type.type == SUBTILIS_TYPE_CONST_INTEGER) {
			right_const = true;
			if (len->exp.ir_op.integer < 0) {
				subtilis_exp_delete(len);
				return str;
			}
			if (len->exp.ir_op.integer == 0) {
				str->type.type = SUBTILIS_TYPE_CONST_STRING;
				subtilis_buffer_init(&str->exp.str, 1);
				subtilis_buffer_zero_terminate(&str->exp.str,
							       err);
				if (err->type != SUBTILIS_ERROR_OK)
					goto cleanup;
				subtilis_exp_delete(len);
				return str;
			}
			len = subtilis_type_if_exp_to_var(p, len, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		}
		ret = prv_right_non_const(p, str->exp.ir_op.reg,
					  len->exp.ir_op.reg, right_const, err);
		subtilis_exp_delete(str);
		subtilis_exp_delete(len);
		return ret;
	default:
		subtilis_error_set_string_expected(err, p->l->stream->name,
						   p->l->line);
		break;
	}

cleanup:

	subtilis_exp_delete(str);
	subtilis_exp_delete(len);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x488b0
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x68487
jmp 0x68681
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
subl $0x3, %eax
je 0x684a8
jmp 0x68497
movl -0x40(%rbp), %eax
subl $0x7, %eax
je 0x6854a
jmp 0x6864f
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x16270
subq $0x1, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x684dd
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x68504
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x67ea0
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x148, %rsi            # imm = 0x148
movq -0x20(%rbp), %rax
movq 0x148(%rax), %rdx
movq -0x28(%rbp), %rcx
callq 0x686b0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x68604
movb $0x1, -0x39(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x148(%rax)
jge 0x6857e
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x20(%rbp), %rax
cmpl $0x0, 0x148(%rax)
jne 0x685e2
movq -0x18(%rbp), %rax
movl $0x3, (%rax)
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
movl $0x1, %esi
callq 0x15f80
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
movq -0x28(%rbp), %rsi
callq 0x16560
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x685cc
jmp 0x68681
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x47c10
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x68602
jmp 0x68681
jmp 0x68604
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x148(%rax), %rdx
movb -0x39(%rbp), %al
movq -0x28(%rbp), %r8
andb $0x1, %al
movzbl %al, %ecx
callq 0x68990
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6869b
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %ecx
movl $0x49, %esi
leaq 0x443e3(%rip), %r8      # 0xaca57
movl $0x6b9, %r9d            # imm = 0x6B9
callq 0x15930
jmp 0x68681
movq -0x18(%rbp), %rdi
callq 0x36ee0
movq -0x20(%rbp), %rdi
callq 0x36ee0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)