// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/string_type.c
// Function: subtilis_string_type_string
subtilis_exp_t *subtilis_string_type_string(subtilis_parser_t *p,
					    subtilis_exp_t *count,
					    subtilis_exp_t *str,
					    subtilis_error_t *err)
{
	size_t buf_size;
	size_t ptr;
	const char *cstr;
	subtilis_exp_t *str_len;
	subtilis_exp_t *ret;
	subtilis_buffer_t dummy;

	switch (str->type.type) {
	case SUBTILIS_TYPE_CONST_STRING:
		buf_size = subtilis_buffer_get_size(&str->exp.str);
		if (buf_size == 1) {
			subtilis_exp_delete(count);
			return str;
		}
		if (count->type.type == SUBTILIS_TYPE_CONST_INTEGER)
			return prv_string_str_const(p, count, str, err);

		buf_size--;

		if (buf_size == 1)
			return prv_string_from_const_char(p, count, str, err);

		cstr = subtilis_buffer_get_string(&str->exp.str);
		ptr = subtilis_string_type_lca_const(p, cstr, buf_size, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
		str_len = subtilis_exp_new_int32(buf_size, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		ret = prv_string_str_non_const_lengt1(p, count, ptr, str_len,
						      err);
		subtilis_exp_delete(str);
		return ret;
	case SUBTILIS_TYPE_STRING:
		if (count->type.type == SUBTILIS_TYPE_CONST_INTEGER) {
			if (count->exp.ir_op.integer == 1) {
				subtilis_exp_delete(count);
				return str;
			} else if (count->exp.ir_op.integer <= 1) {
				subtilis_buffer_init(&dummy, 128);
				subtilis_buffer_zero_terminate(&dummy, err);
				if (err->type != SUBTILIS_ERROR_OK) {
					subtilis_buffer_free(&dummy);
					goto cleanup;
				}
				subtilis_exp_delete(count);
				subtilis_exp_delete(str);
				str = subtilis_exp_new_str(&dummy, err);
				subtilis_buffer_free(&dummy);
				return str;
			}
			count = subtilis_type_if_exp_to_var(p, count, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
		}

		return prv_string_str_non_const(p, count, str, err);

	default:
		subtilis_error_set_string_expected(err, p->l->stream->name,
						   p->l->line);
		break;
	}

cleanup:

	subtilis_exp_delete(count);
	subtilis_exp_delete(str);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movl (%rdx), %eax
cmpl $0x7, %eax
je 0x4b4c5
cmpl $0x3, %eax
jne 0x4b4ea
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14b57
cmpq $0x1, %rax
je 0x4b4dd
cmpl $0x1, (%r14)
jne 0x4b514
cmpl $0x0, 0x148(%r14)
jle 0x4b8d4
movq %rbp, %rdi
callq 0x14b57
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x4b8f8
movq %rax, %r12
movq %rbp, %rdi
callq 0x14db1
movq %r12, %rdi
movq %rax, %rsi
callq 0x12070
movq %rbp, %rdi
callq 0x14d35
cmpl $0x2, 0x148(%r14)
jl 0x4b4a6
movl $0x1, %r13d
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x14b8a
cmpl $0x0, (%r15)
jne 0x4b914
incl %r13d
cmpl 0x148(%r14), %r13d
jl 0x4b482
movq %rbp, %rdi
movq %r15, %rsi
callq 0x14d01
cmpl $0x0, (%r15)
jne 0x4b914
movq %r12, %rdi
callq 0x122c0
jmp 0x4b4dd
cmpl $0x1, (%r14)
jne 0x4b738
cmpl $0x1, 0x148(%r14)
jne 0x4b67f
movq %r14, %rdi
callq 0x2b166
jmp 0x4b9c6
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2a5e4(%rip), %r8      # 0x75ae0
movq %r15, %rdi
movl $0x49, %esi
movl $0xd03, %r9d            # imm = 0xD03
callq 0x145c8
jmp 0x4b9b4
movq %rax, %r13
decq %r13
cmpq $0x1, %r13
jne 0x4b6bb
movq $0x0, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2cc99
movq %rax, %r13
movq %rbp, %rdi
callq 0x14db1
movsbq (%rax), %rax
movq 0x48(%r12), %rdi
movl %eax, %edx
movl $0x1b, %esi
movq %r15, %rcx
callq 0x2be09
cmpl $0x0, (%r15)
jne 0x4b668
movq %rax, %rbp
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36119
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x4b668
movq 0x68(%r12), %rdi
leaq 0x2961a(%rip), %rsi     # 0x74ba8
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2e6f1
cmpl $0x0, (%r15)
jne 0x4b668
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x36182
cmpl $0x0, (%r15)
jne 0x4b668
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x4c890
cmpl $0x0, (%r15)
jne 0x4b668
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x148(%r14), %r8
movq %r15, (%rsp)
leaq 0x295af(%rip), %rsi     # 0x74ba8
movl $0x2, %ecx
movq %r12, %rdi
movl $0x1, %r9d
callq 0x4ddaa
cmpl $0x0, (%r15)
jne 0x4b668
movq 0x148(%r14), %rdx
movq %r12, %rdi
movq %rax, %rsi
movq %rbp, %rcx
movq %r15, %r8
callq 0x30791
cmpl $0x0, (%r15)
jne 0x4b668
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2cca6
cmpl $0x0, (%r15)
jne 0x4b668
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d71f
cmpl $0x0, (%r15)
je 0x4b9d8
movq %r14, %rdi
callq 0x2b166
movq 0x10(%rsp), %rdi
callq 0x122c0
jmp 0x4b9bc
jg 0x4b71d
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
callq 0x149f4
movq %r12, %rdi
movq %r15, %rsi
callq 0x14d01
cmpl $0x0, (%r15)
je 0x4b91c
leaq 0x10(%rsp), %rdi
callq 0x14d5c
jmp 0x4b9b4
movq %rbp, %rdi
callq 0x14db1
movq %r12, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x481e7
cmpl $0x0, (%r15)
jne 0x4b9b4
movq %rax, %rbp
movl %r13d, %edi
movq %r15, %rsi
callq 0x2b7af
cmpl $0x0, (%r15)
jne 0x4b9b4
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %rax, %rcx
movq %r15, %r8
callq 0x4ba17
movq %rax, %r14
movq %rbx, %rdi
callq 0x2b166
movq %r14, %rax
jmp 0x4b9c9
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36119
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x4b9b4
leaq 0x10(%rsp), %rdx
movq $0x0, (%rdx)
movq 0x68(%r12), %rdi
leaq 0x29458(%rip), %rsi     # 0x74ba8
movq %r15, %rcx
callq 0x2e6f1
cmpl $0x0, (%r15)
jne 0x4b9aa
movq %rax, 0x20(%rsp)
movq 0x48(%r12), %rdi
callq 0x2cc99
movq %rax, 0x8(%rsp)
movq 0x48(%r12), %rdi
callq 0x2cc99
movq %rax, %rbp
movq 0x48(%r12), %rdi
callq 0x2cc99
movq %rax, %r13
movq 0x148(%rbx), %rdx
movq 0x48(%r12), %rdi
movl $0x12, %esi
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2bc8f
cmpl $0x0, (%r15)
jne 0x4b9aa
movq %r13, 0x28(%rsp)
movq 0x48(%r12), %rdi
movl $0x43, %esi
movq %rax, %rdx
movq %rbp, %rcx
movq 0x8(%rsp), %r8
movq %r15, %r9
movq %rax, %r13
callq 0x2bd42
cmpl $0x0, (%r15)
jne 0x4b9aa
movq %rbp, 0x30(%rsp)
movq 0x48(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2cca6
cmpl $0x0, (%r15)
jne 0x4b9aa
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %r13, %rdx
andq %rax, %rdx
movq 0x48(%r12), %rdi
movl $0x1b, %esi
movq %r15, %rcx
callq 0x2be09
cmpl $0x0, (%r15)
jne 0x4b9aa
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %rax, %rcx
movq %r15, %r8
callq 0x4d8dd
cmpl $0x0, (%r15)
jne 0x4b9aa
movq 0x48(%r12), %rdi
movl $0x45, %esi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2be1f
cmpl $0x0, (%r15)
jne 0x4b9aa
movq 0x48(%r12), %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x2cca6
cmpl $0x0, (%r15)
jne 0x4b9aa
movq 0x148(%rbx), %rsi
movq %r12, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4d258
cmpl $0x0, (%r15)
jne 0x4b9aa
movq %rax, %rbp
movq %rbx, %rdi
callq 0x2b166
movl %r13d, %edi
movq %r15, %rsi
callq 0x2b71f
cmpl $0x0, (%r15)
je 0x4b949
xorl %ebx, %ebx
jmp 0x4b9aa
movq %rbp, %rdi
callq 0x14d78
cmpl $0x0, (%r15)
jne 0x4b911
movq %rbp, %rdi
movq %r15, %rsi
callq 0x14d01
cmpl $0x0, (%r15)
jne 0x4b911
jmp 0x4b4dd
leaq 0x2a1e1(%rip), %rdx     # 0x75ae0
movq %r15, %rdi
movl $0x1, %esi
movl $0xafb, %ecx            # imm = 0xAFB
callq 0x145a4
xorl %r12d, %r12d
movq %r12, %rdi
jmp 0x4b9af
movq %r14, %rdi
callq 0x2b166
movq %rbx, %rdi
callq 0x2b166
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2b854
movq %rax, %rbx
movq %r14, %rdi
callq 0x14d5c
jmp 0x4b9c6
movq %r15, (%rsp)
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq %rax, %r8
movl $0x1, %r9d
callq 0x4c9fa
cmpl $0x0, (%r15)
jne 0x4b9a5
movq 0x48(%r12), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2cca6
cmpl $0x0, (%r15)
jne 0x4b9a5
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d71f
cmpl $0x0, (%r15)
je 0x4ba07
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
callq 0x122c0
movq %r14, %rdi
callq 0x2b166
movq %rbx, %rdi
callq 0x2b166
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq %r14, %rdi
callq 0x2b166
movq %rbx, %rdi
callq 0x2b166
movq 0x10(%rsp), %rdx
leaq 0x291b1(%rip), %rdi     # 0x74ba8
movl %r12d, %esi
movq %r15, %rcx
callq 0x2b627
movq %rax, %rbx
jmp 0x4b9c6
movq 0x10(%rsp), %rdx
leaq 0x29195(%rip), %rdi     # 0x74ba8
movl %eax, %esi
jmp 0x4b9fa