// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x3691f
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x49c80
movq %rbx, %rdi
callq 0x2b4c3
movq %r14, %rdi
callq 0x2b4c3
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %eax
cmpl $0x7, %eax
je 0x49cd1
cmpl $0x3, %eax
jne 0x49f43
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14ba1
cmpq $0x1, %rax
je 0x4a1ca
cmpl $0x1, (%r14)
jne 0x49f6d
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x49bb6
movl (%r14), %r13d
cmpl $0x1, %r13d
jne 0x49d09
cmpl $0x0, 0x148(%r14)
js 0x4a1ca
je 0x4a19b
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36269
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x49c5c
movq 0x148(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x148(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rax
movq $0x0, (%rax)
movq 0x48(%r12), %rdi
movq 0x18(%rdi), %rax
movq %rax, 0x30(%rsp)
addq $0x2, %rax
movq %rax, 0x18(%rdi)
callq 0x2d00a
movq %rax, 0x28(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %rbp
movq 0x68(%r12), %rdi
leaq 0x2ae22(%rip), %rsi     # 0x74b88
leaq 0x20(%rsp), %rdx
movq %r15, %rcx
callq 0x2ea12
cmpl $0x0, (%r15)
jne 0x4a180
movq %rax, 0x50(%rsp)
xorl %ecx, %ecx
cmpl $0x1, %r13d
sete %cl
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbp, 0x10(%rsp)
movq %rbp, %r8
movq %r15, %r9
callq 0x4c1a5
cmpl $0x0, (%r15)
movq 0x30(%rsp), %rbp
jne 0x49f39
leaq 0x1(%rbp), %rdx
movq 0x48(%r12), %rdi
movl $0x1d, %esi
movq %rdx, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rcx
movq %r15, %r8
callq 0x2c1ac
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movl $0x4, %r8d
movl $0x12, %esi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
movq %r15, %r9
callq 0x2c0c2
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movl $0x45, %esi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2c19f
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x49f39
movq %r12, %rdi
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4d29c
movq 0x48(%rsp), %rcx
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
xorl %esi, %esi
movq %rax, %rdx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movl $0x2, %esi
movq %rbp, %rdx
movq %rax, %rcx
movq 0x18(%rsp), %r8
movq %r15, %r9
callq 0x2c0c2
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movl $0x1d, %esi
movq 0x40(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %r15, %r8
callq 0x2c1ac
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x48(%r12), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x50(%rsp), %rax
movq (%rax), %rdx
movq %r15, (%rsp)
movl $0x2, %esi
movq %r12, %rdi
movq 0x8(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rbp, %r9
callq 0x483d2
cmpl $0x0, (%r15)
jne 0x49f39
movq 0x50(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
je 0x4a1de
movq 0x20(%rsp), %rdi
jmp 0x4a17b
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2bb47(%rip), %r8      # 0x75a9c
movq %r15, %rdi
movl $0x49, %esi
movl $0x6b9, %r9d            # imm = 0x6B9
callq 0x14618
jmp 0x49c5c
movq 0x148(%r14), %r13
leaq 0x38(%rsp), %rax
movq $0x0, (%rax)
movq %rbp, %rdi
callq 0x14ba1
movq %rax, 0x28(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, 0x8(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, 0x18(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, 0x30(%rsp)
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rbp
movq %r13, %rdx
leaq 0x38(%rsp), %r8
movq %r15, %r9
callq 0x4bfeb
cmpl $0x0, (%r15)
jne 0x4a180
movq %rax, %r13
movq 0x48(%r12), %rdi
movl $0x43, %esi
movq %rbp, 0x10(%rsp)
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
movq %rcx, %rbp
movq 0x8(%rsp), %r8
movq %r15, %r9
callq 0x2c0c2
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x48(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq 0x10(%rsp), %rcx
movq %r15, %r8
callq 0x4d921
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x48(%r12), %rdi
movl $0x45, %esi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x2c19f
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x48(%r12), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4a176
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
andq 0x10(%rsp), %rbp
movq 0x48(%r12), %rdi
movl %r13d, %edx
orq %rbp, %rdx
movl $0x7d, %esi
movq %r15, %rcx
callq 0x2c189
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x28(%rsp), %rcx
decl %ecx
movq 0x48(%r12), %rdi
orq %rbp, %rcx
movl $0x9, %esi
movq %rax, %rdx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x48(%r12), %rdi
movl $0x2, %esi
movq %rax, %rdx
movq 0x10(%rsp), %rcx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
movq %r15, (%rsp)
movl $0x2, %esi
movq %r12, %rdi
movq %rax, %rcx
movq 0x10(%rsp), %r8
movl $0x1, %r9d
callq 0x4851e
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x48(%r12), %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4a176
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
je 0x4a1d7
movq 0x38(%rsp), %rdi
callq 0x122c0
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x2b4c3
movq %r14, %rdi
callq 0x2b4c3
movq %r15, %rbx
jmp 0x49c6e
movl $0x3, (%rbx)
leaq 0x148(%rbx), %r12
movl $0x1, %esi
movq %r12, %rdi
callq 0x14a40
movq %r12, %rdi
movq %r15, %rsi
callq 0x14d4b
cmpl $0x0, (%r15)
jne 0x49c5c
movq %r14, %rdi
callq 0x2b4c3
jmp 0x49c6e
movq 0x38(%rsp), %rdx
jmp 0x4a1e3
movq 0x20(%rsp), %rdx
leaq 0x2a99e(%rip), %rdi     # 0x74b88
movl %eax, %esi
movq %r15, %rcx
callq 0x2b99d
movq %rax, %r15
jmp 0x4a183