// File: /workspace/github_c_makefile_star2_O3/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 0x12edc
cmpl $0x0, (%r14)
jne 0x6acd5
movq 0x10(%r15), %rdi
callq 0x12ad0
cmpb $0x28, (%rax)
jne 0x6aca0
cmpb $0x0, 0x1(%rax)
je 0x6acea
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xc341(%rip), %r10      # 0x76ff4
leaq 0x8c3c(%rip), %rdx      # 0x738f6
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x4b6                  # imm = 0x4B6
pushq %r10
callq 0x143da
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 0x69632
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x6ad7c
cmpl $0x8, (%rbx)
jne 0x6ad57
movq 0x10(%r15), %rdi
callq 0x12ad0
movq 0x10(%r15), %rcx
cmpl $0x2, (%rcx)
jne 0x6ad20
cmpb $0x2c, (%rax)
jne 0x6ad20
cmpb $0x0, 0x1(%rax)
je 0x6ad8c
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xc2c1(%rip), %r10      # 0x76ff4
leaq 0x8858(%rip), %rdx      # 0x73592
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x4c7                  # imm = 0x4C7
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x6ad7c
movq 0x8(%r15), %rax
movq 0x30(%rax), %rdx
movl 0x38(%rax), %ecx
leaq 0xc28b(%rip), %r8       # 0x76ff4
movq %r14, %rdi
movl $0x4a, %esi
movl $0x4c0, %r9d            # imm = 0x4C0
callq 0x145c8
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x68d41
jmp 0x6acd8
movq %r15, %rdi
movq %r14, %rsi
callq 0x69632
cmpl $0x0, (%r14)
jne 0x6ad7c
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x6b2c1
movl %eax, %ebp
movq %r12, %rdi
callq 0x68d41
cmpl $0x0, (%r14)
jne 0x6ad7c
movq 0x10(%r15), %rdi
callq 0x12ad0
movq 0x10(%r15), %rsi
cmpl $0x2, (%rsi)
jne 0x6adf3
movzbl (%rax), %ecx
cmpl $0x2c, %ecx
je 0x6aded
cmpl $0x29, %ecx
jne 0x6adf3
cmpb $0x0, 0x1(%rax)
jne 0x6adf3
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
jmp 0x6ae30
cmpb $0x0, 0x1(%rax)
je 0x6ae22
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xc1ee(%rip), %r10      # 0x76ff4
leaq 0x8cf3(%rip), %rdx      # 0x73b00
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x4d8                  # imm = 0x4D8
jmp 0x6ad4a
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
cmpb $0x0, 0x1(%rax)
je 0x6ae84
movq 0x8(%r15), %rdi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x6ad7c
movq %rbx, %r13
addq $0x8, %r13
movq %r13, %rdi
callq 0x14b57
movq %rax, %r12
decl %r12d
sete %al
testl %ebp, %ebp
sets %cl
cmpl $0x0, 0x4(%rsp)
sete %dl
orb %cl, %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x6af10
leaq 0x8f96(%rip), %rdi      # 0x73e15
jmp 0x6af93
movq %r15, %rdi
movq %r14, %rsi
callq 0x69632
cmpl $0x0, (%r14)
jne 0x6ad7c
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x6b2c1
movl %eax, 0x4(%rsp)
movq %r12, %rdi
callq 0x68d41
cmpl $0x0, (%r14)
jne 0x6ad7c
movq 0x10(%r15), %rdi
callq 0x12ad0
movq 0x10(%r15), %rsi
cmpl $0x2, (%rsi)
jne 0x6aee1
cmpb $0x29, (%rax)
jne 0x6aee1
cmpb $0x0, 0x1(%rax)
je 0x6ae30
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xc100(%rip), %r10      # 0x76ff4
leaq 0x8f1a(%rip), %rcx      # 0x73e15
movq %r14, %rdi
movl $0x16, %esi
movq %rax, %rdx
pushq $0x4ea                  # imm = 0x4EA
jmp 0x6ad4a
movq %r13, %rdi
callq 0x14db1
movl %ebp, %edx
cmpl $0x0, 0x4(%rsp)
js 0x6af8d
movl %r12d, %ecx
subl %ebp, %ecx
cmpl %ecx, 0x4(%rsp)
jge 0x6af8d
xorl %r15d, %r15d
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0x14c71
cmpl $0x0, (%r14)
jne 0x6ad7f
addl 0x4(%rsp), %ebp
subl %ebp, %r12d
jle 0x6af6b
movl 0x4(%rsp), %esi
movslq %r12d, %rdx
movq %r13, %rdi
movq %r14, %rcx
callq 0x14c71
cmpl $0x0, (%r14)
jne 0x6ad7c
movq %r13, %rdi
movq %r14, %rsi
callq 0x14d01
cmpl $0x0, (%r14)
jne 0x6ad7c
movq %r13, %rdi
movq %r14, %rsi
callq 0x68d67
jmp 0x6af9b
addq %rdx, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x68cab
movq %rax, %r15
jmp 0x6ad7f