// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_expression.c
// Function: prv_mid_str
static subtilis_arm_exp_val_t *prv_mid_str(subtilis_arm_ass_context_t *c,
					   subtilis_error_t *err)
{
	const char *tbuf;
	int32_t string_len;
	const char *seed_string;
	int32_t start;
	subtilis_arm_exp_val_t *ret_val = NULL;
	subtilis_arm_exp_val_t *str = NULL;
	subtilis_arm_exp_val_t *count = NULL;
	int32_t length = -1;

	subtilis_lexer_get(c->l, c->t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	tbuf = subtilis_token_get_text(c->t);
	if (strcmp(tbuf, "(")) {
		subtilis_error_set_expected(err, "( ", tbuf, c->l->stream->name,
					    c->l->line);
		return NULL;
	}

	str = subtilis_arm_exp_val_get(c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (str->type != SUBTILIS_ARM_EXP_TYPE_STRING) {
		subtilis_error_set_const_string_expected(
		    err, c->l->stream->name, c->l->line);
		goto cleanup;
	}

	tbuf = subtilis_token_get_text(c->t);
	if ((c->t->type != SUBTILIS_TOKEN_OPERATOR) || strcmp(tbuf, ",")) {
		subtilis_error_set_expected(err, ",", tbuf, c->l->stream->name,
					    c->l->line);
		goto cleanup;
	}

	count = subtilis_arm_exp_val_get(c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	start = prv_exp_to_int(c, count, err);
	subtilis_arm_exp_val_free(count);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tbuf = subtilis_token_get_text(c->t);
	if ((c->t->type != SUBTILIS_TOKEN_OPERATOR) ||
	    (strcmp(tbuf, ")") && strcmp(tbuf, ","))) {
		subtilis_error_set_expected(err, ", or )", tbuf,
					    c->l->stream->name, c->l->line);
		goto cleanup;
	}

	if (!strcmp(tbuf, ",")) {
		count = subtilis_arm_exp_val_get(c, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		length = prv_exp_to_int(c, count, err);
		subtilis_arm_exp_val_free(count);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;

		tbuf = subtilis_token_get_text(c->t);
		if ((c->t->type != SUBTILIS_TOKEN_OPERATOR) ||
		    strcmp(tbuf, ")")) {
			subtilis_error_set_right_bkt_expected(
			    err, tbuf, c->l->stream->name, c->l->line);
			goto cleanup;
		}
	}

	subtilis_lexer_get(c->l, c->t, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	string_len = subtilis_buffer_get_size(&str->val.buf) - 1;
	if ((string_len == 0) || (start < 0) || (length == 0)) {
		ret_val = subtilis_arm_exp_new_str_str("", err);
	} else {
		seed_string = subtilis_buffer_get_string(&str->val.buf);
		if (length < 0 || length >= (string_len - start)) {
			ret_val = subtilis_arm_exp_new_str_str(
			    &seed_string[start], err);
		} else {
			subtilis_buffer_delete(&str->val.buf, 0, start, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			if (start + length < string_len)
				subtilis_buffer_delete(
				    &str->val.buf, length,
				    string_len - (start + length), err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;
			subtilis_buffer_zero_terminate(&str->val.buf, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto cleanup;

			ret_val = subtilis_arm_exp_new_str(&str->val.buf, err);
		}
	}

cleanup:

	subtilis_arm_exp_val_free(str);

	return ret_val;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%rdi), %rdi
movq 0x10(%r15), %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x6b0f4
movq 0x10(%r15), %rdi
callq 0x12ad0
movq %rax, %rbx
leaq 0x915e(%rip), %rsi      # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x6b109
movq 0x8(%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0xbebd(%rip), %rax      # 0x76f90
leaq 0x87e8(%rip), %rdx      # 0x738c2
movq %r14, %rdi
movl $0x1d, %esi
movq %rbx, %rcx
pushq $0x4b6                  # imm = 0x4B6
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %r14, %rsi
callq 0x69a84
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x6b1a9
cmpl $0x8, (%rbx)
jne 0x6b184
movq 0x10(%r15), %rdi
callq 0x12ad0
movq %rax, %r12
movq 0x10(%r15), %rax
cmpl $0x2, (%rax)
jne 0x6b14e
leaq 0x8456(%rip), %rsi      # 0x73598
movq %r12, %rdi
callq 0x12160
testl %eax, %eax
je 0x6b1b9
movq 0x8(%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0xbe2f(%rip), %rax      # 0x76f90
leaq 0x8430(%rip), %rdx      # 0x73598
movq %r14, %rdi
movl $0x1d, %esi
movq %r12, %rcx
pushq $0x4c7                  # imm = 0x4C7
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x6b1a9
movq 0x8(%r15), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0xbdfa(%rip), %r8       # 0x76f90
movq %r14, %rdi
movl $0x4a, %esi
movl $0x4c0, %r9d            # imm = 0x4C0
callq 0x14618
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x69167
jmp 0x6b0f7
movq %r15, %rdi
movq %r14, %rsi
callq 0x69a84
cmpl $0x0, (%r14)
jne 0x6b1a9
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x6b731
movl %eax, %ebp
movq %r12, %rdi
callq 0x69167
cmpl $0x0, (%r14)
jne 0x6b1a9
movq 0x10(%r15), %rdi
callq 0x12ad0
movq %rax, %r12
movq 0x10(%r15), %rax
cmpl $0x2, (%rax)
jne 0x6b226
leaq 0x88e6(%rip), %rsi      # 0x73aed
movq %r12, %rdi
callq 0x12160
testl %eax, %eax
je 0x6b255
leaq 0x837e(%rip), %rsi      # 0x73598
movq %r12, %rdi
callq 0x12160
testl %eax, %eax
je 0x6b255
movq 0x8(%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0xbd57(%rip), %rax      # 0x76f90
leaq 0x88a8(%rip), %rdx      # 0x73ae8
movq %r14, %rdi
movl $0x1d, %esi
movq %r12, %rcx
pushq $0x4d8                  # imm = 0x4D8
jmp 0x6b178
leaq 0x833c(%rip), %rsi      # 0x73598
movq %r12, %rdi
callq 0x12160
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x6b2c4
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x6b1a9
movq %rbx, %r13
addq $0x8, %r13
movq %r13, %rdi
callq 0x14ba1
decl %eax
movq %rax, (%rsp)
sete %al
testl %ebp, %ebp
sets %cl
testl %r12d, %r12d
sete %dl
orb %cl, %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x6b35a
leaq 0x8b36(%rip), %rdi      # 0x73df5
jmp 0x6b3e1
movq %r15, %rdi
movq %r14, %rsi
callq 0x69a84
cmpl $0x0, (%r14)
jne 0x6b1a9
movq %rax, %r13
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x6b731
movl %eax, %r12d
movq %r13, %rdi
callq 0x69167
cmpl $0x0, (%r14)
jne 0x6b1a9
movq 0x10(%r15), %rdi
callq 0x12ad0
movq %rax, %r13
movq 0x10(%r15), %rax
cmpl $0x2, (%rax)
jne 0x6b32b
leaq 0x87d2(%rip), %rsi      # 0x73aed
movq %r13, %rdi
callq 0x12160
testl %eax, %eax
je 0x6b26e
movq 0x8(%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0xbc52(%rip), %rax      # 0x76f90
leaq 0x8ab0(%rip), %rcx      # 0x73df5
movq %r14, %rdi
movl $0x16, %esi
movq %r13, %rdx
pushq $0x4ea                  # imm = 0x4EA
jmp 0x6b178
movq %r13, %rdi
callq 0x14dfb
movl %ebp, %edx
testl %r12d, %r12d
js 0x6b3db
movq (%rsp), %rcx
subl %ebp, %ecx
cmpl %ecx, %r12d
jge 0x6b3db
xorl %r15d, %r15d
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0x14cbb
cmpl $0x0, (%r14)
jne 0x6b1ac
addl %r12d, %ebp
movq (%rsp), %rax
subl %ebp, %eax
movq %rax, (%rsp)
jle 0x6b3af
movl %r12d, %esi
movslq (%rsp), %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x14cbb
cmpl $0x0, (%r14)
jne 0x6b1a9
movq %r13, %rdi
movq %r14, %rsi
callq 0x14d4b
cmpl $0x0, (%r14)
jne 0x6b1a9
movq %r13, %rdi
movq %r14, %rsi
callq 0x6918d
jmp 0x6b3e9
addq %rdx, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x690d1
movq %rax, %r15
jmp 0x6b1ac