// File: /workspace/github_c_makefile_star2_O2/rikuu[P]kermit/miniasm/asm.c
// Function: ma_ug_seq
int ma_ug_seq(ma_ug_t *g, const sdict_t *d, const ma_sub_t *sub, const char *fn)
{
	gzFile fp;
	kseq_t *ks;
	utg_intv_t *tmp;
	uint32_t i, j;

	fp = fn && strcmp(fn, "-")? gzopen(fn, "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) return -1;
	ks = kseq_init(fp);

	tmp = (utg_intv_t*)calloc(d->n_seq, sizeof(utg_intv_t));
	for (i = 0; i < g->u.n; ++i) {
		ma_utg_t *u = &g->u.a[i];
		uint32_t l = 0;
		u->s = (char*)calloc(1, u->len + 1);
		memset(u->s, 'N', u->len);
		for (j = 0; j < u->n; ++j) {
			utg_intv_t *t = &tmp[u->a[j]>>33];
			assert(t->len == 0);
			t->utg = i, t->ori = u->a[j]>>32&1;
			t->start = l, t->len = (uint32_t)u->a[j];
			l += t->len;
		}
	}

	while (kseq_read(ks) >= 0) {
		int32_t id;
		utg_intv_t *t;
		ma_utg_t *u;
		id = sd_get(d, ks->name.s);
		if (id < 0 || tmp[id].len == 0) continue;
		t = &tmp[id];
		u = &g->u.a[t->utg];
		if (sub) {
			assert(sub[id].e - sub[id].s <= ks->seq.l);
			memmove(ks->seq.s, ks->seq.s + sub[id].s, sub[id].e - sub[id].s);
			ks->seq.l = sub[id].e - sub[id].s;
		}
		if (!t->ori) { // forward strand
			for (i = 0; i < t->len; ++i)
				u->s[t->start + i] = ks->seq.s[i];
		} else {
			for (i = 0; i < t->len; ++i) {
				int c = (uint8_t)ks->seq.s[ks->seq.l - 1 - i];
				u->s[t->start + i] = c >= 128? 'N' : comp_tab[c];
			}
		}
	}
	free(tmp);

	kseq_destroy(ks);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, %r14
movq %rdi, 0x20(%rsp)
testq %rcx, %rcx
je 0x5c26
cmpb $0x2d, (%rcx)
jne 0x5c15
cmpb $0x0, 0x1(%rcx)
je 0x5c26
leaq 0x3440(%rip), %rsi      # 0x905c
movq %rcx, %rdi
callq 0x11a0
jmp 0x5c43
movq 0x839b(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
callq 0x1150
leaq 0x3420(%rip), %rsi      # 0x905c
movl %eax, %edi
callq 0x1080
movq %rax, %rbx
testq %rax, %rax
je 0x6100
pushq $0x1
popq %r12
pushq $0x70
popq %rsi
movq %r12, %rdi
callq 0x10f0
movq %rax, %r15
pushq $0x20
popq %rsi
movq %r12, %rdi
callq 0x10f0
movq %rax, %r12
movq %rbx, 0x30(%rsp)
movq %rbx, 0x10(%rax)
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x4000, %edi           # imm = 0x4000
callq 0x1160
movq %rax, 0x18(%r12)
movq %r15, (%rsp)
movq %r12, 0x18(%rsp)
movq %r12, 0x68(%r15)
movq %r14, 0x48(%rsp)
movl (%r14), %edi
pushq $0xc
popq %rsi
callq 0x10f0
movq %rax, %rbp
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movl %r15d, %r15d
cmpq %r15, 0x10(%rsp)
jbe 0x5d6b
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rbx
imulq $0x28, %r15, %r14
leaq (%rbx,%r14), %r13
movl (%rbx,%r14), %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
leaq 0x1(%r12), %rsi
pushq $0x1
popq %rdi
callq 0x10f0
movq %rax, 0x20(%rbx,%r14)
movq %rax, %rdi
pushq $0x4e
popq %rsi
movq %r12, %rdx
callq 0x10d0
movl 0x10(%rbx,%r14), %eax
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %rax
je 0x5d63
movq 0x18(%r13), %rdi
movq (%rdi,%rdx,8), %rdi
movq %rdi, %r8
shrq $0x21, %r8
imulq $0xc, %r8, %r8
cmpl $0x0, 0x8(%rbp,%r8)
jne 0x6112
addq %rbp, %r8
movq %rdi, %r9
shrq %r9
andl $0x80000000, %r9d       # imm = 0x80000000
orl %ecx, %r9d
movl %r9d, (%r8)
movl %esi, 0x4(%r8)
movl %edi, 0x8(%r8)
addl %edi, %esi
incq %rdx
jmp 0x5d1a
incl %r15d
jmp 0x5cbe
movq (%rsp), %rdx
leaq 0x48(%rdx), %rax
movq %rax, 0x50(%rsp)
leaq 0x30(%rdx), %rax
movq %rax, 0x10(%rsp)
leaq 0x18(%rdx), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq 0x18(%rsp), %rdi
testl %eax, %eax
movq %rdi, %r13
jne 0x5dbe
callq 0x6285
cmpl $-0x1, %eax
je 0x6098
cmpl $0x40, %eax
movq %r13, %rdi
je 0x5db3
cmpl $0x3e, %eax
jne 0x5d98
movl %eax, 0xc(%rsp)
movq (%rsp), %rdx
movl %eax, 0x60(%rdx)
andq $0x0, 0x48(%rdx)
andq $0x0, 0x30(%rdx)
andq $0x0, 0x18(%rdx)
xorl %esi, %esi
leaq 0xc(%rsp), %rcx
callq 0x62f8
testl %eax, %eax
js 0x6098
cmpl $0xa, 0xc(%rsp)
pushq $0x2
popq %r15
je 0x5dfe
movq %r13, %rdi
movl %r15d, %esi
movq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x62f8
movq (%rsp), %rbx
cmpq $0x0, 0x40(%rbx)
pushq $0x1
popq %r12
jne 0x5e23
movq $0x100, 0x38(%rbx)      # imm = 0x100
movl $0x100, %edi            # imm = 0x100
callq 0x1160
movq %rax, 0x40(%rbx)
movq %r13, %r14
movq %r14, %rdi
callq 0x6285
movl %eax, 0xc(%rsp)
cmpl $0xa, %eax
je 0x5e26
cmpl $-0x1, %eax
je 0x5e7b
cmpl $0x2b, %eax
je 0x5e7b
cmpl $0x3e, %eax
je 0x5e78
cmpl $0x40, %eax
je 0x5e78
movq 0x30(%rbx), %rcx
movq 0x40(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x30(%rbx)
movb %al, (%rdx,%rcx)
movq %r13, %r14
movq %r13, %rdi
movl %r15d, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
movl %r12d, %r8d
callq 0x62fd
jmp 0x5e26
movl %eax, 0x60(%rbx)
movq 0x30(%rbx), %r15
movq 0x38(%rbx), %r12
leaq 0x1(%r15), %rcx
movq 0x40(%rbx), %rax
cmpq %r12, %rcx
jb 0x5ed7
movq %rcx, %rdx
shrq %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x2, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x4, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x8, %rcx
orq %rdx, %rcx
movq %rcx, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r12, 0x38(%rbx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x1180
movq %rax, 0x40(%rbx)
movb $0x0, (%rax,%r15)
cmpl $0x2b, 0xc(%rsp)
jne 0x5f5e
movq (%rsp), %rbx
cmpq %r12, 0x50(%rbx)
jae 0x5f01
movq %r12, 0x50(%rbx)
movq 0x58(%rbx), %rdi
movq %r12, %rsi
callq 0x1180
movq %rax, 0x58(%rbx)
movq %r13, %rdi
callq 0x6285
movl %eax, 0xc(%rsp)
cmpl $-0x1, %eax
je 0x6098
cmpl $0xa, %eax
jne 0x5f01
pushq $0x2
popq %rbx
pushq $0x1
popq %r12
movq %r13, %rdi
movl %ebx, %esi
movq 0x50(%rsp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
movl %r12d, %r8d
callq 0x62fd
movq 0x10(%rsp), %rcx
movq (%rcx), %r15
movq (%r14), %rcx
testl %eax, %eax
js 0x5f4d
cmpq %r15, %rcx
jb 0x5f22
movq (%rsp), %rax
andl $0x0, 0x60(%rax)
cmpq %rcx, %r15
jne 0x6098
testl %r15d, %r15d
js 0x6098
movq (%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x48(%rsp), %rdi
callq 0x17a3
testl %eax, %eax
leaq 0x376e(%rip), %r9       # 0x96f0
js 0x6088
movl %eax, %r14d
imulq $0xc, %r14, %rsi
movl 0x8(%rbp,%rsi), %ebx
testq %rbx, %rbx
je 0x6088
addq %rbp, %rsi
movl (%rsi), %edx
movl %edx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
imulq $0x28, %rax, %r12
movq 0x20(%rsp), %rax
addq 0x10(%rax), %r12
movq 0x40(%rsp), %r13
testq %r13, %r13
je 0x6023
movq %rsi, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movl (%r13,%r14,8), %esi
movl 0x4(%r13,%r14,8), %edx
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
subl %esi, %edx
cmpq %rdx, %r15
jb 0x6131
movq (%rsp), %rax
movq 0x40(%rax), %rdi
addq %rdi, %rsi
callq 0x1190
movl 0x4(%r13,%r14,8), %r15d
movl (%r13,%r14,8), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
subl %eax, %r15d
movq (%rsp), %rax
movq %r15, 0x30(%rax)
leaq 0x36d9(%rip), %r9       # 0x96f0
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rsi
jmp 0x6027
movq (%rsp), %rax
movq 0x40(%rax), %rcx
testl %edx, %edx
js 0x604f
movl 0x4(%rsi), %eax
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x6088
movb (%rcx,%rdx), %sil
movq 0x20(%r12), %rdi
leal (%rax,%rdx), %r8d
movb %sil, (%rdi,%r8)
incq %rdx
jmp 0x6034
movl 0x4(%rsi), %eax
negq %rbx
addq %r15, %rcx
decq %rcx
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x6088
movsbq (%rcx,%rdx), %rsi
testq %rsi, %rsi
js 0x6072
movb (%rsi,%r9), %sil
jmp 0x6075
movb $0x4e, %sil
movq 0x20(%r12), %rdi
movl %eax, %r8d
movb %sil, (%rdi,%r8)
decq %rdx
incl %eax
jmp 0x605d
movq (%rsp), %rdx
movq 0x68(%rdx), %rdi
movl 0x60(%rdx), %eax
jmp 0x5d91
movq %rbp, %rdi
callq 0x1040
movq (%rsp), %r15
testq %r15, %r15
movq 0x30(%rsp), %r14
je 0x60f4
movq 0x10(%r15), %rdi
callq 0x1040
movq 0x28(%r15), %rdi
callq 0x1040
movq 0x40(%r15), %rdi
callq 0x1040
movq 0x58(%r15), %rdi
callq 0x1040
movq 0x68(%r15), %rbx
testq %rbx, %rbx
je 0x60ec
movq 0x18(%rbx), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x1040
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x6103
pushq $-0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x354e(%rip), %rdi      # 0x9667
leaq 0x3553(%rip), %rsi      # 0x9673
leaq 0x355a(%rip), %rcx      # 0x9681
movl $0xfb, %edx
callq 0x10c0
leaq 0x3593(%rip), %rdi      # 0x96cb
leaq 0x3534(%rip), %rsi      # 0x9673
leaq 0x353b(%rip), %rcx      # 0x9681
movl $0x10b, %edx            # imm = 0x10B
callq 0x10c0