// File: /workspace/github_c_makefile_star2_O1/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, 0x5c(%rsp)
movq %r8, %r15
movq %rcx, 0x50(%rsp)
movl %edx, 0x4(%rsp)
movl %esi, %r14d
movq %rdi, %rbx
callq 0x394c
testq %rax, %rax
je 0x5c34
movq %rax, %rbp
movq %r15, 0x60(%rsp)
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x3b99
testl %eax, %eax
js 0x5b78
xorl %r13d, %r13d
xorl %r12d, %r12d
movq $0x0, 0x48(%rsp)
xorl %ebx, %ebx
movl 0x4(%rsp), %r15d
movl 0x20(%rsp), %eax
subl 0x1c(%rsp), %eax
cmpl %r14d, %eax
jb 0x5b5e
movl 0x2c(%rsp), %eax
subl 0x28(%rsp), %eax
cmpl %r14d, %eax
jb 0x5b5e
movl 0x30(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl %r15d, %eax
jl 0x5b5e
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x592a
movq 0x8(%rsp), %rsi
callq 0x3428
testl %eax, %eax
jns 0x5b5e
movq 0x10(%rsp), %rsi
movq 0xa0(%rsp), %rdi
callq 0x3428
testl %eax, %eax
jns 0x5b5e
movq 0x48(%rsp), %rax
cmpq %rax, %rbx
jne 0x5961
movq %rbx, %r15
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
movq %rbx, %rsi
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq %rax, %r12
movq %rbx, 0x48(%rsp)
movq %r15, %rbx
leaq 0x1(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
shlq $0x5, %rbx
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %edx
movq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x3171
shlq $0x20, %rax
movl 0x1c(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%rbx)
movl 0x20(%rsp), %eax
movl %eax, 0x8(%r12,%rbx)
movq 0x10(%rsp), %rsi
movl 0x24(%rsp), %edx
movq %r15, %rdi
callq 0x3171
movl %eax, 0xc(%r12,%rbx)
movl 0x28(%rsp), %ecx
movl %ecx, 0x10(%r12,%rbx)
movl 0x2c(%rsp), %ecx
movl %ecx, 0x14(%r12,%rbx)
movl 0x30(%rsp), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
movq 0x18(%r12,%rbx), %rdx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rdx
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%rbx)
movl 0x30(%rsp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rdx      # imm = 0x80000000
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%rbx)
movl 0x34(%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,%rbx)
cmpl $0x0, 0x5c(%rsp)
je 0x5a48
addq %r12, %rbx
cmpl %eax, 0x4(%rbx)
movl 0x4(%rsp), %r15d
jne 0x5a52
movq 0x40(%rsp), %rbx
jmp 0x5b5e
movq 0x40(%rsp), %rbx
jmp 0x5b59
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %r15
cmpq %rax, %r15
jne 0x5a8d
leaq (%rax,%rax), %rbx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rbx
movq %rbx, %rsi
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq 0x40(%rsp), %r15
movq %rax, %r12
movq %rbx, 0x48(%rsp)
movq 0x38(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x38(%rsp)
shlq $0x5, %r15
movq 0x10(%rsp), %rsi
movl 0x24(%rsp), %edx
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x3171
shlq $0x20, %rax
movl 0x28(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r15)
movl 0x2c(%rsp), %eax
movl %eax, 0x8(%r12,%r15)
movq 0x8(%rsp), %rsi
movl 0x18(%rsp), %edx
movq %rbx, %rdi
movq 0x38(%rsp), %rbx
callq 0x3171
movl %eax, 0xc(%r12,%r15)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%r12,%r15)
movl 0x20(%rsp), %eax
movl %eax, 0x14(%r12,%r15)
movl 0x30(%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 0x30(%rsp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r15)
movl 0x34(%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)
movl 0x4(%rsp), %r15d
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3b99
incq %r13
testl %eax, %eax
jns 0x58bb
jmp 0x5b80
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x39ef
movq 0x50(%rsp), %r15
movl (%r15), %eax
testq %rax, %rax
je 0x5bb4
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 0x5ba2
jmp 0x5bb7
xorl %r14d, %r14d
leaq 0x957a(%rip), %rax      # 0xf138
cmpl $0x3, (%rax)
jge 0x5bef
movq %rbx, %rsi
shlq $0x5, %rsi
addq %r12, %rsi
movq %r12, %rdi
callq 0x52b5
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 0x9402(%rip), %rax      # 0xeff8
movq %rbx, %rbp
movq (%rax), %rbx
xorl %eax, %eax
callq 0x3024
movl (%r15), %r10d
leaq 0x477e(%rip), %rsi      # 0xa38b
leaq 0x476b(%rip), %rdx      # 0xa37f
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 0x5bc3
movq %rbx, %rdi
callq 0x1c2f