// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/assembler/ins_enc.c
// Function: ins_enc_mov_rxX_Ib
void ins_enc_mov_rxX_Ib(
	Instruction *ins,
	InstructionEncoderData *data
) {
	_CHECK_PARAMS(2);

	ParserASTNode *ins_node = data->ins_node;

	ParserASTNode *target = data->ins_node->childs[0];

	ParserASTNode *source = data->ins_node->childs[1];

	EncoderInstruction enc_ins;

	ins_init(data->ctx, ins, ins_node, &enc_ins);

	InsRegister *ins_target_reg = ASM_REG_AST_NODE_GET_REG(target);
	assert(ins_target_reg);

	switch (ASM_PARSER_CONTEXT_DATA_GET_ARCH(data->ctx)) {
		case ASM_ARCH_BIT16: {
			switch (ins_target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;

					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					data->ctx->syntax_error_node_msg(
						data->ctx,
						ins_node,
						"instruction not supported in 64-bit mode."
					);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}
			break;
		}
		case ASM_ARCH_BIT32: {
			switch (ins_target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;

					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					data->ctx->syntax_error_node_msg(
						data->ctx,
						ins_node,
						"instruction not supported in 64-bit mode."
					);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}
			break;
		}
		case ASM_ARCH_BIT64: {
			switch (ins_target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;

					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}
			break;
		}
		default: {
			assert(0);
			break;
		}
	}

	_output(data, &enc_ins);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
testq %rdi, %rdi
je 0x19a13
movq %rsi, %rbx
testq %rsi, %rsi
je 0x19a1c
movq (%rbx), %r12
testq %r12, %r12
je 0x19a25
cmpl $0x2, 0x44(%r12)
jne 0x19a2e
movq %rdi, %r14
movq 0x48(%r12), %rax
movq (%rax), %r13
movq 0x8(%rax), %r15
movq 0x8(%rbx), %rdi
leaq -0x88(%rbp), %rcx
movq %r14, %rsi
movq %r12, %rdx
callq 0x1524f
movq 0x60(%r13), %rax
testq %rax, %rax
je 0x19a4d
movq 0x8(%rbx), %rdi
movl 0xb0(%rdi), %ecx
cmpl $0x4, %ecx
je 0x19999
cmpl $0x2, %ecx
je 0x19968
cmpl $0x1, %ecx
jne 0x19a6c
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x199d0
cmpl $0x4, %eax
je 0x199df
cmpl $0x3, %eax
jne 0x19a8b
leaq -0x88(%rbp), %rcx
jmp 0x199ba
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x199d0
cmpl $0x4, %eax
je 0x199c7
cmpl $0x3, %eax
je 0x199af
leaq 0x149ef(%rip), %rdi     # 0x2e370
leaq 0x182bc(%rip), %rsi     # 0x31c44
leaq 0x18a83(%rip), %rcx     # 0x32412
movl $0x470, %edx            # imm = 0x470
callq 0xa0b0
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x199c7
cmpl $0x4, %eax
je 0x199c7
cmpl $0x3, %eax
jne 0x19aaa
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x15d47
jmp 0x199f5
leaq -0x88(%rbp), %rcx
jmp 0x199ea
leaq 0x185ab(%rip), %rdx     # 0x31f82
movq %r12, %rsi
callq *0x58(%rdi)
jmp 0x199f5
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x15e3d
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x17e70
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16d10(%rip), %rdi     # 0x3072a
jmp 0x19a35
leaq 0x1cb38(%rip), %rdi     # 0x3655b
jmp 0x19a35
leaq 0x18275(%rip), %rdi     # 0x31ca1
jmp 0x19a35
leaq 0x1827b(%rip), %rdi     # 0x31cb0
leaq 0x18208(%rip), %rsi     # 0x31c44
leaq 0x189cf(%rip), %rcx     # 0x32412
movl $0x430, %edx            # imm = 0x430
callq 0xa0b0
leaq 0x189ff(%rip), %rdi     # 0x32453
leaq 0x181e9(%rip), %rsi     # 0x31c44
leaq 0x189b0(%rip), %rcx     # 0x32412
movl $0x43d, %edx            # imm = 0x43D
callq 0xa0b0
leaq 0x148fd(%rip), %rdi     # 0x2e370
leaq 0x181ca(%rip), %rsi     # 0x31c44
leaq 0x18991(%rip), %rcx     # 0x32412
movl $0x48e, %edx            # imm = 0x48E
callq 0xa0b0
leaq 0x148de(%rip), %rdi     # 0x2e370
leaq 0x181ab(%rip), %rsi     # 0x31c44
leaq 0x18972(%rip), %rcx     # 0x32412
movl $0x455, %edx            # imm = 0x455
callq 0xa0b0
leaq 0x148bf(%rip), %rdi     # 0x2e370
leaq 0x1818c(%rip), %rsi     # 0x31c44
leaq 0x18953(%rip), %rcx     # 0x32412
movl $0x487, %edx            # imm = 0x487
callq 0xa0b0