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

	ParserASTNode *ins_node = data->ins_node;

	ParserASTNode *oprd = ins_node->childs[0];

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

	int addr_size = ASM_DIRECT_ADDRESS_AST_NODE_GET_ADDR_SIZE(oprd);

	uint64_t base = ASM_DIRECT_ADDRESS_AST_NODE_GET_BASE(oprd);
	uint64_t offset = ASM_DIRECT_ADDRESS_AST_NODE_GET_OFFSET(oprd);

	switch (ASM_PARSER_CONTEXT_DATA_GET_ARCH(data->ctx)) {
		case ASM_ARCH_BIT16: {
			if (addr_size == ASM_MEM_ADDR_SIZE_UNKNOWN
					|| addr_size == ASM_MEM_ADDR_SIZE_16) {
				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) offset
				);

				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) base
				);
			} else if (addr_size == ASM_MEM_ADDR_SIZE_32) {
				enc_ins.legacy_prefix.operand_size_override = true;

				ins_add_uint32_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint32_t) offset
				);

				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) base
				);
			} else {
				assert(0);
			}
			break;
		}
		case ASM_ARCH_BIT32: {
			if (addr_size == ASM_MEM_ADDR_SIZE_16) {
				enc_ins.legacy_prefix.operand_size_override = true;

				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) offset
				);

				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) base
				);
			} else if (addr_size == ASM_MEM_ADDR_SIZE_32
					|| addr_size == ASM_MEM_ADDR_SIZE_UNKNOWN) {
				ins_add_uint32_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint32_t) offset
				);

				ins_add_uint16_to_ext(
					data->ctx,
					ins,
					&enc_ins,
					(uint16_t) base
				);
			} else {
				assert(0);
			}
			break;
		}
		case ASM_ARCH_BIT64: {
			data->ctx->syntax_error_node_msg(
				data->ctx,
				ins_node,
				"instruction not supported in 64-bit mode."
			);
			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 0x1b4e2
movq %rsi, %rbx
testq %rsi, %rsi
je 0x1b4eb
movq (%rbx), %r15
testq %r15, %r15
je 0x1b4f4
cmpl $0x1, 0x44(%r15)
jne 0x1b4fd
movq %rdi, %r14
movq 0x48(%r15), %rax
movq (%rax), %r12
movq 0x8(%rbx), %rdi
leaq -0x88(%rbp), %rcx
movq %r14, %rsi
movq %r15, %rdx
callq 0x1524f
movq 0x8(%rbx), %rdi
movl 0xb0(%rdi), %edx
cmpl $0x4, %edx
je 0x1b46d
movl 0x60(%r12), %eax
movq 0x70(%r12), %r15
movq 0x80(%r12), %rcx
cmpl $0x2, %edx
je 0x1b435
cmpl $0x1, %edx
jne 0x1b51c
cmpl $0x1, %eax
ja 0x1b490
movl $0xffff, %r13d          # imm = 0xFFFF
andl %r13d, %ecx
leaq -0x88(%rbp), %r12
jmp 0x1b450
cmpl $0x1, %eax
jne 0x1b47c
leaq -0x88(%rbp), %r12
movb $0x1, 0xb(%r12)
movl $0xffff, %r13d          # imm = 0xFFFF
andl %r13d, %ecx
movq %r14, %rsi
movq %r12, %rdx
callq 0x160ce
movq 0x8(%rbx), %rdi
andl %r13d, %r15d
movq %r14, %rsi
movq %r12, %rdx
movl %r15d, %ecx
jmp 0x1b4bf
leaq 0x16b0e(%rip), %rdx     # 0x31f82
movq %r15, %rsi
callq *0x58(%rdi)
jmp 0x1b4c4
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x1b53b
leaq -0x88(%rbp), %r12
jmp 0x1b4a6
cmpl $0x2, %eax
jne 0x1b55a
leaq -0x88(%rbp), %r12
movb $0x1, 0xb(%r12)
movq %r14, %rsi
movq %r12, %rdx
callq 0x1611c
movq 0x8(%rbx), %rdi
movzwl %r15w, %ecx
movq %r14, %rsi
movq %r12, %rdx
callq 0x160ce
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 0x15241(%rip), %rdi     # 0x3072a
jmp 0x1b504
leaq 0x1b069(%rip), %rdi     # 0x3655b
jmp 0x1b504
leaq 0x167a6(%rip), %rdi     # 0x31ca1
jmp 0x1b504
leaq 0x16a1e(%rip), %rdi     # 0x31f22
leaq 0x16739(%rip), %rsi     # 0x31c44
leaq 0x1764f(%rip), %rcx     # 0x32b61
movl $0x837, %edx            # imm = 0x837
callq 0xa0b0
leaq 0x12e4d(%rip), %rdi     # 0x2e370
leaq 0x1671a(%rip), %rsi     # 0x31c44
leaq 0x17630(%rip), %rcx     # 0x32b61
movl $0x89a, %edx            # imm = 0x89A
callq 0xa0b0
leaq 0x12e2e(%rip), %rdi     # 0x2e370
leaq 0x166fb(%rip), %rsi     # 0x31c44
leaq 0x17611(%rip), %rcx     # 0x32b61
movl $0x88d, %edx            # imm = 0x88D
callq 0xa0b0
leaq 0x12e0f(%rip), %rdi     # 0x2e370
leaq 0x166dc(%rip), %rsi     # 0x31c44
leaq 0x175f2(%rip), %rcx     # 0x32b61
movl $0x868, %edx            # imm = 0x868
callq 0xa0b0