// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rcx, %r15
movl %edx, %ebp
movq %rdi, %rbx
xorl %esi, %esi
movq %r8, %rdx
callq 0x59e32
cmpl $0x0, (%r14)
jne 0x57eb6
movl (%r15), %eax
movl 0x18(%r15), %ecx
shll $0x1c, %eax
leal 0x8000000(%rax), %esi
cmpl $0x15, %ebp
movl %ebp, 0x4(%rsp)
jne 0x57e50
cmpl $0x6, %ecx
ja 0x57e88
movl $0x12, %edx
btl %ecx, %edx
jb 0x57e73
movl $0x28, %edx
btl %ecx, %edx
jb 0x57e7a
movl $0x41, %edx
btl %ecx, %edx
jb 0x57e81
jmp 0x57e88
cmpl $0x7, %ecx
ja 0x57e88
movl $0x21, %edx
btl %ecx, %edx
jb 0x57e81
movl $0x48, %edx
btl %ecx, %edx
jb 0x57e7a
movl $0x82, %edx
btl %ecx, %edx
jae 0x57e88
orl $0x9800000, %eax        # imm = 0x9800000
jmp 0x57e86
orl $0x9000000, %eax        # imm = 0x9000000
jmp 0x57e86
orl $0x8800000, %eax        # imm = 0x8800000
movl %eax, %esi
movl %esi, (%rsp)
movb 0x1c(%r15), %bpl
movb 0x1d(%r15), %r12b
movq 0x8(%r15), %r13
movq 0x10(%r15), %r15
movl $0x4, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x5758f
cmpl $0x0, (%r14)
movl 0x4(%rsp), %r8d
je 0x57ec5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rbx), %rax
testb $0x3, %al
je 0x57ef4
leaq 0x1dfac(%rip), %rdx     # 0x75e80
movq %r14, %rdi
movl $0x5d, %esi
movl $0xfb, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x145a4
shll $0x10, %r13d
movl (%rsp), %edx
movl %edx, %ecx
orl $0x200000, %ecx         # imm = 0x200000
testb %bpl, %bpl
cmovel %edx, %ecx
movl %ecx, %edx
orl $0x400000, %edx         # imm = 0x400000
testb %r12b, %r12b
cmovel %ecx, %edx
movzwl %r15w, %ecx
movl %edx, %esi
orl $0x100000, %esi         # imm = 0x100000
cmpl $0x14, %r8d
cmovnel %edx, %esi
orl %ecx, %r13d
orl %esi, %r13d
movq 0x28(%rbx), %rcx
movl %r13d, (%rcx,%rax)
addq $0x4, %rax
movq %rax, 0x30(%rbx)
jmp 0x57eb6