// File: /workspace/github_c_makefile_star2_O1/lh3[P]fermi-lite/misc.c
// Function: fml_fmi_gen
struct rld_t *fml_fmi_gen(int n, bseq1_t *seq, int is_mt)
{
	mrope_t *mr;
	kstring_t str = {0,0,0};
	mritr_t itr;
	rlditr_t di;
	const uint8_t *block;
	rld_t *e = 0;
	int k;

	for (k = 0; k < n; ++k)
		if (seq[k].l_seq > 0)
			break;
	if (k == n) return 0;

	mr = mr_init(ROPE_DEF_MAX_NODES, ROPE_DEF_BLOCK_LEN, MR_SO_RCLO);
	for (k = 0; k < n; ++k) {
		int i;
		bseq1_t *s = &seq[k];
		if (s->l_seq == 0) continue;
		free(s->qual);
		for (i = 0; i < s->l_seq; ++i)
			s->seq[i] = seq_nt6_table[(int)s->seq[i]];
		for (i = 0; i < s->l_seq; ++i)
			if (s->seq[i] == 5) break;
		if (i < s->l_seq) {
			free(s->seq);
			continue;
		}
		if (is_rev_same(s->l_seq, s->seq))
			--s->l_seq, s->seq[s->l_seq] = 0;
		seq_reverse(s->l_seq, (uint8_t*)s->seq);
		kputsn(s->seq, s->l_seq + 1, &str);
		seq_revcomp6(s->l_seq, (uint8_t*)s->seq);
		kputsn(s->seq, s->l_seq + 1, &str);
		free(s->seq);
	}
	free(seq);
	mr_insert_multi(mr, str.l, (uint8_t*)str.s, is_mt);
	free(str.s);

	e = rld_init(6, 3);
	rld_itr_init(e, &di, 0);
	mr_itr_first(mr, &itr, 1);
	while ((block = mr_itr_next_block(&itr)) != 0) {
		const uint8_t *q = block + 2, *end = block + 2 + *rle_nptr(block);
		while (q < end) {
			int c = 0;
			int64_t l;
			rle_dec1(q, c, l);
			rld_enc(e, &di, l, c);
		}
	}
	rld_enc_finish(e, &di);

	mr_destroy(mr);
	return e;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movl %edi, %ebp
movl %edi, %ebx
testl %edi, %edi
movq %rsi, 0x18(%rsp)
jle 0x2852
xorl %eax, %eax
movq %rsi, %rcx
cmpl $0x0, (%rcx)
jg 0x2854
incq %rax
addq $0x18, %rcx
cmpq %rax, %rbx
jne 0x283d
movl %ebx, %eax
jmp 0x2854
xorl %eax, %eax
cmpl %ebp, %eax
jne 0x2860
xorl %r14d, %r14d
jmp 0x2c28
movl %edx, 0x24(%rsp)
movl $0x40, %edi
movl $0x200, %esi            # imm = 0x200
movl $0x2, %edx
callq 0x7578
movq %rax, 0x28(%rsp)
testl %ebp, %ebp
jle 0x2acf
xorl %r14d, %r14d
leaq 0x1a8e1(%rip), %r12     # 0x1d170
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rbp
movq %rbx, 0x38(%rsp)
leaq (%r14,%r14,2), %rax
cmpl $0x0, (%rbp,%rax,8)
je 0x2ac1
leaq (,%rax,8), %rbx
addq %rbp, %rbx
movq 0x10(%rbx), %rdi
callq 0x2040
movl (%rbx), %eax
testl %eax, %eax
jle 0x28f4
xorl %ecx, %ecx
movq 0x8(%rbx), %rax
movsbq (%rax,%rcx), %rdx
movb (%rdx,%r12), %dl
movb %dl, (%rax,%rcx)
incq %rcx
movslq (%rbx), %rax
cmpq %rax, %rcx
jl 0x28d9
testl %eax, %eax
setg %dl
jle 0x2932
movq 0x8(%rbx), %rcx
cmpb $0x5, (%rcx)
je 0x2925
movl %eax, %edx
leaq -0x1(%rdx), %rsi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x2932
leaq 0x1(%rdi), %r8
cmpb $0x5, 0x1(%rcx,%rdi)
movq %r8, %rdi
jne 0x290c
cmpq %rdx, %r8
setb %dl
testb %dl, %dl
je 0x2932
addq $0x8, %rbx
jmp 0x2ab4
testb $0x1, %al
jne 0x297e
movq 0x8(%rbx), %rcx
movl %eax, %edx
sarl %edx
testl %edx, %edx
jle 0x296b
leal -0x1(%rax), %edi
xorl %esi, %esi
movsbl (%rcx,%rsi), %r8d
movslq %edi, %r9
movsbl (%rcx,%r9), %r9d
addl %r8d, %r9d
cmpl $0x5, %r9d
jne 0x296d
incq %rsi
decl %edi
cmpq %rsi, %rdx
jne 0x2947
movl %edx, %esi
jmp 0x296d
xorl %esi, %esi
cmpl %edx, %esi
jne 0x297e
cltq
leaq -0x1(%rax), %rdx
movl %edx, (%rbx)
movb $0x0, -0x1(%rcx,%rax)
movl (%rbx), %edi
movq 0x8(%rbx), %rsi
callq 0x41db
movq 0x8(%rbx), %rsi
movslq (%rbx), %rbp
movq 0x10(%rsp), %rax
addq %rbp, %rax
addq $0x2, %rax
cmpq %r15, %rax
jae 0x29a8
movq 0x8(%rsp), %r12
jmp 0x29f2
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %r15
shrq $0x10, %r15
orq %rax, %r15
incq %r15
movq 0x8(%rsp), %rdi
movq %rsi, %r12
movq %r15, %rsi
callq 0x21d0
movq %r12, %rsi
movq %rax, %r12
incq %rbp
movq 0x10(%rsp), %r13
leaq (%r12,%r13), %rdi
movq %rbp, %rdx
callq 0x2180
addq %r13, %rbp
movb $0x0, (%r12,%rbp)
movl (%rbx), %edi
movq 0x8(%rbx), %rsi
callq 0x4205
movq 0x8(%rbx), %rsi
movslq (%rbx), %rax
movq %rax, %r13
addq %rbp, %rax
addq $0x2, %rax
movq %r15, 0x30(%rsp)
cmpq %r15, %rax
jb 0x2a7e
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rsi, %r15
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %r12, %rdi
movq %rsi, 0x30(%rsp)
callq 0x21d0
movq %r15, %rsi
movq %rax, %r12
addq $0x8, %rbx
incq %r13
leaq (%r12,%rbp), %rdi
movq %r13, %rdx
callq 0x2180
addq %rbp, %r13
movq %r12, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movb $0x0, (%r12,%r13)
movq 0x18(%rsp), %rbp
movq 0x30(%rsp), %r15
leaq 0x1a6bc(%rip), %r12     # 0x1d170
movq (%rbx), %rdi
callq 0x2040
movq 0x38(%rsp), %rbx
incq %r14
cmpq %rbx, %r14
jne 0x28ae
jmp 0x2ae6
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x2040
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movl 0x24(%rsp), %ecx
callq 0x7aae
movq %rbx, %rdi
callq 0x2040
movl $0x6, %edi
movl $0x3, %esi
callq 0x84a4
movq %rax, %r14
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x8663
leaq 0x78(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x7a06
movq %rbx, %rdi
callq 0x7a20
testq %rax, %rax
je 0x2c11
movq %rax, %r12
leaq 0x78(%rsp), %r15
leaq 0x40(%rsp), %r13
movzwl (%r12), %eax
testq %rax, %rax
je 0x2bfd
leaq (%rax,%r12), %rbx
addq $0x2, %rbx
addq $0x2, %r12
movzbl (%r12), %eax
testb %al, %al
js 0x2baa
incq %r12
movl %eax, %edx
shrl $0x3, %edx
andb $0x7, %al
movzbl %al, %ecx
movq %r14, %rdi
movq %r13, %rsi
callq 0x86de
cmpq %rbx, %r12
jb 0x2b82
jmp 0x2bfd
movl %eax, %ecx
andl $-0x20, %ecx
cmpl $0xc0, %ecx
jne 0x2bcf
movl %eax, %ecx
andl $0x18, %ecx
movzbl 0x1(%r12), %edx
andl $0x3f, %edx
leaq (%rdx,%rcx,8), %rdx
addq $0x2, %r12
jmp 0x2b93
movl %eax, %ecx
shrl $0x2, %ecx
andl $0x4, %ecx
movl %eax, %edx
shrl $0x3, %edx
andl $0x1, %edx
incq %r12
xorl $-0x3, %ecx
shlq $0x6, %rdx
movzbl (%r12), %esi
andl $0x3f, %esi
orq %rsi, %rdx
incq %r12
incl %ecx
jne 0x2be5
jmp 0x2b93
movq %r15, %rdi
callq 0x7a20
movq %rax, %r12
testq %rax, %rax
jne 0x2b68
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x8cd3
movq 0x28(%rsp), %rdi
callq 0x75ef
movq %r14, %rax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq