// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi2/match.c
// Function: main_match
int main_match(int argc, char *argv[])
{
	int i, c, use_mmap = 0, batch_size = 10000000, l_seqs;
	gzFile fp;
	char *fn_sa = 0;
	kseq_t *ks;
	global_t g;

	memset(&g, 0, sizeof(global_t));
	g.max_sa_occ = 10, g.min_occ = 1, g.n_threads = 1, g.kmer = 61, g.min_len = 0;
	while ((c = getopt(argc, argv, "Mdps:m:n:b:t:k:l:")) >= 0) {
		if (c == 'M') use_mmap = 1;
		else if (c == 's') fn_sa = optarg;
		else if (c == 'l') g.min_len = atoi(optarg);
		else if (c == 'm') g.max_sa_occ = atoi(optarg);
		else if (c == 'p') g.partial = 1;
		else if (c == 'd') g.discovery = g.partial = 1;
		else if (c == 'n') g.min_occ = atoi(optarg);
		else if (c == 't') g.n_threads = atoi(optarg);
		else if (c == 'k') g.kmer = atoi(optarg), g.discovery = g.partial = 1;
		else if (c == 'b') batch_size = atoi(optarg);
	}

	if (optind + 2 > argc) {
		fprintf(stderr, "Usage: fermi2 match [options] <index.fmd> <seq.fa>\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  -p        find SMEMs (reqiring both strands in one index)\n");
		fprintf(stderr, "  -d        discovery novel alleles (force -p; experimental)\n");
		fprintf(stderr, "  -k INT    k-mer length in the discovery mode (force -d) [%d]\n", g.kmer);
		fprintf(stderr, "  -t INT    number of threads [%d]\n", g.n_threads);
		fprintf(stderr, "  -b INT    batch size [%d]\n", batch_size);
		fprintf(stderr, "  -s FILE   sampled suffix array []\n");
		fprintf(stderr, "  -m INT    show coordinate if the number of hits is no more than INT [%d]\n", g.max_sa_occ);
		fprintf(stderr, "  -n INT    min occurrences [%d]\n", g.min_occ);
		fprintf(stderr, "  -l INT    min length [%d]\n", g.min_len);
		fprintf(stderr, "Output format:\n");
		fprintf(stderr, "    SQ  seqName seqLen\n");
		fprintf(stderr, "    EM  start   end     occurrence [positions]\n");
//		fprintf(stderr, "    NS  start   leftLen  diffLen  rightLen  leftOcc  rightOcc  strand  seq  qual\n");
//		fprintf(stderr, "  At an 'NS' line, the length of 'seq' always equals leftLen+diffLen+rightLen.\n");
		return 1;
	}

	fp = gzopen(argv[optind+1], "r");
	if (fp == 0) {
		fprintf(stderr, "[E::%s] failed to open the sequence file\n", __func__);
		return 1;
	}
	g.e = use_mmap? rld_restore_mmap(argv[optind]) : rld_restore(argv[optind]);
	if (g.e == 0) {
		fprintf(stderr, "[E::%s] failed to open the index file\n", __func__);
		gzclose(fp);
		return 1;
	}
	if (g.partial && (g.e->mcnt[2] != g.e->mcnt[5] || g.e->mcnt[3] != g.e->mcnt[4])) {
		fprintf(stderr, "[E::%s] with '-p', the index must include both strands\n", __func__);
		rld_destroy((rld_t*)g.e);
		gzclose(fp);
		return 1;
	}
	if (fn_sa) g.sa = fm_sa_restore(fn_sa);
	if (fn_sa && g.sa == 0) {
		fprintf(stderr, "[E::%s] failed to open the sampled SA file\n", __func__);
		rld_destroy((rld_t*)g.e);
		gzclose(fp);
		return 1;
	}

	g.mem = calloc(g.n_threads, sizeof(thrmem_t));

	batch_size *= g.n_threads;
	ks = kseq_init(fp);
	l_seqs = 0;
	while (kseq_read(ks) >= 0) {
		if (g.n_seqs == g.m_seqs) {
			g.m_seqs = g.m_seqs? g.m_seqs<<1 : 4;
			g.name = realloc(g.name, g.m_seqs * sizeof(char*));
			g.seq  = realloc(g.seq,  g.m_seqs * sizeof(char*));
			g.qual = realloc(g.qual, g.m_seqs * sizeof(char*));
			g.out  = realloc(g.out,  g.m_seqs * sizeof(char*));
		}
		g.name[g.n_seqs] = strdup(ks->name.s);
		g.seq[g.n_seqs]  = strdup(ks->seq.s);
		g.qual[g.n_seqs] = ks->qual.l? strdup(ks->qual.s) : 0; // these will be free'd in worker
		++g.n_seqs;
		l_seqs += ks->seq.l;
		if (l_seqs >= batch_size) {
			kt_for(g.n_threads, worker, &g, g.n_seqs);
			for (i = 0; i < g.n_seqs; ++i) {
				puts(g.out[i]);
				free(g.out[i]);
			}
			g.n_seqs = l_seqs = 0;
		}
	}
	// the last batch
	kt_for(g.n_threads, worker, &g, g.n_seqs);
	for (i = 0; i < g.n_seqs; ++i) {
		puts(g.out[i]);
		free(g.out[i]);
	}
	kseq_destroy(ks);

	for (i = 0; i < g.n_threads; ++i) {
		free(g.mem[i].curr.a); free(g.mem[i].prev.a); free(g.mem[i].smem.a);
		free(g.mem[i].cmp[0].s); free(g.mem[i].cmp[1].s); free(g.mem[i].str.s);
	}
	free(g.name); free(g.seq); free(g.qual); free(g.out); free(g.mem);
	if (g.sa) fm_sa_destroy((fmsa_t*)g.sa);
	rld_destroy((rld_t*)g.e);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x989680, -0x20(%rbp)  # imm = 0x989680
movq $0x0, -0x38(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x2160
movl $0xa, -0x90(%rbp)
movl $0x1, -0x8c(%rbp)
movl $0x1, -0x78(%rbp)
movl $0x3d, -0x7c(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x5c1e(%rip), %rdx      # 0x2dd13
callq 0x2300
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jl 0x28233
cmpl $0x4d, -0x18(%rbp)
jne 0x28118
movl $0x1, -0x1c(%rbp)
jmp 0x2822e
cmpl $0x73, -0x18(%rbp)
jne 0x28131
movq 0xaeb3(%rip), %rax      # 0x32fd8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x2822c
cmpl $0x6c, -0x18(%rbp)
jne 0x28151
movq 0xae9a(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x88(%rbp)
jmp 0x2822a
cmpl $0x6d, -0x18(%rbp)
jne 0x28171
movq 0xae7a(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x90(%rbp)
jmp 0x28228
cmpl $0x70, -0x18(%rbp)
jne 0x28186
movl $0x1, -0x84(%rbp)
jmp 0x28226
cmpl $0x64, -0x18(%rbp)
jne 0x281a2
movl $0x1, -0x84(%rbp)
movl $0x1, -0x80(%rbp)
jmp 0x28224
cmpl $0x6e, -0x18(%rbp)
jne 0x281bf
movq 0xae29(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x8c(%rbp)
jmp 0x28222
cmpl $0x74, -0x18(%rbp)
jne 0x281d9
movq 0xae0c(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x78(%rbp)
jmp 0x28220
cmpl $0x6b, -0x18(%rbp)
jne 0x28204
movq 0xadf2(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x7c(%rbp)
movl $0x1, -0x84(%rbp)
movl $0x1, -0x80(%rbp)
jmp 0x2821e
cmpl $0x62, -0x18(%rbp)
jne 0x2821c
movq 0xadc7(%rip), %rax      # 0x32fd8
movq (%rax), %rdi
callq 0x2310
movl %eax, -0x20(%rbp)
jmp 0x2821e
jmp 0x28220
jmp 0x28222
jmp 0x28224
jmp 0x28226
jmp 0x28228
jmp 0x2822a
jmp 0x2822c
jmp 0x2822e
jmp 0x280e7
movq 0xad96(%rip), %rax      # 0x32fd0
movl (%rax), %eax
addl $0x2, %eax
cmpl -0x8(%rbp), %eax
jle 0x283bf
movq 0xada9(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5acc(%rip), %rsi      # 0x2dd25
movb $0x0, %al
callq 0x21d0
movq 0xad91(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5ae8(%rip), %rsi      # 0x2dd59
movb $0x0, %al
callq 0x21d0
movq 0xad79(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5ada(%rip), %rsi      # 0x2dd63
movb $0x0, %al
callq 0x21d0
movq 0xad61(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5aff(%rip), %rsi      # 0x2dda0
movb $0x0, %al
callq 0x21d0
movq 0xad49(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x7c(%rbp), %edx
leaq 0x5b22(%rip), %rsi      # 0x2ddde
movb $0x0, %al
callq 0x21d0
movq 0xad2e(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x78(%rbp), %edx
leaq 0x5b47(%rip), %rsi      # 0x2de1e
movb $0x0, %al
callq 0x21d0
movq 0xad13(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x20(%rbp), %edx
leaq 0x5b50(%rip), %rsi      # 0x2de42
movb $0x0, %al
callq 0x21d0
movq 0xacf8(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b55(%rip), %rsi      # 0x2de5f
movb $0x0, %al
callq 0x21d0
movq 0xace0(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x90(%rbp), %edx
leaq 0x5b5c(%rip), %rsi      # 0x2de84
movb $0x0, %al
callq 0x21d0
movq 0xacc2(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x8c(%rbp), %edx
leaq 0x5b8a(%rip), %rsi      # 0x2ded0
movb $0x0, %al
callq 0x21d0
movq 0xaca4(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
movl -0x88(%rbp), %edx
leaq 0x5b8e(%rip), %rsi      # 0x2def2
movb $0x0, %al
callq 0x21d0
movq 0xac86(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b93(%rip), %rsi      # 0x2df0f
movb $0x0, %al
callq 0x21d0
movq 0xac6e(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b8b(%rip), %rsi      # 0x2df1f
movb $0x0, %al
callq 0x21d0
movq 0xac56(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b8b(%rip), %rsi      # 0x2df37
movb $0x0, %al
callq 0x21d0
movl $0x1, -0x4(%rbp)
jmp 0x288d0
movq -0x10(%rbp), %rax
movq 0xac06(%rip), %rcx      # 0x32fd0
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4abe(%rip), %rsi      # 0x2ce9b
callq 0x22c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x28418
movq 0xac04(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b69(%rip), %rsi      # 0x2df67
leaq 0x5b8c(%rip), %rdx      # 0x2df91
movb $0x0, %al
callq 0x21d0
movl $0x1, -0x4(%rbp)
jmp 0x288d0
cmpl $0x0, -0x1c(%rbp)
je 0x2843e
movq -0x10(%rbp), %rax
movq 0xaba7(%rip), %rcx      # 0x32fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3ca0
movq %rax, -0xa8(%rbp)
jmp 0x2845c
movq -0x10(%rbp), %rax
movq 0xab87(%rip), %rcx      # 0x32fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x37c0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x284a8
movq 0xab7d(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5b17(%rip), %rsi      # 0x2df9c
leaq 0x5b05(%rip), %rdx      # 0x2df91
movb $0x0, %al
callq 0x21d0
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0x288d0
cmpl $0x0, -0x84(%rbp)
je 0x28535
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x28(%rcx), %rax
jne 0x284f5
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x20(%rcx), %rax
je 0x28535
movq 0xaafc(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5abd(%rip), %rsi      # 0x2dfc3
leaq 0x5a84(%rip), %rdx      # 0x2df91
movb $0x0, %al
callq 0x21d0
movq -0xa0(%rbp), %rdi
callq 0x28f0
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0x288d0
cmpq $0x0, -0x38(%rbp)
je 0x2854c
movq -0x38(%rbp), %rdi
callq 0x26cd0
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x2859d
cmpq $0x0, -0x98(%rbp)
jne 0x2859d
movq 0xaa94(%rip), %rax      # 0x32ff8
movq (%rax), %rdi
leaq 0x5a8d(%rip), %rsi      # 0x2dffb
leaq 0x5a1c(%rip), %rdx      # 0x2df91
movb $0x0, %al
callq 0x21d0
movq -0xa0(%rbp), %rdi
callq 0x28f0
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0x1, -0x4(%rbp)
jmp 0x288d0
movslq -0x78(%rbp), %rdi
movl $0x78, %esi
callq 0x21a0
movq %rax, -0x70(%rbp)
movl -0x78(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x30(%rbp), %rdi
callq 0x13c80
movq %rax, -0x40(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x40(%rbp), %rdi
callq 0x13d30
cmpl $0x0, %eax
jl 0x28761
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0x28664
cmpl $0x0, -0x64(%rbp)
je 0x285fa
movl -0x64(%rbp), %eax
shll %eax
movl %eax, -0xac(%rbp)
jmp 0x28607
movl $0x4, %eax
movl %eax, -0xac(%rbp)
jmp 0x28607
movl -0xac(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rdi
movslq -0x64(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2270
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x64(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2270
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x64(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2270
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x64(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2270
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2350
movq %rax, %rdx
movq -0x60(%rbp), %rax
movslq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2350
movq %rax, %rdx
movq -0x58(%rbp), %rax
movslq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x286bc
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x2350
movq %rax, -0xb8(%rbp)
jmp 0x286c7
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x286c7
movq -0xb8(%rbp), %rdx
movq -0x50(%rbp), %rax
movslq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movl 0x20(%rax), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jl 0x2875c
movl -0x78(%rbp), %edi
movslq -0x68(%rbp), %rcx
leaq 0x1da(%rip), %rsi       # 0x288e0
leaq -0xa0(%rbp), %rdx
callq 0x2490
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x2874e
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2090
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x28719
movl $0x0, -0x24(%rbp)
movl $0x0, -0x68(%rbp)
jmp 0x285cd
movl -0x78(%rbp), %edi
movslq -0x68(%rbp), %rcx
leaq 0x171(%rip), %rsi       # 0x288e0
leaq -0xa0(%rbp), %rdx
callq 0x2490
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x287b7
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2090
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x28782
movq -0x40(%rbp), %rdi
callq 0x13cc0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x78(%rbp), %eax
jge 0x28871
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x2040
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rdi
callq 0x2040
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x40(%rax), %rdi
callq 0x2040
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rdi
callq 0x2040
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x70(%rax), %rdi
callq 0x2040
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq 0x50(%rax), %rdi
callq 0x2040
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x287c7
movq -0x60(%rbp), %rdi
callq 0x2040
movq -0x58(%rbp), %rdi
callq 0x2040
movq -0x50(%rbp), %rdi
callq 0x2040
movq -0x48(%rbp), %rdi
callq 0x2040
movq -0x70(%rbp), %rdi
callq 0x2040
cmpq $0x0, -0x98(%rbp)
je 0x288b4
movq -0x98(%rbp), %rdi
callq 0x26950
movq -0xa0(%rbp), %rdi
callq 0x28f0
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)