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

	ParserASTNode *ins_node = data->ins_node;

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

	EncoderInstruction enc_ins;

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

	int arch = ASM_PARSER_CONTEXT_DATA_GET_ARCH(data->ctx);

	InsRegister *target_reg = ASM_REG_AST_NODE_GET_REG(target);

	switch (arch) {
		case ASM_ARCH_BIT16: {
			switch (target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					// 无需操作数大小前缀。
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					data->ctx->syntax_error_node_msg(
						data->ctx,
						ins_node,
						"instruction not supported in 16-bit mode."
					);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}
			break;
		}
		case ASM_ARCH_BIT32: {
			switch (target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					// 无需操作数大小前缀。
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					data->ctx->syntax_error_node_msg(
						data->ctx,
						ins_node,
						"instruction not supported in 32-bit mode."
					);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}
			break;
		}
		case ASM_ARCH_BIT64: {
			switch (target_reg->type) {
				case INS_REGISTER_GENERAL_2BYTE: {
					enc_ins.legacy_prefix.operand_size_override = true;
					break;
				}
				case INS_REGISTER_GENERAL_4BYTE: {
					data->ctx->syntax_error_node_msg(
						data->ctx,
						ins_node,
						"instruction not supported in 64-bit mode."
					);
					break;
				}
				case INS_REGISTER_GENERAL_8BYTE: {
					// 无需操作数大小前缀。
					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 %rbx
subq $0x68, %rsp
testq %rdi, %rdi
je 0x17b8d
movq %rsi, %rbx
testq %rsi, %rsi
je 0x17b96
movq (%rbx), %r14
testq %r14, %r14
je 0x17b9f
cmpl $0x1, 0x44(%r14)
jne 0x17ba8
movq %rdi, %rsi
movq 0x48(%r14), %rax
movq (%rax), %r15
movq 0x8(%rbx), %rdi
leaq -0x78(%rbp), %rcx
movq %r14, %rdx
callq 0x1470f
movq 0x8(%rbx), %rdi
movl 0xb0(%rdi), %ecx
movq 0x60(%r15), %rax
cmpl $0x4, %ecx
je 0x17b3b
cmpl $0x2, %ecx
je 0x17b0a
cmpl $0x1, %ecx
jne 0x17bc7
movl 0xc(%rax), %eax
cmpl $0x3, %eax
je 0x17b76
cmpl $0x5, %eax
je 0x17b69
cmpl $0x4, %eax
je 0x17b51
leaq 0x1587e(%rip), %rdi     # 0x2d370
leaq 0x1915b(%rip), %rsi     # 0x30c54
leaq 0x19451(%rip), %rcx     # 0x30f51
movl $0x190, %edx            # imm = 0x190
callq 0xa0b0
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x17b57
cmpl $0x4, %eax
je 0x17b76
cmpl $0x3, %eax
je 0x17b51
leaq 0x1584d(%rip), %rdi     # 0x2d370
leaq 0x1912a(%rip), %rsi     # 0x30c54
leaq 0x19420(%rip), %rcx     # 0x30f51
movl $0x1a9, %edx            # imm = 0x1A9
callq 0xa0b0
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x17b76
cmpl $0x4, %eax
je 0x17b60
cmpl $0x3, %eax
jne 0x17be6
movb $0x1, -0x6d(%rbp)
jmp 0x17b76
leaq 0x1932c(%rip), %rdx     # 0x30e8a
jmp 0x17b70
leaq 0x1942b(%rip), %rdx     # 0x30f92
jmp 0x17b70
leaq 0x192f0(%rip), %rdx     # 0x30e60
movq %r14, %rsi
callq *0x58(%rdi)
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x17180
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17ba6(%rip), %rdi     # 0x2f73a
jmp 0x17baf
leaq 0x1da4e(%rip), %rdi     # 0x355eb
jmp 0x17baf
leaq 0x1910b(%rip), %rdi     # 0x30cb1
jmp 0x17baf
leaq 0x19383(%rip), %rdi     # 0x30f32
leaq 0x1909e(%rip), %rsi     # 0x30c54
leaq 0x19394(%rip), %rcx     # 0x30f51
movl $0x16e, %edx            # imm = 0x16E
callq 0xa0b0
leaq 0x157a2(%rip), %rdi     # 0x2d370
leaq 0x1907f(%rip), %rsi     # 0x30c54
leaq 0x19375(%rip), %rcx     # 0x30f51
movl $0x1c9, %edx            # imm = 0x1C9
callq 0xa0b0
leaq 0x15783(%rip), %rdi     # 0x2d370
leaq 0x19060(%rip), %rsi     # 0x30c54
leaq 0x19356(%rip), %rcx     # 0x30f51
movl $0x1c2, %edx            # imm = 0x1C2
callq 0xa0b0