// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdi, 0x20(%rsp)
callq 0x3e60
movq %rbx, %rsi
movq %rax, 0x8(%rsp)
cmpl $0x0, (%rbx)
je 0x1dc4
pushq $0xc
popq %r13
xorl %ebx, %ebx
testq %r12, %r12
je 0x1d93
movl (%r12,%rbx,8), %eax
pushq $0x1
popq %rcx
testl %eax, %eax
js 0x1d85
movq 0x8(%rsi), %rcx
movl (%rcx,%r13), %ecx
shrl $0x1f, %ecx
movl 0x4(%r12,%rbx,8), %edx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
jmp 0x1da3
movq 0x8(%rsi), %rax
movl -0x4(%rax,%r13), %edx
movl (%rax,%r13), %ecx
shrl $0x1f, %ecx
movq 0x8(%rsp), %rdi
movq %rsi, %rbp
movl %ebx, %esi
callq 0x3f77
incq %rbx
movl (%rbp), %eax
addq $0x10, %r13
cmpq %rax, %rbx
movq %rbp, %rsi
jb 0x1d6a
testq %r15, %r15
je 0x204f
addq $0x18, %r14
movq %rsi, 0x28(%rsp)
movq -0x18(%r14), %rbp
movq %rbp, %rax
shrq $0x20, %rax
testq %r12, %r12
je 0x1e0b
movl 0x4(%r12,%rax,8), %ebx
movl (%r12,%rax,8), %ecx
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %ecx
subl %ecx, %ebx
movl -0xc(%r14), %r8d
movl 0x4(%r12,%r8,8), %edi
movl (%r12,%r8,8), %ecx
andl %edx, %ecx
subl %ecx, %edi
jmp 0x1e29
movq 0x8(%rsi), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movl 0x8(%rcx,%rdx), %ebx
movl -0xc(%r14), %r8d
movq %r8, %rdx
shlq $0x4, %rdx
movl 0x8(%rcx,%rdx), %edi
movq (%r14), %rcx
movq %rcx, 0x18(%rsp)
testl %ecx, %ecx
movq %r8, 0x30(%rsp)
js 0x1e4b
movl -0x8(%r14), %esi
movl -0x4(%r14), %edx
subl %edx, %edi
movl %edi, %r10d
movl %esi, %edi
jmp 0x1e58
movl -0x8(%r14), %esi
movl -0x4(%r14), %edx
subl %edx, %edi
movl %esi, %r10d
movq 0x20(%rsp), %r8
movl 0x10(%r8), %r13d
cmpl %ebp, %edi
movl %ebp, %r9d
cmovll %edi, %r9d
movl -0x10(%r14), %r8d
movl %ebx, 0x14(%rsp)
subl %r8d, %ebx
cmpl %r10d, %ebx
movl %r10d, %r11d
cmovbl %ebx, %r11d
cmpl %r13d, %r9d
jg 0x203d
cmpl %r13d, %r11d
jg 0x203d
movl %r8d, %r13d
subl %ebp, %r13d
cvtsi2ss %r13, %xmm0
addl %r9d, %r13d
addl %r11d, %r13d
cvtsi2ss %r13, %xmm1
movq 0x20(%rsp), %rcx
mulss 0x18(%rcx), %xmm1
ucomiss %xmm0, %xmm1
ja 0x203d
movq 0x20(%rsp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x4(%rsp)
cmpl %edi, %ebp
jg 0x1ee4
cmpl %r10d, %ebx
ja 0x1ee4
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
orl $0x80000000, (%rcx,%rax,4) # imm = 0x80000000
jmp 0x203d
cmpl %edi, %ebp
jl 0x1ef1
cmpl %r10d, %ebx
jae 0x203d
cmpl $0x0, 0x18(%rsp)
setns %cl
addl %r8d, %r10d
movl 0x14(%rsp), %ebx
subl %r10d, %ebx
movl %ebp, %r10d
subl %edi, %r10d
setg %dil
setle 0x3(%rsp)
cmovlel %ebx, %r10d
cmpl 0x4(%rsp), %r13d
jb 0x203d
addl %r9d, %r11d
subl %esi, %r11d
addl %edx, %r11d
cmpl 0x4(%rsp), %r11d
jb 0x203d
testl %r10d, %r10d
js 0x1f6b
movq 0x30(%rsp), %r13
cmpl %eax, %r13d
jne 0x1f7a
cmpl %ebp, %esi
jne 0x203d
movq 0x18(%rsp), %rcx
andl $0x80000000, %ecx       # imm = 0x80000000
je 0x203d
cmpl %edx, %r8d
je 0x1ecf
jmp 0x203d
cmpl $-0x2, %r10d
je 0x1ecf
jmp 0x203d
movb %cl, 0x18(%rsp)
movq 0x8(%rsp), %rbx
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl (%rbx), %ecx
jne 0x1fd1
leal (%rcx,%rcx), %esi
testl %ecx, %ecx
pushq $0x10
popq %rax
cmovel %eax, %esi
movl %esi, (%rbx)
movb %dil, 0x2(%rsp)
movq 0x8(%rbx), %rdi
shlq $0x4, %rsi
movl %r10d, 0x4(%rsp)
callq 0x1180
movb 0x2(%rsp), %dil
movl 0x4(%rsp), %r10d
movq %rax, 0x8(%rbx)
movl 0x4(%rbx), %edx
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0x1fd5
movq 0x8(%rbx), %rax
xorl %r8d, %r8d
movb 0x3(%rsp), %sil
movb %sil, %r8b
movb 0x18(%rsp), %sil
xorb %dil, %sil
movzbl %sil, %esi
shrq $0x1f, %rbp
andl $-0x2, %ebp
orl %ebp, %r8d
leal (%rsi,%r13,2), %esi
shlq $0x20, %r8
movl %r10d, %edi
orq %r8, %rdi
movl 0x14(%rsp), %r9d
subl %r10d, %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
leal 0x1(%rdx), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orl %r8d, %edx
movl %edx, 0x4(%rbx)
movl %ecx, %ecx
shlq $0x4, %rcx
movq %rdi, (%rax,%rcx)
movl %esi, 0x8(%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
addq $0x20, %r14
decq %r15
movq 0x28(%rsp), %rsi
jne 0x1dd6
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x40c7
movq 0xbf95(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x4(%rbx), %ecx
leaq 0x84b4(%rip), %rsi      # 0xa529
leaq 0x84c3(%rip), %rdx      # 0xa53f
xorl %eax, %eax
callq 0x1120
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq