// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/string_type.c
// Function: subtilis_string_type_left_exp
subtilis_exp_t *subtilis_string_type_left_exp(subtilis_parser_t *p,
					      subtilis_exp_t *str,
					      subtilis_exp_t *len,
					      subtilis_error_t *err)
{
	size_t const_str_len;
	size_t const_int_val;
	subtilis_exp_t *ret;
	bool left_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) {
			const_int_val = len->exp.ir_op.integer;
			return prv_left_right_const_str(str, len, const_int_val,
							err);
		}
		ret = prv_left_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) {
			left_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_left_non_const(p, str->exp.ir_op.reg,
					 len->exp.ir_op.reg, left_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 $0x48, %rsp
movq %rcx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x347d5
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x46cfb
movq %rbx, %rdi
callq 0x29d88
movq %r14, %rdi
callq 0x29d88
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %eax
cmpl $0x7, %eax
je 0x46d51
cmpl $0x3, %eax
jne 0x46f30
leaq 0x148(%rbx), %r13
movq %r13, %rdi
callq 0x14804
cmpq $0x1, %rax
je 0x4713d
cmpl $0x1, (%r14)
jne 0x46f58
movslq 0x148(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4716c
movl (%r14), %r13d
cmpl $0x1, %r13d
jne 0x46d89
cmpl $0x0, 0x148(%r14)
js 0x4713d
je 0x47110
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3415f
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x46cd7
movq 0x148(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x148(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
movq 0x48(%r12), %rdi
movq 0x18(%rdi), %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0x18(%rdi)
callq 0x2b774
movq %rax, 0x28(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, 0x20(%rsp)
movq 0x68(%r12), %rdi
leaq 0x27d78(%rip), %rsi     # 0x6eb58
leaq 0x18(%rsp), %rdx
movq %r15, %rcx
callq 0x2cee3
cmpl $0x0, (%r15)
jne 0x470f5
movq %rax, 0x40(%rsp)
movq %rbp, 0x30(%rsp)
xorl %ecx, %ecx
cmpl $0x1, %r13d
sete %cl
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x28(%rsp), %r8
movq %r8, %rbp
movq %r15, %r9
callq 0x4963f
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x48(%r12), %rdi
pushq $0x1d
popq %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
movq %r15, %r8
callq 0x2a9a4
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x48(%r12), %rdi
pushq $0x45
popq %rsi
movq 0x20(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x48(%r12), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x48(%r12), %rdi
pushq $0x1d
popq %rsi
movq 0x30(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r15, %r8
callq 0x2a9a4
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x48(%r12), %rdi
movq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x46f26
movq %r12, %rdi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4a690
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x40(%rsp), %rcx
movq (%rcx), %rdx
movq %r15, (%rsp)
pushq $0x2
popq %rsi
movq %r12, %rdi
movq 0x10(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %rax, %r9
callq 0x45a2a
cmpl $0x0, (%r15)
jne 0x46f26
movq 0x40(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4ab28
cmpl $0x0, (%r15)
je 0x4714a
movq 0x18(%rsp), %rdi
jmp 0x470f0
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x28b2a(%rip), %r8      # 0x6fa6c
pushq $0x49
popq %rsi
movq %r15, %rdi
movl $0x5b1, %r9d            # imm = 0x5B1
callq 0x142c0
jmp 0x46cd7
movq 0x148(%r14), %rbp
leaq 0x38(%rsp), %rax
andq $0x0, (%rax)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, 0x8(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, 0x28(%rsp)
leaq 0x18(%rsp), %rcx
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0x38(%rsp), %r8
movq %r15, %r9
callq 0x49492
cmpl $0x0, (%r15)
jne 0x470f5
movq %rax, 0x20(%rsp)
movq 0x48(%r12), %rdi
pushq $0x43
popq %rsi
movq %rbp, %rdx
movq 0x10(%rsp), %rcx
movq %rcx, %r13
movq 0x8(%rsp), %r8
movq %r15, %r9
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x48(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %rbp, %rcx
movq %r15, %r8
callq 0x4acc2
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x48(%r12), %rdi
pushq $0x45
popq %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x470eb
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rbp, %rax
movq 0x48(%r12), %rdi
movl 0x20(%rsp), %edx
orq %rax, %rdx
pushq $0x7d
popq %rsi
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x8(%rsp), %rcx
movq (%rcx), %rdx
movq %r15, (%rsp)
pushq $0x2
popq %rsi
pushq $0x1
popq %r9
movq %r12, %rdi
movq %rax, %rcx
movq %rbp, %r8
callq 0x45b72
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x48(%r12), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x470eb
movq 0x8(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4ab28
cmpl $0x0, (%r15)
je 0x47151
movq 0x38(%rsp), %rdi
callq 0x122c0
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x29d88
movq %r14, %rdi
callq 0x29d88
movq %r15, %rbx
jmp 0x46ce9
movl $0x3, (%rbx)
leaq 0x148(%rbx), %r12
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x146a8
movq %r12, %rdi
movq %r15, %rsi
callq 0x149a8
cmpl $0x0, (%r15)
jne 0x46cd7
movq %r14, %rdi
callq 0x29d88
jmp 0x46ce9
movq 0x18(%rsp), %rdx
jmp 0x47156
movq 0x38(%rsp), %rdx
leaq 0x279fb(%rip), %rdi     # 0x6eb58
movl %eax, %esi
movq %r15, %rcx
callq 0x2a252
movq %rax, %r15
jmp 0x470f8