// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/assembler.c
// Function: prv_get_op2
static void prv_get_op2(subtilis_arm_ass_context_t *c, subtilis_arm_op2_t *op2,
			subtilis_error_t *err)
{
	uint32_t encoded;
	int32_t num;
	subtilis_arm_exp_val_t *val;
	const char *tbuf;

	val = subtilis_arm_exp_val_get(c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if ((val->type == SUBTILIS_ARM_EXP_TYPE_INT) ||
	    (val->type == SUBTILIS_ARM_EXP_TYPE_REAL)) {
		if (val->type == SUBTILIS_ARM_EXP_TYPE_REAL)
			num = (int32_t)val->val.real;
		else
			num = val->val.integer;
		if (!subtilis_arm_encode_imm(num, &encoded)) {
			subtilis_error_set_ass_integer_encode(
			    err, num, c->l->stream->name, c->l->line);
			goto cleanup;
		}
		op2->type = SUBTILIS_ARM_OP2_I32;
		op2->op.integer = encoded;
		goto cleanup;
	}

	if (val->type != SUBTILIS_ARM_EXP_TYPE_REG) {
		subtilis_error_set_expected(err, "register",
					    subtilis_arm_exp_type_name(val),
					    c->l->stream->name, c->l->line);
		goto cleanup;
	}

	op2->op.reg = val->val.reg;

	tbuf = subtilis_token_get_text(c->t);
	if (c->t->type != SUBTILIS_TOKEN_OPERATOR) {
		op2->type = SUBTILIS_ARM_OP2_REG;
		goto cleanup;
	}

	op2->type = SUBTILIS_ARM_OP2_SHIFTED;

	tbuf = subtilis_token_get_text(c->t);
	if (strcmp(tbuf, ",")) {
		op2->type = SUBTILIS_ARM_OP2_REG;
		goto cleanup;
	}

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

	tbuf = subtilis_token_get_text(c->t);
	if (c->t->type != SUBTILIS_TOKEN_KEYWORD) {
		subtilis_error_set_keyword_expected(
		    err, tbuf, c->l->stream->name, c->l->line);
		goto cleanup;
	}

	switch (c->t->tok.keyword.type) {
	case SUBTILIS_ARM_KEYWORD_ASR:
		op2->op.shift.type = SUBTILIS_ARM_SHIFT_ASR;
		break;
	case SUBTILIS_ARM_KEYWORD_LSL:
		op2->op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
		break;
	case SUBTILIS_ARM_KEYWORD_LSR:
		op2->op.shift.type = SUBTILIS_ARM_SHIFT_LSR;
		break;
	case SUBTILIS_ARM_KEYWORD_ROR:
		op2->op.shift.type = SUBTILIS_ARM_SHIFT_ROR;
		break;
	case SUBTILIS_ARM_KEYWORD_RRX:
		op2->op.shift.type = SUBTILIS_ARM_SHIFT_RRX;
		break;
	default:
		subtilis_error_set_expected(
		    err, "ASR or LSL or LSR or ROR or RRX", tbuf,
		    c->l->stream->name, c->l->line);
		goto cleanup;
	}

	subtilis_arm_exp_val_free(val);
	val = subtilis_arm_exp_val_get(c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (val->type == SUBTILIS_ARM_EXP_TYPE_INT) {
		op2->op.shift.shift.integer = val->val.integer;
		op2->op.shift.shift_reg = false;
	} else if (val->type == SUBTILIS_ARM_EXP_TYPE_REG) {
		op2->op.shift.shift.reg = val->val.reg;
		op2->op.shift.shift_reg = true;
	} else {
		subtilis_error_set_expected(err, "integer or register",
					    subtilis_arm_exp_type_name(val),
					    c->l->stream->name, c->l->line);
		if (err->type != SUBTILIS_ERROR_OK)
			goto cleanup;
	}

cleanup:

	subtilis_arm_exp_val_free(val);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq %rdx, %rsi
callq 0x69a84
cmpl $0x0, (%r14)
jne 0x67fe1
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x1, %eax
je 0x67f57
cmpl $0x6, %eax
je 0x67f02
cmpl $0x7, %eax
jne 0x67f9c
cvttsd2si 0x8(%rbx), %ebp
jmp 0x67f05
movl 0x8(%rbx), %ebp
leaq 0xc(%rsp), %rsi
movl %ebp, %edi
callq 0x4f8d1
testb %al, %al
je 0x67f2b
movl $0x1, (%r12)
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
jmp 0x67fd9
movq 0x8(%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0xedd2(%rip), %rax      # 0x76d10
movq %r14, %rdi
movl $0x59, %esi
movl %ebp, %edx
xorl %ecx, %ecx
pushq $0x1a2                  # imm = 0x1A2
pushq %rax
callq 0x144d6
jmp 0x67fd5
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r12)
movq 0x10(%r15), %rdi
callq 0x12ad0
movq 0x10(%r15), %rdi
cmpl $0x2, (%rdi)
jne 0x67f92
movl $0x2, (%r12)
callq 0x12ad0
leaq 0xb612(%rip), %rsi      # 0x73598
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x67fee
movl $0x0, (%r12)
jmp 0x67fd9
movq %rbx, %rdi
callq 0x69abf
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xed59(%rip), %r10      # 0x76d10
leaq 0xedfb(%rip), %rdx      # 0x76db9
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x1ad                  # imm = 0x1AD
pushq %r10
callq 0x1442a
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x69167
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x67fd9
movq 0x10(%r15), %rdi
callq 0x12ad0
movq 0x10(%r15), %rcx
cmpl $0x1, (%rcx)
jne 0x68071
movl 0x8(%rcx), %ecx
addl $-0x27, %ecx
cmpl $0x5, %ecx
jae 0x680a0
movl %ecx, %eax
leaq 0xecd2(%rip), %rcx      # 0x76cfc
movl (%rcx,%rax,4), %eax
movl %eax, 0x10(%r12)
movq %rbx, %rdi
callq 0x69167
movq %r15, %rdi
movq %r14, %rsi
callq 0x69a84
cmpl $0x0, (%r14)
jne 0x67fe1
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x1, %eax
je 0x680cf
cmpl $0x6, %eax
jne 0x680e3
movl 0x8(%rbx), %eax
movl %eax, 0x18(%r12)
movb $0x0, 0x20(%r12)
jmp 0x67fd9
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xec8c(%rip), %r10      # 0x76d10
leaq 0xbd6a(%rip), %rcx      # 0x73df5
movq %r14, %rdi
movl $0x10, %esi
movq %rax, %rdx
pushq $0x1c8                  # imm = 0x1C8
jmp 0x67fce
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xec5d(%rip), %r10      # 0x76d10
leaq 0xed26(%rip), %rdx      # 0x76de0
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x1df                  # imm = 0x1DF
jmp 0x67fce
movq 0x8(%rbx), %rax
movq %rax, 0x18(%r12)
movb $0x1, 0x20(%r12)
jmp 0x67fd9
movq %rbx, %rdi
callq 0x69abf
movq 0x8(%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0xec12(%rip), %r10      # 0x76d10
leaq 0xecfb(%rip), %rdx      # 0x76e00
movq %r14, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x1f1                  # imm = 0x1F1
jmp 0x67fce