// File: /workspace/github_c_makefile_star2_O1/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, 0x4(%rsp)
movq %rdi, %rbx
xorl %esi, %esi
movq %r8, %rdx
callq 0x59d65
cmpl $0x0, (%r14)
jne 0x57d91
movl (%r15), %r12d
movl 0x18(%r15), %eax
leal -0x4(%rax), %ecx
cmpl $0x3, %ecx
ja 0x57d33
cmpl $0x15, 0x4(%rsp)
leaq 0x1defd(%rip), %rax     # 0x75c20
leaq 0x1df06(%rip), %rdx     # 0x75c30
cmoveq %rax, %rdx
movl %ecx, %eax
movl (%rdx,%rax,4), %eax
shll $0x1c, %r12d
cmpl $0x3, %eax
je 0x57d57
cmpl $0x1, %eax
je 0x57d4e
testl %eax, %eax
jne 0x57d60
orl $0x8800000, %r12d       # imm = 0x8800000
jmp 0x57d67
orl $0x9800000, %r12d       # imm = 0x9800000
jmp 0x57d67
orl $0x9000000, %r12d       # imm = 0x9000000
jmp 0x57d67
orl $0x8000000, %r12d       # imm = 0x8000000
movb 0x1c(%r15), %al
movb %al, 0x3(%rsp)
movb 0x1d(%r15), %bpl
movq 0x8(%r15), %r13
movq 0x10(%r15), %r15
movl $0x4, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x57496
cmpl $0x0, (%r14)
je 0x57da0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0x3(%rsp), %dl
movq 0x30(%rbx), %rax
testb $0x3, %al
je 0x57dd3
leaq 0x1e08d(%rip), %rdx     # 0x75e40
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 0x145f4
shll $0x10, %r13d
movl %r12d, %ecx
orl $0x200000, %ecx         # imm = 0x200000
testb %dl, %dl
cmovel %r12d, %ecx
movl %ecx, %edx
orl $0x400000, %edx         # imm = 0x400000
testb %bpl, %bpl
cmovel %ecx, %edx
movzwl %r15w, %ecx
movl %edx, %esi
orl $0x100000, %esi         # imm = 0x100000
cmpl $0x14, 0x4(%rsp)
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 0x57d91