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

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

	word |= instr->ccode << 28;
	word |= 0x4 << 25;

	m_type = instr->type;
	if (type == SUBTILIS_ARM_INSTR_STM) {
		switch (m_type) {
		case SUBTILIS_ARM_MTRAN_FA:
			m_type = SUBTILIS_ARM_MTRAN_IB;
			break;
		case SUBTILIS_ARM_MTRAN_FD:
			m_type = SUBTILIS_ARM_MTRAN_DB;
			break;
		case SUBTILIS_ARM_MTRAN_EA:
			m_type = SUBTILIS_ARM_MTRAN_IA;
			break;
		case SUBTILIS_ARM_MTRAN_ED:
			m_type = SUBTILIS_ARM_MTRAN_DA;
			break;
		default:
			break;
		}
	} else {
		switch (m_type) {
		case SUBTILIS_ARM_MTRAN_FA:
			m_type = SUBTILIS_ARM_MTRAN_DA;
			break;
		case SUBTILIS_ARM_MTRAN_FD:
			m_type = SUBTILIS_ARM_MTRAN_IA;
			break;
		case SUBTILIS_ARM_MTRAN_EA:
			m_type = SUBTILIS_ARM_MTRAN_DB;
			break;
		case SUBTILIS_ARM_MTRAN_ED:
			m_type = SUBTILIS_ARM_MTRAN_IB;
			break;
		default:
			break;
		}
	}

	switch (m_type) {
	case SUBTILIS_ARM_MTRAN_IA:
		word |= 1 << 23;
		break;
	case SUBTILIS_ARM_MTRAN_IB:
		word |= 1 << 23;
		word |= 1 << 24;
		break;
	case SUBTILIS_ARM_MTRAN_DA:
		break;
	case SUBTILIS_ARM_MTRAN_DB:
		word |= 1 << 24;
		break;
	default:
		break;
	}

	if (instr->write_back)
		word |= 1 << 21;

	if (instr->status)
		word |= 1 << 22;

	if (type == SUBTILIS_ARM_INSTR_LDM)
		word |= 1 << 20;

	word |= instr->op0 << 16;
	word |= instr->reg_list & 0xffff;

	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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %rbx
movq %rcx, %r15
movl %edx, %ebp
movq %rdi, %r14
movq %r8, %rsi
callq 0x55e87
cmpl $0x0, (%rbx)
jne 0x5438e
movl (%r15), %eax
movl 0x18(%r15), %ecx
shll $0x1c, %eax
leal 0x8000000(%rax), %esi
cmpl $0x15, %ebp
movl %ebp, 0x4(%rsp)
jne 0x54330
cmpl $0x6, %ecx
ja 0x54364
pushq $0x12
popq %rdx
btl %ecx, %edx
jb 0x5434f
pushq $0x28
popq %rdx
btl %ecx, %edx
jb 0x54356
pushq $0x41
popq %rdx
btl %ecx, %edx
jb 0x5435d
jmp 0x54364
cmpl $0x7, %ecx
ja 0x54364
pushq $0x21
popq %rdx
btl %ecx, %edx
jb 0x5435d
pushq $0x48
popq %rdx
btl %ecx, %edx
jb 0x54356
movl $0x82, %edx
btl %ecx, %edx
jae 0x54364
orl $0x9800000, %eax        # imm = 0x9800000
jmp 0x54362
orl $0x9000000, %eax        # imm = 0x9000000
jmp 0x54362
orl $0x8800000, %eax        # imm = 0x8800000
movl %eax, %esi
movl %esi, %ebp
movb 0x1c(%r15), %r12b
movb 0x1d(%r15), %al
movb %al, 0x3(%rsp)
movq 0x8(%r15), %r13
movq 0x10(%r15), %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x55e8e
cmpl $0x0, (%rbx)
movl 0x4(%rsp), %edx
je 0x5439d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %eax
orl $0x200000, %eax         # imm = 0x200000
testb %r12b, %r12b
cmovel %ebp, %eax
movl %eax, %ecx
orl $0x400000, %ecx         # imm = 0x400000
cmpb $0x0, 0x3(%rsp)
cmovel %eax, %ecx
movl %ecx, %eax
orl $0x100000, %eax         # imm = 0x100000
cmpl $0x14, %edx
cmovnel %ecx, %eax
shll $0x10, %r13d
movzwl %r15w, %esi
orl %r13d, %esi
orl %eax, %esi
movq %r14, %rdi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x55e99