// File: /workspace/github_c_makefile_star2_O3/rikuu[P]kermit/miniasm/hit.c
// Function: ma_hit_read
ma_hit_t *ma_hit_read(const char *fn, int min_span, int min_match, sdict_t *d, size_t *n, int bi_dir, const sdict_t *excl)
{
	paf_file_t *fp;
	paf_rec_t r;
	ma_hit_v h = {0,0,0};
	size_t i, tot = 0, tot_len = 0;

	fp = paf_open(fn);
	if (!fp) {
		fprintf(stderr, "[E::%s] could not open PAF file %s\n", __func__, fn);
		exit(1);
	}
	while (paf_read(fp, &r) >= 0) {
		ma_hit_t *p;
		++tot;
		if (r.qe - r.qs < min_span || r.te - r.ts < min_span || r.ml < min_match) continue;
		if (excl && (sd_get(excl, r.qn) >= 0 || sd_get(excl, r.tn) >= 0)) continue;
		kv_pushp(ma_hit_t, h, &p);
		p->qns = (uint64_t)sd_put(d, r.qn, r.ql)<<32 | r.qs;
		p->qe = r.qe;
		p->tn = sd_put(d, r.tn, r.tl);
		p->ts = r.ts, p->te = r.te, p->rev = r.rev, p->ml = r.ml, p->bl = r.bl;
		if (bi_dir && p->qns>>32 != p->tn) {
			kv_pushp(ma_hit_t, h, &p);
			p->qns = (uint64_t)sd_put(d, r.tn, r.tl)<<32 | r.ts;
			p->qe = r.te;
			p->tn = sd_put(d, r.qn, r.ql);
			p->ts = r.qs, p->te = r.qe, p->rev = r.rev, p->ml = r.ml, p->bl = r.bl;
		}
	}
	paf_close(fp);
	for (i = 0; i < d->n_seq; ++i)
		tot_len += d->seq[i].len;
	if (ma_verbose >= 3) fprintf(stderr, "[M::%s::%s] read %ld hits; stored %ld hits and %d sequences (%ld bp)\n", __func__, sys_timestamp(), tot, h.n, d->n_seq, tot_len);
	ma_hit_sort(h.n, h.a);
	*n = h.n;
	return h.a;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x54(%rsp)
movq %r8, %r15
movq %rcx, 0x48(%rsp)
movl %edx, 0x4(%rsp)
movl %esi, %r14d
movq %rdi, %rbx
callq 0x3850
testq %rax, %rax
je 0x59a7
movq %rax, %rbp
movq %r15, 0x60(%rsp)
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x3a85
testl %eax, %eax
js 0x58eb
xorl %r13d, %r13d
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movl 0x4(%rsp), %r15d
movl 0x30(%rsp), %eax
subl 0x2c(%rsp), %eax
cmpl %r14d, %eax
jb 0x58d1
movl 0x3c(%rsp), %eax
subl 0x38(%rsp), %eax
cmpl %r14d, %eax
jb 0x58d1
movl 0x40(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %r15d, %eax
jl 0x58d1
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x56bb
movq 0x18(%rsp), %rsi
callq 0x336b
testl %eax, %eax
jns 0x58d1
movq 0x20(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x336b
testl %eax, %eax
jns 0x58d1
movq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x56ec
leaq (%rax,%rax), %r15
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r15
movq %r15, %rsi
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq %rax, %r12
movq %r15, 0x10(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
movq %rbx, 0x8(%rsp)
movq %rbx, %r15
shlq $0x5, %r15
movq 0x18(%rsp), %rsi
movl 0x28(%rsp), %edx
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x3091
shlq $0x20, %rax
movl 0x2c(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r15)
movl 0x30(%rsp), %eax
movl %eax, 0x8(%r12,%r15)
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %edx
movq %rbx, %rdi
callq 0x3091
movl %eax, 0xc(%r12,%r15)
movq 0x38(%rsp), %rcx
movq %rcx, 0x10(%r12,%r15)
movl 0x40(%rsp), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
movq 0x18(%r12,%r15), %rdx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rdx
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%r15)
movl 0x40(%rsp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rdx      # imm = 0x80000000
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%r15)
movl 0x44(%rsp), %ecx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %ecx
shlq $0x20, %rcx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rdx
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%r15)
cmpl $0x0, 0x54(%rsp)
je 0x58c7
movq 0x58(%rsp), %rbx
addq %r12, %r15
cmpl %eax, 0x4(%r15)
je 0x58cc
movq 0x10(%rsp), %rax
cmpq %rax, %rbx
jne 0x57fe
leaq (%rax,%rax), %r15
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r15
movq %r15, %rsi
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq %rax, %r12
movq %r15, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x8(%rsp)
shlq $0x5, %rbx
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %edx
movq %rbx, %r15
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x3091
shlq $0x20, %rax
movl 0x38(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r15)
movl 0x3c(%rsp), %eax
movl %eax, 0x8(%r12,%r15)
movq 0x18(%rsp), %rsi
movl 0x28(%rsp), %edx
movq %rbx, %rdi
movq 0x8(%rsp), %rbx
callq 0x3091
movl %eax, 0xc(%r12,%r15)
movq 0x2c(%rsp), %rax
movq %rax, 0x10(%r12,%r15)
movl 0x40(%rsp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
movq 0x18(%r12,%r15), %rcx
movabsq $-0x80000001, %rdx      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdx, %rcx
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r15)
movl 0x40(%rsp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r15)
movl 0x44(%rsp), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
shlq $0x20, %rax
movabsq $-0x7fffffff00000001, %rdx # imm = 0x80000000FFFFFFFF
andq %rdx, %rcx
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r15)
jmp 0x58cc
movq 0x58(%rsp), %rbx
movl 0x4(%rsp), %r15d
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3a85
incq %r13
testl %eax, %eax
jns 0x564c
jmp 0x58f3
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x38e0
movq 0x48(%rsp), %r15
movl (%r15), %eax
testq %rax, %rax
je 0x5927
movq 0x8(%r15), %rcx
shlq $0x4, %rax
xorl %edx, %edx
xorl %r14d, %r14d
movl 0x8(%rcx,%rdx), %esi
addq %rsi, %r14
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x5915
jmp 0x592a
xorl %r14d, %r14d
leaq 0x8807(%rip), %rax      # 0xe138
cmpl $0x3, (%rax)
jge 0x5962
movq %rbx, %rsi
shlq $0x5, %rsi
addq %r12, %rsi
movq %r12, %rdi
callq 0x5036
movq 0x60(%rsp), %rax
movq %rbx, (%rax)
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x868f(%rip), %rax      # 0xdff8
movq %rbx, %rbp
movq (%rax), %rbx
xorl %eax, %eax
callq 0x2f44
movl (%r15), %r10d
leaq 0x49db(%rip), %rsi      # 0xa35b
leaq 0x49c8(%rip), %rdx      # 0xa34f
movq %rbx, %rdi
movq %rbp, %rbx
movq %rax, %rcx
movq %r13, %r8
movq %rbp, %r9
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0x1120
addq $0x10, %rsp
jmp 0x5936
movq %rbx, %rdi
callq 0x1c4a