// File: /workspace/github_c_makefile_star2_O2/rikuu[P]kermit/miniasm/asm.c
// Function: ma_sg_gen
asg_t *ma_sg_gen(const ma_opt_t *opt, const sdict_t *d, const ma_sub_t *sub, size_t n_hits, const ma_hit_t *hit)
{
	size_t i;
	asg_t *g;
	g = asg_init();
	for (i = 0; i < d->n_seq; ++i) {
		if (sub) asg_seq_set(g, i, sub[i].e - sub[i].s, (sub[i].del || d->seq[i].del));
		else asg_seq_set(g, i, d->seq[i].len, d->seq[i].del);
	}
	for (i = 0; i < n_hits; ++i) {
		int r;
		asg_arc_t t, *p;
		const ma_hit_t *h = &hit[i];
		uint32_t qn = h->qns>>32;
		int ql = sub? sub[qn].e - sub[qn].s : d->seq[qn].len;
		int tl = sub? sub[h->tn].e - sub[h->tn].s : d->seq[h->tn].len;
		r = ma_hit2arc(h, ql, tl, opt->max_hang, opt->int_frac, opt->min_ovlp, &t);
		if (r >= 0) {
			if (qn == h->tn) { // self match
				if ((uint32_t)h->qns == h->ts && h->qe == h->te && h->rev) // PacBio-specific artifact (TODO: is this right when we skip target containment above?)
					g->seq[qn].del = 1;
				continue;
			}
			p = asg_arc_pushp(g);
			*p = t;
		} else if (r == MA_HT_QCONT) g->seq[qn].del = 1;
	}
	asg_cleanup(g);
	fprintf(stderr, "[M::%s] read %d arcs\n", __func__, g->n_arc);
	return g;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
pushq $0xc
popq %rbp
xorl %ebx, %ebx
callq 0x2217
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r13
movq 0x18(%rsp), %rax
movl (%rax), %eax
cmpq %rax, %rbx
jae 0x4d8d
testq %r12, %r12
je 0x4d65
movl (%r12,%rbx,8), %eax
movl %r13d, %ecx
testl %eax, %eax
js 0x4d57
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movl (%rcx,%rbp), %ecx
shrl $0x1f, %ecx
movl 0x4(%r12,%rbx,8), %edx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
jmp 0x4d78
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movl -0x4(%rax,%rbp), %edx
movl (%rax,%rbp), %ecx
shrl $0x1f, %ecx
movq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x230a
incq %rbx
addq $0x10, %rbp
jmp 0x4d2c
addq $0x18, %r14
subq $0x1, %r15
jb 0x4f83
movq -0x18(%r14), %rcx
movq %rcx, %rax
shrq $0x20, %rax
testq %r12, %r12
je 0x4dd2
movl 0x4(%r12,%rax,8), %r13d
movl (%r12,%rax,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andl %edi, %edx
subl %edx, %r13d
movl -0xc(%r14), %edx
movl 0x4(%r12,%rdx,8), %r9d
movl (%r12,%rdx,8), %esi
andl %edi, %esi
subl %esi, %r9d
jmp 0x4df7
movq 0x18(%rsp), %rdx
movq 0x8(%rdx), %rsi
movq %rax, %rdx
shlq $0x4, %rdx
movl 0x8(%rsi,%rdx), %r13d
movl -0xc(%r14), %edx
movq %rdx, %rdi
shlq $0x4, %rdi
movl 0x8(%rsi,%rdi), %r9d
movq (%r14), %rsi
movq %rsi, 0x28(%rsp)
testl %esi, %esi
movq %rdx, 0x30(%rsp)
js 0x4e1f
movl -0x8(%r14), %edi
movl -0x4(%r14), %edx
movl %edx, 0xc(%rsp)
subl %edx, %r9d
movl %r9d, %r8d
movl %edi, %r9d
jmp 0x4e31
movl -0x8(%r14), %edi
movl -0x4(%r14), %edx
movl %edx, 0xc(%rsp)
subl %edx, %r9d
movl %edi, %r8d
movq 0x20(%rsp), %rsi
movl 0x10(%rsi), %esi
cmpl %ecx, %r9d
movl %ecx, %r11d
cmovll %r9d, %r11d
movl -0x10(%r14), %r10d
movl %r13d, %ebx
subl %r10d, %ebx
cmpl %r8d, %ebx
movl %r8d, %ebp
cmovbl %ebx, %ebp
cmpl %esi, %r11d
jg 0x4f7a
cmpl %esi, %ebp
jg 0x4f7a
movl %r10d, %esi
subl %ecx, %esi
cvtsi2ss %rsi, %xmm0
addl %r11d, %esi
addl %ebp, %esi
cvtsi2ss %rsi, %xmm1
movq 0x20(%rsp), %rdx
mulss 0x18(%rdx), %xmm1
ucomiss %xmm0, %xmm1
ja 0x4f7a
movq 0x20(%rsp), %rdx
movl 0x14(%rdx), %edx
cmpl %r9d, %ecx
jg 0x4eb5
cmpl %r8d, %ebx
ja 0x4eb5
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
orl $0x80000000, (%rcx,%rax,4) # imm = 0x80000000
jmp 0x4f7a
cmpl %r9d, %ecx
jl 0x4ec3
cmpl %r8d, %ebx
jae 0x4f7a
cmpl $0x0, 0x28(%rsp)
setns 0xb(%rsp)
addl %r10d, %r8d
movl %r13d, %ebx
subl %r8d, %ebx
movl %ecx, %r8d
subl %r9d, %r8d
setg 0xa(%rsp)
setle %r9b
cmovlel %ebx, %r8d
cmpl %edx, %esi
jb 0x4f7a
addl %r11d, %ebp
subl %edi, %ebp
addl 0xc(%rsp), %ebp
cmpl %edx, %ebp
jb 0x4f7a
testl %r8d, %r8d
js 0x4f2a
movq 0x30(%rsp), %rdx
cmpl %eax, %edx
jne 0x4f36
cmpl %ecx, %edi
jne 0x4f7a
movq 0x28(%rsp), %rcx
andl $0x80000000, %ecx       # imm = 0x80000000
je 0x4f7a
cmpl 0xc(%rsp), %r10d
je 0x4ea0
jmp 0x4f7a
cmpl $-0x2, %r8d
je 0x4ea0
jmp 0x4f7a
xorl %esi, %esi
movb %r9b, %sil
movb 0xb(%rsp), %al
xorb 0xa(%rsp), %al
movzbl %al, %eax
shrq $0x1f, %rcx
andl $-0x2, %ecx
orl %ecx, %esi
leal (%rax,%rdx,2), %ebx
shlq $0x20, %rsi
movl %r8d, %ebp
orq %rsi, %rbp
subl %r8d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x10(%rsp), %rdi
callq 0x4fc9
movq %rbp, (%rax)
movl %ebx, 0x8(%rax)
movl %r13d, 0xc(%rax)
addq $0x20, %r14
jmp 0x4d91
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x2447
movq 0x9061(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x4(%rbx), %ecx
leaq 0x4580(%rip), %rsi      # 0x9529
leaq 0x458f(%rip), %rdx      # 0x953f
xorl %eax, %eax
callq 0x1120
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq