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

	ParserASTNode *ins_node = data->ins_node;

	ParserASTNode *node_label = data->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);

	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 0x24ccc
jmp 0x24ceb
leaq 0x24e33(%rip), %rdi     # 0x49b06
leaq 0x26346(%rip), %rsi     # 0x4b020
movl $0x95f, %edx            # imm = 0x95F
leaq 0x273ca(%rip), %rcx     # 0x4c0b0
callq 0xa0b0
cmpq $0x0, -0x10(%rbp)
je 0x24cf4
jmp 0x24d13
leaq 0x2b2f4(%rip), %rdi     # 0x4ffef
leaq 0x2631e(%rip), %rsi     # 0x4b020
movl $0x95f, %edx            # imm = 0x95F
leaq 0x273a2(%rip), %rcx     # 0x4c0b0
callq 0xa0b0
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x24d1f
jmp 0x24d3e
leaq 0x26357(%rip), %rdi     # 0x4b07d
leaq 0x262f3(%rip), %rsi     # 0x4b020
movl $0x95f, %edx            # imm = 0x95F
leaq 0x27377(%rip), %rcx     # 0x4c0b0
callq 0xa0b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, 0x44(%rax)
jne 0x24d4d
jmp 0x24d6c
leaq 0x265aa(%rip), %rdi     # 0x4b2fe
leaq 0x262c5(%rip), %rsi     # 0x4b020
movl $0x95f, %edx            # imm = 0x95F
leaq 0x27349(%rip), %rcx     # 0x4c0b0
callq 0xa0b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %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
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0xb0(%rax), %eax
movl %eax, -0xcc(%rbp)
subl $0x1, %eax
je 0x24df3
jmp 0x24dd9
movl -0xcc(%rbp), %eax
subl $0x2, %eax
je 0x24df9
jmp 0x24de6
movl -0xcc(%rbp), %eax
subl $0x4, %eax
je 0x24df9
jmp 0x24dff
movb $0x2, -0x6a(%rbp)
jmp 0x24e1e
movb $0x4, -0x6a(%rbp)
jmp 0x24e1e
leaq 0x2265f(%rip), %rdi     # 0x47465
leaq 0x26213(%rip), %rsi     # 0x4b020
movl $0x976, %edx            # imm = 0x976
leaq 0x27297(%rip), %rcx     # 0x4c0b0
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 0x24ece
jmp 0x24ef5
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
nop