// File: /workspace/github_c_makefile_star2_O3/lh3[P]bgt/view.c
// Function: main_view
int main_view(int argc, char *argv[])
{
	int i, c, n_files = 0, out_bcf = 0, clevel = -1, multi_flag = 0, excl = 0, not_vcf = 0, in_mem = 0, u_set = 0;
	long seekn = -1, n_rec = LONG_MAX, n_read = 0;
	bgtm_t *bm = 0;
	bcf1_t *b;
	htsFile *out = 0;
	char modew[8], *reg = 0, *site_flt = 0;
	void *bed = 0;
	int n_groups = 0;
	char *gexpr[BGT_MAX_GROUPS], *aexpr = 0, *dbfn = 0, *fmt = 0;
	bgt_file_t **files = 0;
	fmf_t *vardb = 0;

	while ((c = getopt(argc, argv, "ubs:r:l:CMGB:ef:g:a:i:n:SHt:d:")) >= 0) {
		if (c == 'b') out_bcf = 1;
		else if (c == 'r') reg = optarg;
		else if (c == 'l') clevel = atoi(optarg);
		else if (c == 'e') excl = 1;
		else if (c == 'u') u_set = 1;
		else if (c == 'B') bed = bed_read(optarg);
		else if (c == 'C') multi_flag |= BGT_F_SET_AC;
		else if (c == 'G') multi_flag |= BGT_F_NO_GT;
		else if (c == 'S') multi_flag |= BGT_F_NO_GT | BGT_F_CNT_AL, not_vcf = 1;
		else if (c == 'H') multi_flag |= BGT_F_NO_GT | BGT_F_CNT_HAP, not_vcf = 1;
		else if (c == 'M') in_mem = 1;
		else if (c == 'i') seekn = atol(optarg) - 1;
		else if (c == 'n') n_rec = atol(optarg);
		else if (c == 'f') site_flt = optarg;
		else if (c == 't') fmt = optarg, not_vcf = 1;
		else if (c == 'd') dbfn = optarg;
		else if (c == 's' && n_groups < BGT_MAX_GROUPS) gexpr[n_groups++] = optarg;
		else if (c == 'a') aexpr = optarg;
	}
	if (n_rec < 0) {
		fprintf(stderr, "[E::%s] option -n must be at least 0.\n", __func__);
		return 1;
	}
	if (clevel > 9) clevel = 9;
	if (u_set) clevel = 0, out_bcf = 1;
	if (n_groups > 1) multi_flag |= BGT_F_SET_AC;
	if (argc - optind < 1) {
		fprintf(stderr, "Usage: bgt %s [options] <bgt-prefix> [...]", argv[0]);
		fputc('\n', stderr);
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  Sample selection:\n");
		fprintf(stderr, "    -s EXPR      samples list (,sample1,sample2 or a file or expr; see Notes below) [all]\n");
		fprintf(stderr, "  Site selection:\n");
		fprintf(stderr, "    -r STR       region [all]\n");
		fprintf(stderr, "    -B FILE      extract variants overlapping BED FILE []\n");
		fprintf(stderr, "    -e           exclude variants overlapping BED FILE (effective with -B)\n");
		fprintf(stderr, "    -i INT       process from the INT-th record (1-based) []\n");
		fprintf(stderr, "    -n INT       process at most INT records []\n");
		fprintf(stderr, "    -d FILE      variant annotations in FMF (to work with -a) []\n");
		fprintf(stderr, "    -M           load variant annotations in RAM (only with -d)\n");
		fprintf(stderr, "    -a EXPR      alleles list chr:1basedPos:refLen:seq (,allele1,allele2 or a file or expr) []\n");
		fprintf(stderr, "    -f STR       frequency filters []\n");
		fprintf(stderr, "  VCF output:\n");
		fprintf(stderr, "    -b           BCF output (effective without -S/-H)\n");
		fprintf(stderr, "    -l INT       compression level for BCF [default]\n");
		fprintf(stderr, "    -u           equivalent to -bl0 (overriding -b and -l)\n");
		fprintf(stderr, "    -G           don't output sample genotypes\n");
		fprintf(stderr, "    -C           write AC/AN to the INFO field (auto applied with -f or multipl -s)\n");
		fprintf(stderr, "  Non-VCF output:\n");
		fprintf(stderr, "    -S           show samples with a set of alleles (with -a)\n");
		fprintf(stderr, "    -H           count of haplotypes with a set of alleles (with -a)\n");
		fprintf(stderr, "    -t STR       comma-delimited list of fields to output. Accepted variables:\n");
		fprintf(stderr, "                 AC, AN, AC#, AN#, CHROM, POS, END, REF, ALT (# for a group number)\n");
		fprintf(stderr, "Notes:\n");
		fprintf(stderr, "  For option -s/-a, EXPR can be one of:\n");
		fprintf(stderr, "    1) comma-delimited list following a colon/comma. e.g. -s,NA12878,NA12044\n");
		fprintf(stderr, "    2) space-delimited file with the first column giving a sample/allele name. e.g. -s list.txt\n");
		fprintf(stderr, "    3) expression if .spl/-d file contains metadata. e.g.: -s\"gender=='M'&&population!='CEU'\"\n");
		fprintf(stderr, "  If multiple -s is specified, the AC/AN of the first group will be written to VCF INFO AC1/AN1,\n");
		fprintf(stderr, "  the second to AC2/AN2, etc.\n");
		return 1;
	}

	if (dbfn && in_mem) vardb = fmf_read(dbfn), dbfn = 0;

	if ((multi_flag&(BGT_F_CNT_AL|BGT_F_CNT_HAP)) && aexpr == 0) {
		fprintf(stderr, "[E::%s] -a must be specified when -S/-H is in use.\n", __func__);
		return 1;
	}

	n_files = argc - optind;
	files = (bgt_file_t**)calloc(n_files, sizeof(bgt_file_t*));
	for (i = 0; i < n_files; ++i) {
		files[i] = bgt_open(argv[optind+i]);
		if (files[i] == 0) {
			fprintf(stderr, "[E::%s] failed to open BGT with prefix '%s'\n", __func__, argv[optind+i]);
			return 1; // FIXME: memory leak
		}
	}

	bm = bgtm_reader_init(n_files, files);
	bgtm_set_flag(bm, multi_flag);
	if (site_flt && bgtm_set_flt_site(bm, site_flt) != 0) {
		fprintf(stderr, "[E::%s] failed to set frequency filters. Syntax error?\n", __func__);
		return 1;
	}
	if (reg && bgtm_set_region(bm, reg) < 0) {
		fprintf(stderr, "[E::%s] failed to set region. Region format error?\n", __func__);
		return 1;
	}
	if (bed) bgtm_set_bed(bm, bed, excl);
	if (fmt && bgtm_set_table(bm, fmt) < 0) {
		fprintf(stderr, "[E::%s] failed to set tabular output.\n", __func__);
		return 1;
	}
	if (seekn > 0) bgtm_set_start(bm, seekn);
	if (aexpr) {
		int n_al;
		n_al = bgtm_set_alleles(bm, aexpr, vardb, dbfn);
		if (n_al < 0) {
			fprintf(stderr, "[E::%s] failed to set alleles.\n", __func__);
			return 1;
		} else if (n_al == 0)
			fprintf(stderr, "[W::%s] no alleles selected.\n", __func__);
	}
	for (i = 0; i < n_groups; ++i) {
		if (bgtm_add_group(bm, gexpr[i]) < 0) {
			fprintf(stderr, "[E::%s] failed to add sample group '%s'.\n", __func__, gexpr[i]);
			return 1;
		}
	}
	bgtm_prepare(bm); // bgtm_prepare() generates the VCF header

	if (!not_vcf) {
		strcpy(modew, "w");
		if (out_bcf) strcat(modew, "b");
		sprintf(modew + strlen(modew), "%d", clevel);
		out = hts_open("-", modew, 0);
		vcf_hdr_write(out, bm->h_out);
	}

	b = bcf_init1();
	while (bgtm_read(bm, b) >= 0 && n_read < n_rec) {
		if (out) vcf_write1(out, bm->h_out, b);
		if (fmt && bm->n_fields > 0) puts(bm->tbl_line.s);
		++n_read;
	}
	bcf_destroy1(b);

	if (not_vcf && bm->n_aal > 0) {
		if (bm->flag & BGT_F_CNT_HAP) {
			bgt_hapcnt_t *hc;
			int n_hap;
			char *s;
			hc = bgtm_hapcnt(bm, &n_hap);
			s = bgtm_hapcnt_print_destroy(bm, n_hap, hc);
			fputs(s, stdout);
			free(s);
		}
		if (bm->flag & BGT_F_CNT_AL) {
			char *s;
			if ((s = bgtm_alcnt_print(bm)) != 0)
				fputs(s, stdout);
			free(s);
		}
	}

	if (out) hts_close(out);
	bgtm_reader_destroy(bm);
	if (bed) bed_destroy(bed);
	for (i = 0; i < n_files; ++i) bgt_close(files[i]);
	free(files);
	if (vardb) fmf_destroy(vardb);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %r13
movl %edi, %ebp
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x60(%rsp)
leaq 0x1ae50(%rip), %rdx     # 0x1e538
callq 0x23d0
testl %eax, %eax
js 0x3980
movq $-0x1, 0x70(%rsp)
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x38(%rsp)
leaq 0x1ada2(%rip), %rbx     # 0x1e4b8
leaq 0x1ae1b(%rip), %r12     # 0x1e538
leaq 0x1adc4(%rip), %r14     # 0x1e4e8
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x48(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x10(%rsp)
leal -0x62(%rax), %ecx
cmpl $0x13, %ecx
ja 0x37a9
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
movl $0x1, %eax
movq %rax, 0x38(%rsp)
jmp 0x3905
leal -0x42(%rax), %ecx
cmpl $0xb, %ecx
ja 0x37d3
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movq 0x227ef(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x14312
movq %rax, 0x48(%rsp)
jmp 0x3905
cmpl $0x53, %eax
jne 0x37e5
movq 0x10(%rsp), %rax
orl $0x6, %eax
jmp 0x38df
cmpl $0x73, %eax
sete %cl
cmpl $0x20, %r15d
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x391c
movl %r15d, %esi
movq 0x227a9(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movslq %r15d, %rcx
incl %esi
movl %esi, %r15d
movq %rax, 0x90(%rsp,%rcx,8)
jmp 0x3905
movq 0x2278a(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x2380
movq %rax, 0x60(%rsp)
jmp 0x3905
movq 0x22771(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x80(%rsp)
jmp 0x3905
movq 0x2275a(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x78(%rsp)
jmp 0x3905
movl $0x1, 0x34(%rsp)
jmp 0x3905
movl $0x1, 0x20(%rsp)
jmp 0x3905
movq 0x2272c(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x23e0
movl %eax, 0x24(%rsp)
jmp 0x3905
movq 0x22717(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x2380
decq %rax
movq %rax, 0x70(%rsp)
jmp 0x3905
movq 0x226fe(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x3905
movq 0x226ed(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x58(%rsp)
jmp 0x38e4
movl $0x1, 0x1c(%rsp)
jmp 0x3905
movq 0x10(%rsp), %rax
orl $0xa, %eax
movq %rax, 0x10(%rsp)
movl $0x1, 0x28(%rsp)
jmp 0x3905
movq 0x10(%rsp), %rax
orl $0x2, %eax
jmp 0x3900
movq 0x10(%rsp), %rax
orl $0x1, %eax
movq %rax, 0x10(%rsp)
movl %ebp, %edi
movq %r13, %rsi
movq %r12, %rdx
callq 0x23d0
testl %eax, %eax
jns 0x3789
jmp 0x3932
cmpl $0x61, %eax
jne 0x3905
movq 0x22688(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x3905
cmpq $0x0, 0x60(%rsp)
js 0x3d86
cmpl $0x0, 0x28(%rsp)
sete 0xf(%rsp)
cmpl $0x0, 0x1c(%rsp)
setne %al
movl 0x24(%rsp), %edx
cmpl $0x9, %edx
movl $0x9, %ecx
cmovll %edx, %ecx
xorl %r12d, %r12d
movl 0x20(%rsp), %edx
testl %edx, %edx
cmovel %ecx, %r12d
movq 0x38(%rsp), %rcx
orl %edx, %ecx
sete %cl
movl %r15d, %r14d
movq 0x50(%rsp), %rdi
jmp 0x39de
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq $-0x1, 0x70(%rsp)
movb $0x1, 0xf(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, 0x34(%rsp)
xorl %eax, %eax
movb $0x1, %cl
movq $0x0, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x48(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x40(%rsp)
xorl %edi, %edi
movq $0x0, 0x58(%rsp)
xorl %r15d, %r15d
cmpl $0x2, %r14d
setge %dl
movq 0x225a9(%rip), %rbx     # 0x25f98
cmpl %ebp, (%rbx)
jge 0x3d75
movb %cl, 0x1c(%rsp)
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
movb %dl, 0x24(%rsp)
jne 0x3a15
callq 0x9c9c
xorl %edi, %edi
jmp 0x3a17
xorl %eax, %eax
testb $0xc, 0x10(%rsp)
je 0x3a2a
cmpq $0x0, 0x40(%rsp)
je 0x3d7f
movl %r12d, 0x88(%rsp)
movq %rax, 0x38(%rsp)
movq %rdi, 0x50(%rsp)
movl %r14d, 0x20(%rsp)
movslq (%rbx), %rax
movslq %ebp, %r14
subq %rax, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x2220
movq %rax, %rbp
movl %r14d, %r12d
movq %r14, 0x28(%rsp)
testl %r14d, %r14d
jle 0x3a91
xorl %r14d, %r14d
movl (%rbx), %eax
addl %r14d, %eax
cltq
movq (%r13,%rax,8), %rdi
callq 0x160cc
movq %rax, (%rbp,%r14,8)
testq %rax, %rax
je 0x3d8d
incq %r14
cmpq %r14, %r12
jne 0x3a6a
movb 0x24(%rsp), %al
movb %al, %r15b
movq 0x10(%rsp), %rbx
orl %r15d, %ebx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x17694
movq %rax, %r13
movq %rax, %rdi
movl %ebx, %esi
callq 0x179b0
movq 0x80(%rsp), %rsi
testq %rsi, %rsi
je 0x3ad7
movq %r13, %rdi
callq 0x179b4
testl %eax, %eax
jne 0x3d9a
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
je 0x3af1
movq %r13, %rdi
callq 0x17908
testl %eax, %eax
js 0x3da1
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0x3b07
movq %r13, %rdi
movl 0x34(%rsp), %edx
callq 0x1798d
movq 0x58(%rsp), %rsi
testq %rsi, %rsi
movl 0x20(%rsp), %ebx
movq 0x40(%rsp), %r14
je 0x3b2a
movq %r13, %rdi
callq 0x18bee
testl %eax, %eax
js 0x3da8
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
jle 0x3b3c
movq %r13, %rdi
callq 0x1794c
testq %r14, %r14
je 0x3b64
movq %r13, %rdi
movq %r14, %rsi
movq 0x38(%rsp), %rdx
movq 0x50(%rsp), %rcx
callq 0x17a37
testl %eax, %eax
js 0x3daf
je 0x3df1
testl %ebx, %ebx
jle 0x3b91
movl %ebx, %r14d
xorl %r15d, %r15d
movq 0x90(%rsp,%r15,8), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x178af
testl %eax, %eax
js 0x3db6
incq %r15
cmpq %r15, %r14
jne 0x3b6e
movq %r13, %rdi
callq 0x18c11
cmpb $0x0, 0xf(%rsp)
je 0x3c0b
movw $0x77, 0x68(%rsp)
cmpb $0x0, 0x1c(%rsp)
jne 0x3bbf
leaq 0x68(%rsp), %rdi
callq 0x2170
movw $0x62, 0x68(%rsp,%rax)
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x2170
leaq (%rsp,%rax), %rdi
addq $0x68, %rdi
leaq 0x1c122(%rip), %rsi     # 0x1fcfd
movl 0x88(%rsp), %edx
xorl %eax, %eax
callq 0x23f0
leaq 0x1a8c4(%rip), %rdi     # 0x1e4b4
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6553
movq %rax, %rbx
movq 0x50(%r13), %rsi
movq %rax, %rdi
callq 0xc494
jmp 0x3c0d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xbb1a
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0x1aac7
testl %eax, %eax
sets %al
cmpq $0x0, 0x60(%rsp)
sete %cl
orb %al, %cl
jne 0x3c86
movl $0x1, %r15d
testq %rbx, %rbx
je 0x3c4e
movq 0x50(%r13), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x10839
cmpq $0x0, 0x58(%rsp)
je 0x3c69
cmpl $0x0, 0x68(%r13)
jle 0x3c69
movq 0x88(%r13), %rdi
callq 0x20e0
movq %r13, %rdi
movq %r14, %rsi
callq 0x1aac7
testl %eax, %eax
js 0x3c86
leaq 0x1(%r15), %rax
cmpq 0x60(%rsp), %r15
movq %rax, %r15
jl 0x3c3a
movq %r14, %rdi
callq 0xbb29
cmpb $0x0, 0xf(%rsp)
jne 0x3d1b
cmpl $0x0, 0x90(%r13)
jle 0x3d1b
movl 0xc(%r13), %eax
testb $0x8, %al
je 0x3ced
leaq 0x8c(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1af7f
movl (%r14), %esi
movq %r13, %rdi
movq %rax, %rdx
callq 0x1b696
movq %rax, %r14
movq 0x222aa(%rip), %rax     # 0x25f80
movq (%rax), %rsi
movq %r14, %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x2050
movl 0xc(%r13), %eax
testb $0x4, %al
je 0x3d1b
movq %r13, %rdi
callq 0x1b982
movq %rax, %r14
testq %rax, %rax
je 0x3d13
movq 0x22278(%rip), %rax     # 0x25f80
movq (%rax), %rsi
movq %r14, %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x2050
testq %rbx, %rbx
je 0x3d28
movq %rbx, %rdi
callq 0x677e
movq %r13, %rdi
callq 0x17711
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d3f
callq 0x14def
cmpl $0x0, 0x28(%rsp)
jle 0x3d5a
xorl %ebx, %ebx
movq (%rbp,%rbx,8), %rdi
callq 0x163b9
incq %rbx
cmpq %rbx, %r12
jne 0x3d48
movq %rbp, %rdi
callq 0x2050
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3ddd
callq 0xa152
jmp 0x3ddd
movq %r13, %rdi
callq 0x2697
jmp 0x3dd8
callq 0x2a5e
jmp 0x3dd8
callq 0x2a7d
jmp 0x3dd8
movl %r14d, %edi
movq %r13, %rsi
callq 0x2a28
jmp 0x3dd8
callq 0x298d
jmp 0x3dd8
callq 0x29ac
jmp 0x3dd8
callq 0x29cb
jmp 0x3dd8
callq 0x29ea
jmp 0x3dd8
movq 0x2223b(%rip), %rax     # 0x25ff8
movq (%rax), %rdi
leaq 0x1affa(%rip), %rsi     # 0x1edc1
leaq 0x1a7b0(%rip), %rdx     # 0x1e57e
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2250
movl $0x1, %ebx
movl %ebx, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2a09
jmp 0x3b64