// File: /workspace/github_c_makefile_star2_O2/Ihsoh[P]ilang/compiler/assembler/ins_enc.c
// Function: ins_enc_XXX_rAX_Iz
void ins_enc_XXX_rAX_Iz(
	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);

	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->id) {
				case INS_AM_AX: {
					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_EAX: {
					enc_ins.legacy_prefix.operand_size_override = true;
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_RAX: {
					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->id) {
				case INS_AM_AX: {
					enc_ins.legacy_prefix.operand_size_override = true;
					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_EAX: {
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_RAX: {
					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->id) {
				case INS_AM_AX: {
					enc_ins.legacy_prefix.operand_size_override = true;
					ins_fill_imm16(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_EAX: {
					ins_fill_imm32(data->ctx, ins, source, &enc_ins);
					break;
				}
				case INS_AM_RAX: {
					enc_ins.rex_prefix_used = true;
					enc_ins.rex_prefix.w = 1;
					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 0x1781b
movq %rsi, %rbx
testq %rsi, %rsi
je 0x17824
movq (%rbx), %r12
testq %r12, %r12
je 0x1782d
cmpl $0x2, 0x44(%r12)
jne 0x17836
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 0x1470f
movq 0x8(%rbx), %rdi
movl 0xb0(%rdi), %ecx
movq 0x60(%r13), %rax
cmpl $0x4, %ecx
je 0x17783
cmpl $0x2, %ecx
je 0x1774c
cmpl $0x1, %ecx
jne 0x17855
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x177f0
cmpl $0x8900, %eax           # imm = 0x8900
je 0x177d8
cmpl $0x8800, %eax           # imm = 0x8800
jne 0x17874
leaq -0x88(%rbp), %rcx
jmp 0x177aa
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x177c0
cmpl $0x8900, %eax           # imm = 0x8900
je 0x177b7
cmpl $0x8800, %eax           # imm = 0x8800
je 0x1779f
leaq 0x15c05(%rip), %rdi     # 0x2d370
leaq 0x194e2(%rip), %rsi     # 0x30c54
leaq 0x196a6(%rip), %rcx     # 0x30e1f
movl $0xf6, %edx
callq 0xa0b0
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x177c9
cmpl $0x8900, %eax           # imm = 0x8900
je 0x177b7
cmpl $0x8800, %eax           # imm = 0x8800
jne 0x17893
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x151f8
jmp 0x177fd
leaq -0x88(%rbp), %rcx
jmp 0x177e3
leaq 0x196c3(%rip), %rdx     # 0x30e8a
jmp 0x177f7
leaq -0x88(%rbp), %rcx
movw $0x101, 0xd(%rcx)       # imm = 0x101
jmp 0x177e3
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x152ee
jmp 0x177fd
leaq 0x19669(%rip), %rdx     # 0x30e60
movq %r12, %rsi
callq *0x58(%rdi)
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0x17180
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17f18(%rip), %rdi     # 0x2f73a
jmp 0x1783d
leaq 0x1ddc0(%rip), %rdi     # 0x355eb
jmp 0x1783d
leaq 0x1947d(%rip), %rdi     # 0x30cb1
jmp 0x1783d
leaq 0x19483(%rip), %rdi     # 0x30cc0
leaq 0x19410(%rip), %rsi     # 0x30c54
leaq 0x195d4(%rip), %rcx     # 0x30e1f
movl $0xb7, %edx
callq 0xa0b0
leaq 0x15b14(%rip), %rdi     # 0x2d370
leaq 0x193f1(%rip), %rsi     # 0x30c54
leaq 0x195b5(%rip), %rcx     # 0x30e1f
movl $0x115, %edx            # imm = 0x115
callq 0xa0b0
leaq 0x15af5(%rip), %rdi     # 0x2d370
leaq 0x193d2(%rip), %rsi     # 0x30c54
leaq 0x19596(%rip), %rcx     # 0x30e1f
movl $0xdc, %edx
callq 0xa0b0
leaq 0x15ad6(%rip), %rdi     # 0x2d370
leaq 0x193b3(%rip), %rsi     # 0x30c54
leaq 0x19577(%rip), %rcx     # 0x30e1f
movl $0x10e, %edx            # imm = 0x10E
callq 0xa0b0