// File: chhylp123[P]hifiasm/inter.cpp
// Function: write_ul_hits(mg_gres_a*, mg_dbn_t*, char const*)
void write_ul_hits(mg_gres_a *hits, mg_dbn_t *nn, const char *fn)
{
	char *buf = (char*)calloc(strlen(fn) + 25, 1);
    sprintf(buf, "%s.ul.aln.bin", fn);
    FILE* fp = fopen(buf, "w");
	uint32_t i;

    fwrite(&hits->n, sizeof(hits->n), 1, fp);
	for (i = 0; i < hits->n; i++) {
		fwrite(&hits->a[i].qid, sizeof(hits->a[i].qid), 1, fp);
		fwrite(&hits->a[i].qlen, sizeof(hits->a[i].qlen), 1, fp);
		fwrite(&hits->a[i].n_gc, sizeof(hits->a[i].n_gc), 1, fp);
		fwrite(&hits->a[i].n_lc, sizeof(hits->a[i].n_lc), 1, fp);
		fwrite(hits->a[i].gc, sizeof(mg_gchain_t), hits->a[i].n_gc, fp);
		fwrite(hits->a[i].lc, sizeof(mg_lres_t), hits->a[i].n_lc, fp);
	}
    // fwrite(hits->a, sizeof(mg_gres_t), hits->n, fp);
	fwrite(&hits->total_pair, sizeof(hits->total_pair), 1, fp);
	fwrite(&hits->total_base, sizeof(hits->total_base), 1, fp);

	fwrite(&(nn->n), sizeof(nn->n), 1, fp);
	fwrite(nn->a, sizeof(uint64_t), nn->n, fp);
	fwrite(&(nn->tl), sizeof(nn->tl), 1, fp);
	fwrite(&(nn->cc.n), sizeof(nn->cc.n), 1, fp);
	fwrite(nn->cc.a, sizeof(char), nn->cc.n, fp);
    // write_dbug(ug, fp);

    fclose(fp);
	fprintf(stderr, "[M::%s::] ==> UL alignments have been written\n", __func__);
    free(buf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x19, %rdi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xa0a9c(%rip), %rsi     # 0x3950bd
movb $0x0, %al
callq 0x2050
movq -0x20(%rbp), %rdi
leaq 0xa4d9f(%rip), %rsi     # 0x3993d2
callq 0x2200
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2f478b
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x2c(%rbp), %eax
imulq $0x28, %rax, %rax
addq %rax, %rdi
addq $0x4, %rdi
movq -0x28(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x48, %esi
callq 0x2400
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x1c, %esi
callq 0x2400
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2f465a
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x8, %esi
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x2400
movq -0x28(%rbp), %rdi
callq 0x21a0
movq 0xcf787(%rip), %rax     # 0x3c3fe0
movq (%rax), %rdi
leaq 0xa0868(%rip), %rsi     # 0x3950cb
leaq 0xa0890(%rip), %rdx     # 0x3950fa
movb $0x0, %al
callq 0x22a0
movq -0x20(%rbp), %rdi
callq 0x2210
addq $0x30, %rsp
popq %rbp
retq