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

	ParserASTNode *ins_node = data->ins_node;

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

	uint64_t addr = asm_parser_get_symbol_by_token_key(data->ctx, node_label->token);

	EncoderInstruction enc_ins;

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

	enc_ins.mod_rm_used = true;
	enc_ins.mod_rm.mod = 0x3;
	enc_ins.mod_rm.reg = ins->opcode_ext.reg;

	switch (ASM_PARSER_CONTEXT_DATA_GET_ARCH(data->ctx)) {
		case ASM_ARCH_BIT16: {
			enc_ins.disp_len = 2;
			break;
		}
		case ASM_ARCH_BIT32:
		case ASM_ARCH_BIT64: {
			enc_ins.disp_len = 4;
			break;
		}
		default: {
			assert(0);
			break;
		}
	}
	enc_ins.disp = 0;

	uint8_t buffer[32];
	size_t len = enc_ins_encode(&enc_ins, buffer, sizeof(buffer));

	uint64_t ip = ASM_PARSER_CONTEXT_DATA_GET_ADDRESS_COUNTER(data->ctx) + len;
	uint64_t offset = addr - ip;
	enc_ins.disp = offset;

	len = enc_ins_encode(&enc_ins, buffer, sizeof(buffer));

	ASM_PARSER_CONTEXT_DATA_INC_ADDRESS_COUNTER(data->ctx, len);
	if (ASM_PARSER_CONTEXT_DATA_GET_STEP(data->ctx) == ASM_STEP_SCAN) {
		return;
	}

	fwrite(buffer, len, 1, ASM_PARSER_CONTEXT_DATA_GET_OUT(data->ctx));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x21f4c
jmp 0x21f6b
leaq 0x27bb3(%rip), %rdi     # 0x49b06
leaq 0x290c6(%rip), %rsi     # 0x4b020
movl $0x550, %edx            # imm = 0x550
leaq 0x299d0(%rip), %rcx     # 0x4b936
callq 0xa0b0
cmpq $0x0, -0x10(%rbp)
je 0x21f74
jmp 0x21f93
leaq 0x2e074(%rip), %rdi     # 0x4ffef
leaq 0x2909e(%rip), %rsi     # 0x4b020
movl $0x550, %edx            # imm = 0x550
leaq 0x299a8(%rip), %rcx     # 0x4b936
callq 0xa0b0
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x21f9f
jmp 0x21fbe
leaq 0x290d7(%rip), %rdi     # 0x4b07d
leaq 0x29073(%rip), %rsi     # 0x4b020
movl $0x550, %edx            # imm = 0x550
leaq 0x2997d(%rip), %rcx     # 0x4b936
callq 0xa0b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x44(%rax)
jne 0x21fcd
jmp 0x21fec
leaq 0x2932a(%rip), %rdi     # 0x4b2fe
leaq 0x29045(%rip), %rsi     # 0x4b020
movl $0x550, %edx            # imm = 0x550
leaq 0x2994f(%rip), %rcx     # 0x4b936
callq 0xa0b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2a7f0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x88(%rbp), %rcx
callq 0x1a9e0
movb $0x1, -0x72(%rbp)
movb $0x3, -0x71(%rbp)
movq -0x8(%rbp), %rax
movb 0x22(%rax), %al
shrb $0x2, %al
andb $0x7, %al
movb %al, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0xb0(%rax), %eax
movl %eax, -0xcc(%rbp)
subl $0x1, %eax
je 0x22087
jmp 0x2206d
movl -0xcc(%rbp), %eax
subl $0x2, %eax
je 0x2208d
jmp 0x2207a
movl -0xcc(%rbp), %eax
subl $0x4, %eax
je 0x2208d
jmp 0x22093
movb $0x2, -0x6a(%rbp)
jmp 0x220b2
movb $0x4, -0x6a(%rbp)
jmp 0x220b2
leaq 0x253cb(%rip), %rdi     # 0x47465
leaq 0x28f7f(%rip), %rsi     # 0x4b020
movl $0x56b, %edx            # imm = 0x56B
leaq 0x29889(%rip), %rcx     # 0x4b936
callq 0xa0b0
movq $0x0, -0x68(%rbp)
leaq -0xb0(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movl $0x20, %edx
callq 0x19210
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0xc0(%rax), %rax
addq -0xb8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
subq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0xb0(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movl $0x20, %edx
callq 0x19210
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq 0xc0(%rax), %rcx
movq %rcx, 0xc0(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x1, 0xc8(%rax)
jne 0x22162
jmp 0x22189
leaq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0xb8(%rax), %rcx
movl $0x1, %edx
callq 0xa190
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)