// File: /workspace/github_c_makefile_star2_O3/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 0x18517
movq %rsi, %rbx
testq %rsi, %rsi
je 0x18520
movq (%rbx), %r12
testq %r12, %r12
je 0x18529
cmpl $0x2, 0x44(%r12)
jne 0x18532
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 0x8(%rbx), %rdi
movl 0xb0(%rdi), %ecx
movq 0x60(%r13), %rax
cmpl $0x4, %ecx
je 0x1847f
cmpl $0x2, %ecx
je 0x18448
cmpl $0x1, %ecx
jne 0x18551
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x184ec
cmpl $0x8900, %eax           # imm = 0x8900
je 0x184d4
cmpl $0x8800, %eax           # imm = 0x8800
jne 0x18570
leaq -0x88(%rbp), %rcx
jmp 0x184a6
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x184bc
cmpl $0x8900, %eax           # imm = 0x8900
je 0x184b3
cmpl $0x8800, %eax           # imm = 0x8800
je 0x1849b
leaq 0x15f09(%rip), %rdi     # 0x2e370
leaq 0x197d6(%rip), %rsi     # 0x31c44
leaq 0x1999a(%rip), %rcx     # 0x31e0f
movl $0xf6, %edx
callq 0xa0b0
movl 0x8(%rax), %eax
cmpl $0x8a00, %eax           # imm = 0x8A00
je 0x184c5
cmpl $0x8900, %eax           # imm = 0x8900
je 0x184b3
cmpl $0x8800, %eax           # imm = 0x8800
jne 0x1858f
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x15d47
jmp 0x184f9
leaq -0x88(%rbp), %rcx
jmp 0x184df
leaq 0x199b7(%rip), %rdx     # 0x31e7a
jmp 0x184f3
leaq -0x88(%rbp), %rcx
movw $0x101, 0xd(%rcx)       # imm = 0x101
jmp 0x184df
leaq -0x88(%rbp), %rcx
movb $0x1, 0xb(%rcx)
movq %r14, %rsi
movq %r15, %rdx
callq 0x15e3d
jmp 0x184f9
leaq 0x1995d(%rip), %rdx     # 0x31e50
movq %r12, %rsi
callq *0x58(%rdi)
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 0x1820c(%rip), %rdi     # 0x3072a
jmp 0x18539
leaq 0x1e034(%rip), %rdi     # 0x3655b
jmp 0x18539
leaq 0x19771(%rip), %rdi     # 0x31ca1
jmp 0x18539
leaq 0x19777(%rip), %rdi     # 0x31cb0
leaq 0x19704(%rip), %rsi     # 0x31c44
leaq 0x198c8(%rip), %rcx     # 0x31e0f
movl $0xb7, %edx
callq 0xa0b0
leaq 0x15e18(%rip), %rdi     # 0x2e370
leaq 0x196e5(%rip), %rsi     # 0x31c44
leaq 0x198a9(%rip), %rcx     # 0x31e0f
movl $0x115, %edx            # imm = 0x115
callq 0xa0b0
leaq 0x15df9(%rip), %rdi     # 0x2e370
leaq 0x196c6(%rip), %rsi     # 0x31c44
leaq 0x1988a(%rip), %rcx     # 0x31e0f
movl $0xdc, %edx
callq 0xa0b0
leaq 0x15dda(%rip), %rdi     # 0x2e370
leaq 0x196a7(%rip), %rsi     # 0x31c44
leaq 0x1986b(%rip), %rcx     # 0x31e0f
movl $0x10e, %edx            # imm = 0x10E
callq 0xa0b0