// File: /workspace/github_c_makefile_star2_O3/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 0x18889
movq %rsi, %rbx
testq %rsi, %rsi
je 0x18892
movq (%rbx), %r14
testq %r14, %r14
je 0x1889b
cmpl $0x1, 0x44(%r14)
jne 0x188a4
movq %rdi, %rsi
movq 0x48(%r14), %rax
movq (%rax), %r15
movq 0x8(%rbx), %rdi
leaq -0x78(%rbp), %rcx
movq %r14, %rdx
callq 0x1524f
movq 0x8(%rbx), %rdi
movl 0xb0(%rdi), %ecx
movq 0x60(%r15), %rax
cmpl $0x4, %ecx
je 0x18837
cmpl $0x2, %ecx
je 0x18806
cmpl $0x1, %ecx
jne 0x188c3
movl 0xc(%rax), %eax
cmpl $0x3, %eax
je 0x18872
cmpl $0x5, %eax
je 0x18865
cmpl $0x4, %eax
je 0x1884d
leaq 0x15b82(%rip), %rdi     # 0x2e370
leaq 0x1944f(%rip), %rsi     # 0x31c44
leaq 0x19745(%rip), %rcx     # 0x31f41
movl $0x190, %edx            # imm = 0x190
callq 0xa0b0
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x18853
cmpl $0x4, %eax
je 0x18872
cmpl $0x3, %eax
je 0x1884d
leaq 0x15b51(%rip), %rdi     # 0x2e370
leaq 0x1941e(%rip), %rsi     # 0x31c44
leaq 0x19714(%rip), %rcx     # 0x31f41
movl $0x1a9, %edx            # imm = 0x1A9
callq 0xa0b0
movl 0xc(%rax), %eax
cmpl $0x5, %eax
je 0x18872
cmpl $0x4, %eax
je 0x1885c
cmpl $0x3, %eax
jne 0x188e2
movb $0x1, -0x6d(%rbp)
jmp 0x18872
leaq 0x19620(%rip), %rdx     # 0x31e7a
jmp 0x1886c
leaq 0x1971f(%rip), %rdx     # 0x31f82
jmp 0x1886c
leaq 0x195e4(%rip), %rdx     # 0x31e50
movq %r14, %rsi
callq *0x58(%rdi)
leaq -0x78(%rbp), %rsi
movq %rbx, %rdi
callq 0x17e70
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17e9a(%rip), %rdi     # 0x3072a
jmp 0x188ab
leaq 0x1dcc2(%rip), %rdi     # 0x3655b
jmp 0x188ab
leaq 0x193ff(%rip), %rdi     # 0x31ca1
jmp 0x188ab
leaq 0x19677(%rip), %rdi     # 0x31f22
leaq 0x19392(%rip), %rsi     # 0x31c44
leaq 0x19688(%rip), %rcx     # 0x31f41
movl $0x16e, %edx            # imm = 0x16E
callq 0xa0b0
leaq 0x15aa6(%rip), %rdi     # 0x2e370
leaq 0x19373(%rip), %rsi     # 0x31c44
leaq 0x19669(%rip), %rcx     # 0x31f41
movl $0x1c9, %edx            # imm = 0x1C9
callq 0xa0b0
leaq 0x15a87(%rip), %rdi     # 0x2e370
leaq 0x19354(%rip), %rsi     # 0x31c44
leaq 0x1964a(%rip), %rcx     # 0x31f41
movl $0x1c2, %edx            # imm = 0x1C2
callq 0xa0b0