// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %r9d, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, %r15
movl %edx, 0x4c(%rsp)
movl %esi, %ebp
movq %rdi, %r14
callq 0x1c10
testq %rax, %rax
je 0x421a
movq %rax, %rbx
xorl %r14d, %r14d
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1e42
testl %eax, %eax
js 0x417f
movl 0x30(%rsp), %eax
subl 0x2c(%rsp), %eax
cmpl %ebp, %eax
jb 0x4177
movl 0x3c(%rsp), %eax
subl 0x38(%rsp), %eax
cmpl %ebp, %eax
jb 0x4177
movl 0x40(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
cmpl 0x4c(%rsp), %eax
jl 0x4177
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3f81
movq 0x18(%rsp), %rsi
callq 0x17a3
testl %eax, %eax
jns 0x4177
movq 0x20(%rsp), %rsi
movq 0x90(%rsp), %rdi
callq 0x17a3
testl %eax, %eax
jns 0x4177
cmpq 0x10(%rsp), %r14
jne 0x3faa
leaq (%r14,%r14), %rsi
testq %r14, %r14
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x10(%rsp)
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq %rax, %r12
leaq 0x1(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
shlq $0x5, %r14
movq 0x18(%rsp), %rsi
movl 0x28(%rsp), %edx
movq %r15, %rdi
callq 0x14fd
shlq $0x20, %rax
movl 0x2c(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r14)
movl 0x30(%rsp), %eax
movl %eax, 0x8(%r12,%r14)
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %edx
movq %r15, %rdi
callq 0x14fd
movl %eax, 0xc(%r12,%r14)
movq 0x38(%rsp), %rcx
movq %rcx, 0x10(%r12,%r14)
movl 0x40(%rsp), %ecx
andl $0x80000000, %ecx       # imm = 0x80000000
movq 0x18(%r12,%r14), %rdx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rdx
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%r14)
movl 0x40(%rsp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rdx      # imm = 0x80000000
orq %rcx, %rdx
movq %rdx, 0x18(%r12,%r14)
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,%r14)
cmpl $0x0, 0x48(%rsp)
je 0x4075
addq %r12, %r14
cmpl %eax, 0x4(%r14)
jne 0x407f
movq 0x8(%rsp), %r14
jmp 0x4177
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
cmpq %rax, %rcx
jne 0x40b8
leaq (%rax,%rax), %r14
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r14
movq %r14, %rsi
shlq $0x5, %rsi
movq %r12, %rdi
callq 0x1180
movq 0x8(%rsp), %rcx
movq %rax, %r12
movq %r14, 0x10(%rsp)
movq (%rsp), %rax
addq $0x2, %rax
movq %rax, (%rsp)
shlq $0x5, %rcx
movq 0x20(%rsp), %rsi
movl 0x34(%rsp), %edx
movq %r15, %rdi
movq %rcx, %r14
callq 0x14fd
shlq $0x20, %rax
movl 0x38(%rsp), %ecx
orq %rax, %rcx
movq %rcx, (%r12,%r14)
movl 0x3c(%rsp), %eax
movl %eax, 0x8(%r12,%r14)
movq 0x18(%rsp), %rsi
movl 0x28(%rsp), %edx
movq %r15, %rdi
callq 0x14fd
movl %eax, 0xc(%r12,%r14)
movq 0x2c(%rsp), %rax
movq %rax, 0x10(%r12,%r14)
movl 0x40(%rsp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
movq 0x18(%r12,%r14), %rcx
movabsq $-0x80000001, %rdx      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdx, %rcx
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r14)
movl 0x40(%rsp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rax, %rcx
movq %rcx, 0x18(%r12,%r14)
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,%r14)
movq (%rsp), %r14
incq %r13
jmp 0x3efe
movq %r14, %rbp
movq %rbx, %rdi
callq 0x1ca9
movl (%r15), %eax
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %r14d, %r14d
cmpq %rcx, %rax
je 0x41ac
movq 0x8(%r15), %rdx
movl 0x8(%rdx,%rcx), %edx
addq %rdx, %r14
addq $0x10, %rcx
jmp 0x4196
leaq 0x9f85(%rip), %rax      # 0xe138
cmpl $0x3, (%rax)
jge 0x41dd
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3c05
movq 0x50(%rsp), %rax
movq %rbp, (%rax)
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9e14(%rip), %rax      # 0xdff8
movq (%rax), %rbx
xorl %eax, %eax
callq 0x1412
movl (%r15), %r10d
leaq 0x5163(%rip), %rsi      # 0x935b
leaq 0x5150(%rip), %rdx      # 0x934f
movq %rbx, %rdi
movq %rax, %rcx
movq %r13, %r8
movq %rbp, %r9
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0x1120
popq %rcx
popq %rdx
jmp 0x41b8
movq 0x9dd7(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x50c9(%rip), %rsi      # 0x92f4
leaq 0x511d(%rip), %rdx      # 0x934f
movq %r14, %rcx
xorl %eax, %eax
callq 0x1120
pushq $0x1
popq %rdi
callq 0x1200