// File: chhylp123[P]hifiasm/inter.cpp
// Function: write_all_ul_t(all_ul_t*, char*, ma_ug_t*)
int32_t write_all_ul_t(all_ul_t *x, char* file_name, ma_ug_t *ug)
{
	char* gfa_name = NULL; MALLOC(gfa_name, strlen(file_name)+50);
	sprintf(gfa_name, "%s.ul.ovlp.bin", file_name);
	FILE* fp = fopen(gfa_name, "w"); free(gfa_name);
	if (!fp) return 0;
	uint64_t k; ul_vec_t *p = NULL;

	if(ug) write_dbug(ug, fp);

	fwrite(&x->nid.n, sizeof(x->nid.n), 1, fp);
	for (k = 0; k < x->nid.n; k++) {
		fwrite(&x->nid.a[k].n, sizeof(x->nid.a[k].n), 1, fp);
		fwrite(x->nid.a[k].a, sizeof((*(x->nid.a[k].a))), x->nid.a[k].n, fp);
	}

	fwrite(&x->ridx.idx.n, sizeof(x->ridx.idx.n), 1, fp);
	fwrite(x->ridx.idx.a, sizeof((*(x->ridx.idx.a))), x->ridx.idx.n, fp);

	fwrite(&x->ridx.occ.n, sizeof(x->ridx.occ.n), 1, fp);
	fwrite(x->ridx.occ.a, sizeof((*(x->ridx.occ.a))), x->ridx.occ.n, fp);

	fwrite(&x->n, sizeof(x->n), 1, fp);
	for (k = 0; k < x->n; k++) {
		p = &(x->a[k]);
		fwrite(&p->dd, sizeof(p->dd), 1, fp);
		fwrite(&p->rlen, sizeof(p->rlen), 1, fp);

		fwrite(&p->r_base.n, sizeof(p->r_base.n), 1, fp);
		fwrite(p->r_base.a, sizeof((*(p->r_base.a))), p->r_base.n, fp);

		fwrite(&p->bb.n, sizeof(p->bb.n), 1, fp);
		fwrite(p->bb.a, sizeof((*(p->bb.a))), p->bb.n, fp);

		fwrite(&p->N_site.n, sizeof(p->N_site.n), 1, fp);
		fwrite(p->N_site.a, sizeof((*(p->N_site.a))), p->N_site.n, fp);
	}

	fprintf(stderr, "[M::%s] Index has been written.\n", __func__);
	fclose(fp);
	if(asm_opt.bin_only) exit(0);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, %rdi
addq $0x32, %rdi
shlq $0x0, %rdi
callq 0x2270
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x9d21e(%rip), %rsi     # 0x39a7f6
movb $0x0, %al
callq 0x2050
movq -0x28(%rbp), %rdi
leaq 0x9bde8(%rip), %rsi     # 0x3993d2
callq 0x2200
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x30(%rbp)
jne 0x2fd60f
movl $0x0, -0x4(%rbp)
jmp 0x2fd8c2
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2fd62b
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1018e0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x2fd6ce
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %edx
movq -0x30(%rbp), %rcx
movl $0x1, %esi
callq 0x2400
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2fd64a
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x4, %esi
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
addq $0x18, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x8, %esi
callq 0x2400
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jae 0x2fd87c
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
imulq $0x58, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
addq $0x50, %rdi
movq -0x30(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x2400
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movq -0x30(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2400
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %esi
callq 0x2400
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x24, %esi
callq 0x2400
movq -0x40(%rbp), %rdi
addq $0x38, %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2400
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x30(%rbp), %rcx
movl $0x4, %esi
callq 0x2400
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2fd767
movq 0xc675d(%rip), %rax     # 0x3c3fe0
movq (%rax), %rdi
leaq 0x8d5b5(%rip), %rsi     # 0x38ae42
leaq 0x97c39(%rip), %rdx     # 0x3954cd
movb $0x0, %al
callq 0x22a0
movq -0x30(%rbp), %rdi
callq 0x21a0
leaq 0xc6f4d(%rip), %rax     # 0x3c47f8
cmpb $0x0, 0x24e(%rax)
je 0x2fd8bb
xorl %edi, %edi
callq 0x2240
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)