// File: /workspace/github_c_makefile_star2_O1/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 0x4b513
cmpl $0x3, %eax
jne 0x4b538
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14ba1
cmpq $0x1, %rax
je 0x4b52b
cmpl $0x1, (%r14)
jne 0x4b562
cmpl $0x0, 0x148(%r14)
jle 0x4b922
movq %rbp, %rdi
callq 0x14ba1
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x4b946
movq %rax, %r12
movq %rbp, %rdi
callq 0x14dfb
movq %r12, %rdi
movq %rax, %rsi
callq 0x12070
movq %rbp, %rdi
callq 0x14d7f
cmpl $0x2, 0x148(%r14)
jl 0x4b4f4
movl $0x1, %r13d
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x14bd4
cmpl $0x0, (%r15)
jne 0x4b962
incl %r13d
cmpl 0x148(%r14), %r13d
jl 0x4b4d0
movq %rbp, %rdi
movq %r15, %rsi
callq 0x14d4b
cmpl $0x0, (%r15)
jne 0x4b962
movq %r12, %rdi
callq 0x122c0
jmp 0x4b52b
cmpl $0x1, (%r14)
jne 0x4b786
cmpl $0x1, 0x148(%r14)
jne 0x4b6cd
movq %r14, %rdi
callq 0x2b4c3
jmp 0x4ba14
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2a552(%rip), %r8      # 0x75a9c
movq %r15, %rdi
movl $0x49, %esi
movl $0xd03, %r9d            # imm = 0xD03
callq 0x14618
jmp 0x4ba02
movq %rax, %r13
decq %r13
cmpq $0x1, %r13
jne 0x4b709
movq $0x0, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %r13
movq %rbp, %rdi
callq 0x14dfb
movsbq (%rax), %rax
movq 0x48(%r12), %rdi
movl %eax, %edx
movl $0x1b, %esi
movq %r15, %rcx
callq 0x2c189
cmpl $0x0, (%r15)
jne 0x4b6b6
movq %rax, %rbp
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36269
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x4b6b6
movq 0x68(%r12), %rdi
leaq 0x295ac(%rip), %rsi     # 0x74b88
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2ea12
cmpl $0x0, (%r15)
jne 0x4b6b6
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x362d2
cmpl $0x0, (%r15)
jne 0x4b6b6
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x4c8d3
cmpl $0x0, (%r15)
jne 0x4b6b6
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x148(%r14), %r8
movq %r15, (%rsp)
leaq 0x29541(%rip), %rsi     # 0x74b88
movl $0x2, %ecx
movq %r12, %rdi
movl $0x1, %r9d
callq 0x4ddee
cmpl $0x0, (%r15)
jne 0x4b6b6
movq 0x148(%r14), %rdx
movq %r12, %rdi
movq %rax, %rsi
movq %rbp, %rcx
movq %r15, %r8
callq 0x3095d
cmpl $0x0, (%r15)
jne 0x4b6b6
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4b6b6
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
je 0x4ba26
movq %r14, %rdi
callq 0x2b4c3
movq 0x10(%rsp), %rdi
callq 0x122c0
jmp 0x4ba0a
jg 0x4b76b
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
callq 0x14a40
movq %r12, %rdi
movq %r15, %rsi
callq 0x14d4b
cmpl $0x0, (%r15)
je 0x4b96a
leaq 0x10(%rsp), %rdi
callq 0x14da6
jmp 0x4ba02
movq %rbp, %rdi
callq 0x14dfb
movq %r12, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x48267
cmpl $0x0, (%r15)
jne 0x4ba02
movq %rax, %rbp
movl %r13d, %edi
movq %r15, %rsi
callq 0x2bb29
cmpl $0x0, (%r15)
jne 0x4ba02
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %rax, %rcx
movq %r15, %r8
callq 0x4ba65
movq %rax, %r14
movq %rbx, %rdi
callq 0x2b4c3
movq %r14, %rax
jmp 0x4ba17
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36269
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x4ba02
leaq 0x10(%rsp), %rdx
movq $0x0, (%rdx)
movq 0x68(%r12), %rdi
leaq 0x293ea(%rip), %rsi     # 0x74b88
movq %r15, %rcx
callq 0x2ea12
cmpl $0x0, (%r15)
jne 0x4b9f8
movq %rax, 0x20(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, 0x8(%rsp)
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %rbp
movq 0x48(%r12), %rdi
callq 0x2d00a
movq %rax, %r13
movq 0x148(%rbx), %rdx
movq 0x48(%r12), %rdi
movl $0x12, %esi
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2c00f
cmpl $0x0, (%r15)
jne 0x4b9f8
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 0x2c0c2
cmpl $0x0, (%r15)
jne 0x4b9f8
movq %rbp, 0x30(%rsp)
movq 0x48(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4b9f8
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %r13, %rdx
andq %rax, %rdx
movq 0x48(%r12), %rdi
movl $0x1b, %esi
movq %r15, %rcx
callq 0x2c189
cmpl $0x0, (%r15)
jne 0x4b9f8
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %rax, %rcx
movq %r15, %r8
callq 0x4d921
cmpl $0x0, (%r15)
jne 0x4b9f8
movq 0x48(%r12), %rdi
movl $0x45, %esi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2c19f
cmpl $0x0, (%r15)
jne 0x4b9f8
movq 0x48(%r12), %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4b9f8
movq 0x148(%rbx), %rsi
movq %r12, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4d29c
cmpl $0x0, (%r15)
jne 0x4b9f8
movq %rax, %rbp
movq %rbx, %rdi
callq 0x2b4c3
movl %r13d, %edi
movq %r15, %rsi
callq 0x2ba99
cmpl $0x0, (%r15)
je 0x4b997
xorl %ebx, %ebx
jmp 0x4b9f8
movq %rbp, %rdi
callq 0x14dc2
cmpl $0x0, (%r15)
jne 0x4b95f
movq %rbp, %rdi
movq %r15, %rsi
callq 0x14d4b
cmpl $0x0, (%r15)
jne 0x4b95f
jmp 0x4b52b
leaq 0x2a14f(%rip), %rdx     # 0x75a9c
movq %r15, %rdi
movl $0x1, %esi
movl $0xafb, %ecx            # imm = 0xAFB
callq 0x145f4
xorl %r12d, %r12d
movq %r12, %rdi
jmp 0x4b9fd
movq %r14, %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2bbce
movq %rax, %rbx
movq %r14, %rdi
callq 0x14da6
jmp 0x4ba14
movq %r15, (%rsp)
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq %rax, %r8
movl $0x1, %r9d
callq 0x4ca3d
cmpl $0x0, (%r15)
jne 0x4b9f3
movq 0x48(%r12), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2d017
cmpl $0x0, (%r15)
jne 0x4b9f3
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movl $0x2, %esi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4d763
cmpl $0x0, (%r15)
je 0x4ba55
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
callq 0x122c0
movq %r14, %rdi
callq 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
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 0x2b4c3
movq %rbx, %rdi
callq 0x2b4c3
movq 0x10(%rsp), %rdx
leaq 0x29143(%rip), %rdi     # 0x74b88
movl %r12d, %esi
movq %r15, %rcx
callq 0x2b99d
movq %rax, %rbx
jmp 0x4ba14
movq 0x10(%rsp), %rdx
leaq 0x29127(%rip), %rdi     # 0x74b88
movl %eax, %esi
jmp 0x4ba48