// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
callq 0x3f78
movq %rbx, %r8
movq %rax, %rbx
cmpl $0x0, (%r8)
je 0x1daf
pushq $0xc
popq %r13
xorl %ebp, %ebp
movq %rbx, 0x8(%rsp)
testq %r12, %r12
je 0x1d7c
movl (%r12,%rbp,8), %eax
pushq $0x1
popq %rcx
testl %eax, %eax
js 0x1d6e
movq 0x8(%r8), %rcx
movl (%rcx,%r13), %ecx
shrl $0x1f, %ecx
movl 0x4(%r12,%rbp,8), %edx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
jmp 0x1d8c
movq 0x8(%r8), %rax
movl -0x4(%rax,%r13), %edx
movl (%rax,%r13), %ecx
shrl $0x1f, %ecx
movq %rbx, %rdi
movl %ebp, %esi
movq %r8, %rbx
callq 0x4074
incq %rbp
movl (%rbx), %eax
addq $0x10, %r13
cmpq %rax, %rbp
movq %rbx, %r8
movq 0x8(%rsp), %rbx
jb 0x1d53
testq %r15, %r15
jne 0x1df5
movq %rbx, %rdi
callq 0x41c9
movq 0xd235(%rip), %rax      # 0xeff8
movq (%rax), %rdi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x4(%rbx), %ecx
leaq 0x8784(%rip), %rsi      # 0xa559
leaq 0x8793(%rip), %rdx      # 0xa56f
xorl %eax, %eax
callq 0x1120
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x18, %r14
movq %r8, 0x10(%rsp)
movq -0x18(%r14), %rcx
movq %rcx, %rax
shrq $0x20, %rax
testq %r12, %r12
je 0x1e23
movl 0x4(%r12,%rax,8), %r13d
movl (%r12,%rax,8), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
subl %edx, %r13d
jmp 0x1e33
movq 0x8(%r8), %rdx
movq %rax, %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %r13d
testq %r12, %r12
je 0x1e51
movl -0xc(%r14), %edx
movl 0x4(%r12,%rdx,8), %r8d
movl (%r12,%rdx,8), %edx
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %edx
subl %edx, %r8d
jmp 0x1e62
movq 0x8(%r8), %rdx
movl -0xc(%r14), %esi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %r8d
movq (%r14), %rdx
testl %edx, %edx
js 0x1e79
movl -0x8(%r14), %esi
subl -0x4(%r14), %r8d
movl %r8d, %r11d
movl %esi, %r8d
jmp 0x1e81
subl -0x4(%r14), %r8d
movl -0x8(%r14), %r11d
movq 0x18(%rsp), %rsi
movl 0x10(%rsi), %ebp
cmpl %ecx, %r8d
movl %ecx, %r10d
cmovll %r8d, %r10d
movl -0x10(%r14), %esi
movl %r13d, %edi
subl %esi, %edi
cmpl %r11d, %edi
movl %r11d, %r9d
cmovbl %edi, %r9d
cmpl %ebp, %r10d
jg 0x1edc
cmpl %ebp, %r9d
jg 0x1edc
movq %rdx, 0x8(%rsp)
movl %esi, %ebp
subl %ecx, %ebp
cvtsi2ss %rbp, %xmm0
addl %r9d, %ebp
addl %r10d, %ebp
cvtsi2ss %rbp, %xmm1
movq 0x18(%rsp), %rdx
mulss 0x18(%rdx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x1ee2
pushq $-0x1
jmp 0x1ef9
pushq $-0x1
popq %r10
jmp 0x1f00
movl 0x14(%rdx), %edx
cmpl %r8d, %ecx
jg 0x1fce
cmpl %r11d, %edi
ja 0x1fce
pushq $-0x2
popq %r10
movq 0x8(%rsp), %rdx
testl %r10d, %r10d
js 0x1f2d
cmpl %eax, -0xc(%r14)
jne 0x1f49
cmpl %ecx, -0x8(%r14)
movq 0x10(%rsp), %r8
jne 0x1fbc
testl %edx, %edx
jns 0x1fbc
cmpl -0x4(%r14), %esi
je 0x1f3c
jmp 0x1fbc
cmpl $-0x2, %r10d
movq 0x10(%rsp), %r8
jne 0x1fbc
movq 0x18(%rbx), %rcx
orl $0x80000000, (%rcx,%rax,4) # imm = 0x80000000
jmp 0x1fbc
movl 0x4(%rbx), %ecx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1f77
leal (%rax,%rax), %esi
testl %eax, %eax
pushq $0x10
popq %rax
cmovel %eax, %esi
movl %esi, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x4, %rsi
callq 0x1180
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movl %ecx, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
shlq $0x4, %rdx
movq 0x30(%rsp), %rcx
movq %rcx, (%rax,%rdx)
movl 0x2c(%rsp), %ecx
movl %ecx, 0x8(%rax,%rdx)
movl 0x28(%rsp), %ecx
movl %ecx, 0xc(%rax,%rdx)
movq 0x10(%rsp), %r8
addq $0x20, %r14
decq %r15
jne 0x1dfe
jmp 0x1db4
movl %edx, 0x24(%rsp)
cmpl %r8d, %ecx
movq 0x8(%rsp), %rdx
jl 0x1fe8
cmpl %r11d, %edi
jb 0x1fe8
pushq $-0x3
jmp 0x1ede
testl %edx, %edx
setns 0x7(%rsp)
addl %esi, %r11d
movl %r13d, %edi
subl %r11d, %edi
movl %ecx, %r11d
subl %r8d, %r11d
setg 0x6(%rsp)
setle %r8b
cmovlel %edi, %r11d
movl 0x24(%rsp), %edi
cmpl %edi, %ebp
jae 0x201a
pushq $-0x4
jmp 0x1ede
addl %r10d, %r9d
addl -0x4(%r14), %r9d
subl -0x8(%r14), %r9d
pushq $-0x4
popq %r10
cmpl %edi, %r9d
jb 0x1f00
xorl %r9d, %r9d
movb %r8b, %r9b
movb 0x7(%rsp), %dl
xorb 0x6(%rsp), %dl
movzbl %dl, %edi
movq %rcx, %r8
shrq $0x1f, %r8
andl $-0x2, %r8d
orl %r8d, %r9d
movl -0xc(%r14), %r8d
leal (%rdi,%r8,2), %edx
movl %edx, 0x2c(%rsp)
shlq $0x20, %r9
movl %r11d, %edx
orq %r9, %rdx
movq %rdx, 0x30(%rsp)
movq 0x8(%rsp), %rdx
subl %r11d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl %r13d, 0x28(%rsp)
movl %r11d, %r10d
jmp 0x1f00