// File: /workspace/github_c_makefile_star2_O2/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 0x48a0a
cmpl $0x3, %eax
jne 0x48a2f
leaq 0x148(%rbx), %rbp
movq %rbp, %rdi
callq 0x14804
cmpq $0x1, %rax
je 0x48a22
cmpl $0x1, (%r14)
jne 0x48a57
cmpl $0x0, 0x148(%r14)
jle 0x48e6f
movq %rbp, %rdi
callq 0x14804
leaq 0x1(%rax), %rdi
callq 0x121d0
testq %rax, %rax
je 0x48e93
movq %rax, %r12
movq %rbp, %rdi
callq 0x14a53
movq %r12, %rdi
movq %rax, %rsi
callq 0x12070
movq %rbp, %rdi
callq 0x149da
xorl %r13d, %r13d
incl %r13d
cmpl 0x148(%r14), %r13d
jge 0x48eb5
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x14837
cmpl $0x0, (%r15)
je 0x489e1
jmp 0x48ead
cmpl $0x1, (%r14)
jne 0x48cdc
cmpl $0x1, 0x148(%r14)
jne 0x48bb7
movq %r14, %rdi
callq 0x29d88
jmp 0x48f9a
movq (%r12), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0x2702b(%rip), %r8      # 0x6fa6c
pushq $0x49
popq %rsi
movq %r15, %rdi
movl $0xd03, %r9d            # imm = 0xD03
callq 0x142c0
jmp 0x48f88
movq %rax, %r13
decq %r13
cmpq $0x1, %r13
jne 0x48bf3
andq $0x0, 0x10(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, %r13
movq %rbp, %rdi
callq 0x14a53
movsbq (%rax), %rax
movq 0x48(%r12), %rdi
movl %eax, %edx
pushq $0x1b
popq %rsi
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x48ba0
movq %rax, %rbp
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3415f
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x48ba0
movq 0x68(%r12), %rdi
leaq 0x2608c(%rip), %rsi     # 0x6eb58
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x2cee3
cmpl $0x0, (%r15)
jne 0x48ba0
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x341c4
cmpl $0x0, (%r15)
jne 0x48ba0
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x49d2b
cmpl $0x0, (%r15)
jne 0x48ba0
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x148(%r14), %r8
movq %r15, (%rsp)
leaq 0x26021(%rip), %rsi     # 0x6eb58
pushq $0x2
popq %rcx
pushq $0x1
popq %r9
movq %r12, %rdi
callq 0x4b101
cmpl $0x0, (%r15)
jne 0x48ba0
movq 0x148(%r14), %rdx
movq %r12, %rdi
movq %rax, %rsi
movq %rbp, %rcx
movq %r15, %r8
callq 0x2ec82
cmpl $0x0, (%r15)
jne 0x48ba0
movq 0x48(%r12), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x48ba0
movq 0x8(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4ab28
cmpl $0x0, (%r15)
je 0x48fac
movq %r14, %rdi
callq 0x29d88
movq 0x10(%rsp), %rdi
callq 0x122c0
jmp 0x48f90
jg 0x48cc1
leaq 0x10(%rsp), %r12
movl $0x80, %esi
movq %r12, %rdi
callq 0x146a8
movq %r12, %rdi
movq %r15, %rsi
callq 0x149a8
cmpl $0x0, (%r15)
je 0x48ed3
leaq 0x10(%rsp), %rdi
callq 0x14a01
jmp 0x48f88
movq %rbp, %rdi
callq 0x14a53
movq %r12, %rdi
movq %rax, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x458cb
cmpl $0x0, (%r15)
jne 0x48f88
movq %rax, %rbp
movl %r13d, %edi
movq %r15, %rsi
callq 0x2a369
cmpl $0x0, (%r15)
jne 0x48f88
movq %rax, %r13
leaq 0x10(%rsp), %rdx
andq $0x0, (%rdx)
movq 0x68(%r12), %rdi
leaq 0x25f12(%rip), %rsi     # 0x6eb58
movq %r15, %rcx
callq 0x2cee3
cmpl $0x0, (%r15)
jne 0x48c94
movq %r15, (%rsp)
movq %r12, %rdi
movq %rax, %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq %r13, %r8
xorl %r9d, %r9d
movq %rax, %rbp
callq 0x49e81
cmpl $0x0, (%r15)
jne 0x48c94
movq (%rbp), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4ab28
cmpl $0x0, (%r15)
je 0x48f03
movq 0x10(%rsp), %rdi
callq 0x122c0
movq %r14, %rdi
callq 0x29d88
movq %r13, %rdi
callq 0x29d88
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x29d88
movq %r14, %rbx
jmp 0x48f9a
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3415f
movq %rax, %r14
cmpl $0x0, (%r15)
jne 0x48f88
leaq 0x10(%rsp), %rdx
andq $0x0, (%rdx)
movq 0x68(%r12), %rdi
leaq 0x25e67(%rip), %rsi     # 0x6eb58
movq %r15, %rcx
callq 0x2cee3
cmpl $0x0, (%r15)
jne 0x48f7e
movq %rax, 0x20(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, 0x8(%rsp)
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, %rbp
movq 0x48(%r12), %rdi
callq 0x2b774
movq %rax, %r13
movq 0x148(%rbx), %rdx
movq 0x48(%r12), %rdi
pushq $0x12
popq %rsi
xorl %ecx, %ecx
movq %r15, %r8
callq 0x2a819
cmpl $0x0, (%r15)
jne 0x48f7e
movq %r13, 0x28(%rsp)
movq 0x48(%r12), %rdi
pushq $0x43
popq %rsi
movq %rax, %rdx
movq %rbp, %rcx
movq 0x8(%rsp), %r8
movq %r15, %r9
movq %rax, %r13
callq 0x2a8c1
cmpl $0x0, (%r15)
jne 0x48f7e
movq %rbp, 0x30(%rsp)
movq 0x48(%r12), %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x48f7e
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %r13, %rdx
andq %rax, %rdx
movq 0x48(%r12), %rdi
pushq $0x1b
popq %rsi
movq %r15, %rcx
callq 0x2a981
cmpl $0x0, (%r15)
jne 0x48f7e
movq 0x20(%rsp), %rcx
movq (%rcx), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %rax, %rcx
movq %r15, %r8
callq 0x4acc2
cmpl $0x0, (%r15)
jne 0x48f7e
movq 0x48(%r12), %rdi
pushq $0x45
popq %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x2a997
cmpl $0x0, (%r15)
jne 0x48f7e
movq 0x48(%r12), %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x48f7e
movq 0x148(%rbx), %rsi
movq %r12, %rdi
xorl %edx, %edx
movq %r15, %rcx
callq 0x4a690
cmpl $0x0, (%r15)
jne 0x48f7e
movq %rax, %rbp
movq %rbx, %rdi
callq 0x29d88
movl %r13d, %edi
movq %r15, %rsi
callq 0x2a336
cmpl $0x0, (%r15)
je 0x48f21
xorl %ebx, %ebx
jmp 0x48f7e
movq %rbp, %rdi
callq 0x14a1a
cmpl $0x0, (%r15)
jne 0x48eaa
movq %rbp, %rdi
movq %r15, %rsi
callq 0x149a8
cmpl $0x0, (%r15)
jne 0x48eaa
jmp 0x48a22
leaq 0x26bd2(%rip), %rdx     # 0x6fa6c
pushq $0x1
popq %rsi
movq %r15, %rdi
movl $0xafb, %ecx            # imm = 0xAFB
callq 0x1429e
xorl %r12d, %r12d
movq %r12, %rdi
jmp 0x48f83
movq %rbp, %rdi
movq %r15, %rsi
callq 0x149a8
cmpl $0x0, (%r15)
jne 0x48ead
movq %r12, %rdi
callq 0x122c0
jmp 0x48a22
movq %r14, %rdi
callq 0x29d88
movq %rbx, %rdi
callq 0x29d88
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2a406
movq %rax, %rbx
movq %r14, %rdi
callq 0x14a01
jmp 0x48f9a
movq 0x10(%rsp), %rdx
leaq 0x25c49(%rip), %rdi     # 0x6eb58
movl %eax, %esi
movq %r15, %rcx
callq 0x2a252
movq %rax, %r14
jmp 0x48cb1
movq %r15, (%rsp)
pushq $0x1
popq %r9
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq %rax, %r8
callq 0x49e81
cmpl $0x0, (%r15)
jne 0x48f79
movq 0x48(%r12), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x2b781
cmpl $0x0, (%r15)
jne 0x48f79
movq 0x20(%rsp), %rax
movq (%rax), %rdx
pushq $0x2
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x4ab28
cmpl $0x0, (%r15)
je 0x48fdb
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
callq 0x122c0
movq %r14, %rdi
callq 0x29d88
movq %rbx, %rdi
callq 0x29d88
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 0x29d88
movq %rbx, %rdi
callq 0x29d88
movq 0x10(%rsp), %rdx
leaq 0x25b8d(%rip), %rdi     # 0x6eb58
movl %r12d, %esi
movq %r15, %rcx
callq 0x2a252
movq %rax, %rbx
jmp 0x48f9a
movq 0x10(%rsp), %rdx
leaq 0x25b71(%rip), %rdi     # 0x6eb58
movl %eax, %esi
jmp 0x48fce