// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/arch/arm32/arm_encode.c
// Function: prv_encode_stran_misc_instr
static void prv_encode_stran_misc_instr(void *user_data, subtilis_arm_op_t *op,
					subtilis_arm_instr_type_t type,
					subtilis_arm_stran_misc_instr_t *instr,
					subtilis_error_t *err)
{
	subtilis_arm_encode_ud_t *ud = user_data;
	uint32_t word = 0x90;

	prv_check_pool(ud, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if ((instr->base > 15) || (instr->dest > 15)) {
		subtilis_error_set_assertion_failed(err);
		return;
	}

	word |= instr->ccode << 28;
	if (instr->pre_indexed)
		word |= 1 << 24;

	if (instr->write_back)
		word |= 1 << 21;
	if (!instr->subtract)
		word |= 1 << 23;
	word |= instr->base << 16;
	word |= instr->dest << 12;

	switch (instr->type) {
	case SUBTILIS_ARM_STRAN_MISC_SB:
		word |= 1 << 6;
		if (type == SUBTILIS_ARM_STRAN_MISC_LDR)
			word |= 1 << 20;
		break;
	case SUBTILIS_ARM_STRAN_MISC_SH:
		word |= 1 << 6;
		word |= 1 << 5;
		if (type == SUBTILIS_ARM_STRAN_MISC_LDR)
			word |= 1 << 20;
		break;
	case SUBTILIS_ARM_STRAN_MISC_H:
		if (type == SUBTILIS_ARM_STRAN_MISC_LDR)
			word |= 1 << 20;
		word |= 1 << 5;
		break;
	case SUBTILIS_ARM_STRAN_MISC_D:
		word |= 1 << 6;
		if (type == SUBTILIS_ARM_STRAN_MISC_STR)
			word |= 1 << 5;
		break;
	}

	if (instr->reg_offset) {
		word |= instr->offset.reg;
	} else {
		word |= 1 << 22;
		word |= instr->offset.imm & 0xf;
		word |= (instr->offset.imm & 0xf0) << 8;
	}

	prv_ensure_code(ud, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	prv_add_word(ud, word, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %r8, %rbx
movq %rcx, %r15
movl %edx, %ebp
movq %rdi, %r14
movq %r8, %rsi
callq 0x55e87
cmpl $0x0, (%rbx)
je 0x5588f
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r15), %rax
cmpq $0xf, %rax
ja 0x558a3
movq 0x8(%r15), %r12
cmpq $0x10, %r12
jb 0x558c2
leaq 0x1a546(%rip), %rdx     # 0x6fdf0
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl $0x859, %ecx            # imm = 0x859
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1429e
movl (%r15), %ecx
movl 0x4(%r15), %edx
shll $0x1c, %edx
movzbl 0x28(%r15), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x29(%r15), %edx
shll $0x15, %edx
orl %esi, %edx
movzbl 0x2a(%r15), %esi
xorl $0x1, %esi
shll $0x17, %esi
orl %edx, %esi
shll $0x10, %eax
shll $0xc, %r12d
orl %eax, %r12d
orl %esi, %r12d
orl $0x90, %r12d
cmpq $0x3, %rcx
ja 0x5596b
leaq 0x1a3c2(%rip), %rax     # 0x6fcd0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
cmpl $0x83, %ebp
sete %al
shll $0x14, %eax
jmp 0x5594c
movl %r12d, %eax
orl $0x100000, %eax         # imm = 0x100000
cmpl $0x83, %ebp
cmovnel %r12d, %eax
orl $0x20, %eax
jmp 0x55968
xorl %eax, %eax
cmpl $0x84, %ebp
sete %al
shll $0x5, %eax
orl %r12d, %eax
orl $0x40, %eax
jmp 0x55968
xorl %eax, %eax
cmpl $0x83, %ebp
sete %al
shll $0x14, %eax
orl %r12d, %eax
orl $0x60, %eax
movl %eax, %r12d
cmpb $0x1, 0x18(%r15)
jne 0x55978
orl 0x20(%r15), %r12d
jmp 0x55997
movsbl 0x20(%r15), %eax
movl %eax, %ecx
andl $0xf, %ecx
shll $0x8, %eax
andl $0xf000, %eax           # imm = 0xF000
orl %ecx, %eax
orl %r12d, %eax
orl $0x400000, %eax         # imm = 0x400000
movl %eax, %r12d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x55e8e
cmpl $0x0, (%rbx)
jne 0x55886
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x55e99