// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/assembler/ins.c
// Function: ins_fill_GX
void ins_fill_GX(
	ParserContext *ctx,
	Instruction *ins,
	ParserASTNode *node,
	EncoderInstruction *enc_ins
) {
	assert(ctx);
	assert(ins);
	assert(node);
	assert(node->type == ASM_NODE_REG);
	assert(enc_ins);

	int arch = ASM_PARSER_CONTEXT_DATA_GET_ARCH(ctx);

	InsRegister *ins_reg = ASM_REG_AST_NODE_GET_REG(node);
	assert(ins_reg);

	enc_ins->mod_rm.reg = ins_reg->index & 0x7;	// 0x7 == 0b0111

	if (ins_reg->index & 0x08) {	// 0x8 == 0b1000
		enc_ins->rex_prefix_used = true;
		enc_ins->rex_prefix.r = true;
	}

	if (arch == ASM_ARCH_BIT16) {
		// Operand size
		if (ins_reg->type == INS_REGISTER_GENERAL_4BYTE) {
			enc_ins->legacy_prefix.operand_size_override = true;
		}
	} else if (arch == ASM_ARCH_BIT32) {
		// Operand size
		if (ins_reg->type == INS_REGISTER_GENERAL_2BYTE) {
			enc_ins->legacy_prefix.operand_size_override = true;
		}
	} else if (arch == ASM_ARCH_BIT64) {
		// Operand size
		if (ins->superscript | INS_SS_d64) {
			if (ins_reg->type == INS_REGISTER_GENERAL_2BYTE) {
				enc_ins->legacy_prefix.operand_size_override = true;
			}
		} else {
			if (ins_reg->type == INS_REGISTER_GENERAL_2BYTE) {
				enc_ins->legacy_prefix.operand_size_override = true;
			} else if (ins_reg->type == INS_REGISTER_GENERAL_8BYTE) {
				enc_ins->rex_prefix_used = true;
				enc_ins->rex_prefix.w = true;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1ab61
jmp 0x1ab80
leaq 0x32ff9(%rip), %rdi     # 0x4db61
leaq 0x2ed8d(%rip), %rsi     # 0x498fc
movl $0x2d4, %edx            # imm = 0x2D4
leaq 0x2ef8f(%rip), %rcx     # 0x49b0a
callq 0xa0b0
cmpq $0x0, -0x10(%rbp)
je 0x1ab89
jmp 0x1aba8
leaq 0x2ef76(%rip), %rdi     # 0x49b06
leaq 0x2ed65(%rip), %rsi     # 0x498fc
movl $0x2d5, %edx            # imm = 0x2D5
leaq 0x2ef67(%rip), %rcx     # 0x49b0a
callq 0xa0b0
cmpq $0x0, -0x18(%rbp)
je 0x1abb1
jmp 0x1abd0
leaq 0x304cf(%rip), %rdi     # 0x4b087
leaq 0x2ed3d(%rip), %rsi     # 0x498fc
movl $0x2d6, %edx            # imm = 0x2D6
leaq 0x2ef3f(%rip), %rcx     # 0x49b0a
callq 0xa0b0
movq -0x18(%rbp), %rax
cmpl $0x500, (%rax)          # imm = 0x500
jne 0x1abde
jmp 0x1abfd
leaq 0x2ef7d(%rip), %rdi     # 0x49b62
leaq 0x2ed10(%rip), %rsi     # 0x498fc
movl $0x2d7, %edx            # imm = 0x2D7
leaq 0x2ef12(%rip), %rcx     # 0x49b0a
callq 0xa0b0
cmpq $0x0, -0x20(%rbp)
je 0x1ac06
jmp 0x1ac25
leaq 0x2eef5(%rip), %rdi     # 0x49b02
leaq 0x2ece8(%rip), %rsi     # 0x498fc
movl $0x2d8, %edx            # imm = 0x2D8
leaq 0x2eeea(%rip), %rcx     # 0x49b0a
callq 0xa0b0
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1ac47
jmp 0x1ac66
leaq 0x2ef2f(%rip), %rdi     # 0x49b7d
leaq 0x2eca7(%rip), %rsi     # 0x498fc
movl $0x2dd, %edx            # imm = 0x2DD
leaq 0x2eea9(%rip), %rcx     # 0x49b0a
callq 0xa0b0
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x7, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x1ac98
movq -0x20(%rbp), %rax
movb $0x1, 0xd(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0xf(%rax)
cmpl $0x1, -0x24(%rbp)
jne 0x1acb2
movq -0x30(%rbp), %rax
cmpl $0x4, 0xc(%rax)
jne 0x1acb0
movq -0x20(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0x1ad2d
cmpl $0x2, -0x24(%rbp)
jne 0x1accc
movq -0x30(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jne 0x1acca
movq -0x20(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0x1ad2b
cmpl $0x4, -0x24(%rbp)
jne 0x1ad29
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
orl $0x20, %eax
cmpl $0x0, %eax
je 0x1acf5
movq -0x30(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jne 0x1acf3
movq -0x20(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0x1ad27
movq -0x30(%rbp), %rax
cmpl $0x3, 0xc(%rax)
jne 0x1ad09
movq -0x20(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0x1ad25
movq -0x30(%rbp), %rax
cmpl $0x5, 0xc(%rax)
jne 0x1ad23
movq -0x20(%rbp), %rax
movb $0x1, 0xd(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0xe(%rax)
jmp 0x1ad25
jmp 0x1ad27
jmp 0x1ad29
jmp 0x1ad2b
jmp 0x1ad2d
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)