// File: /workspace/github_c_makefile_star2_O1/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 0x1ae8c(%rip), %rdx     # 0x1e538
callq 0x23d0
testl %eax, %eax
js 0x392f
movq $-0x1, 0x70(%rsp)
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x48(%rsp)
leaq 0x1adde(%rip), %rbx     # 0x1e4b8
leaq 0x1ae57(%rip), %r12     # 0x1e538
leaq 0x1ae00(%rip), %r14     # 0x1e4e8
movq $0x0, 0x40(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x38(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x10(%rsp)
leal -0x62(%rax), %ecx
cmpl $0x13, %ecx
ja 0x376d
movslq (%r14,%rcx,4), %rcx
addq %r14, %rcx
jmpq *%rcx
movl $0x1, %eax
movq %rax, 0x48(%rsp)
jmp 0x38c9
leal -0x42(%rax), %ecx
cmpl $0xb, %ecx
ja 0x3797
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movq 0x2282b(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x13f0c
movq %rax, 0x38(%rsp)
jmp 0x38c9
cmpl $0x53, %eax
jne 0x37a9
movq 0x10(%rsp), %rax
orl $0x6, %eax
jmp 0x38a3
cmpl $0x73, %eax
sete %cl
cmpl $0x20, %r15d
setl %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x38e0
movl %r15d, %esi
movq 0x227e5(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movslq %r15d, %rcx
incl %esi
movl %esi, %r15d
movq %rax, 0x90(%rsp,%rcx,8)
jmp 0x38c9
movq 0x227c6(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x2380
movq %rax, 0x60(%rsp)
jmp 0x38c9
movq 0x227ad(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x80(%rsp)
jmp 0x38c9
movq 0x22796(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x78(%rsp)
jmp 0x38c9
movl $0x1, 0x2c(%rsp)
jmp 0x38c9
movl $0x1, 0xc(%rsp)
jmp 0x38c9
movq 0x22768(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x23e0
movl %eax, 0x30(%rsp)
jmp 0x38c9
movq 0x22753(%rip), %rax     # 0x25fb0
movq (%rax), %rdi
callq 0x2380
decq %rax
movq %rax, 0x70(%rsp)
jmp 0x38c9
movq 0x2273a(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x58(%rsp)
jmp 0x38c9
movq 0x22729(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x38a8
movl $0x1, 0x1c(%rsp)
jmp 0x38c9
movq 0x10(%rsp), %rax
orl $0xa, %eax
movq %rax, 0x10(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x38c9
movq 0x10(%rsp), %rax
orl $0x2, %eax
jmp 0x38c4
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 0x374d
jmp 0x38f6
cmpl $0x61, %eax
jne 0x38c9
movq 0x226c4(%rip), %rax     # 0x25fb0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x38c9
cmpl $0x0, 0xc(%rsp)
sete %sil
cmpl $0x0, 0x1c(%rsp)
setne %al
cmpl $0x0, 0x20(%rsp)
sete 0xc(%rsp)
cmpl $0x0, 0x48(%rsp)
sete %r8b
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %r14
movl 0x30(%rsp), %edx
movq 0x38(%rsp), %rcx
jmp 0x3983
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq $-0x1, 0x70(%rsp)
movb $0x1, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, 0x2c(%rsp)
xorl %eax, %eax
movb $0x1, %sil
movq $0x0, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
xorl %ecx, %ecx
xorl %r15d, %r15d
movq $0x0, 0x50(%rsp)
xorl %edi, %edi
xorl %r14d, %r14d
movb $0x1, %r8b
cmpq $0x0, 0x60(%rsp)
js 0x3d5c
movq %rcx, 0x38(%rsp)
cmpl $0x9, %edx
movl $0x9, %ecx
cmovll %edx, %ecx
xorl %edx, %edx
testb %sil, %sil
cmovnel %ecx, %edx
xorl %r12d, %r12d
cmpl $0x2, %r15d
setge %r9b
movq 0x225df(%rip), %rbx     # 0x25f98
cmpl %ebp, (%rbx)
jge 0x3d63
testq %rdi, %rdi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
movb %sil, 0xb(%rsp)
movb %r8b, 0xa(%rsp)
movl %edx, 0x88(%rsp)
movb %r9b, 0x48(%rsp)
jne 0x39ed
callq 0x9a08
xorl %edi, %edi
jmp 0x39ef
xorl %eax, %eax
testb $0xc, 0x10(%rsp)
je 0x3a02
cmpq $0x0, 0x50(%rsp)
je 0x3d6d
movq %rax, 0x30(%rsp)
movq %rdi, 0x58(%rsp)
movl %r15d, 0x1c(%rsp)
movq %r14, 0x40(%rsp)
movslq (%rbx), %rax
movslq %ebp, %r14
subq %rax, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x2220
movq %rax, %rbp
movl %r14d, %r15d
movq %r14, 0x20(%rsp)
testl %r14d, %r14d
jle 0x3a66
xorl %r14d, %r14d
movl (%rbx), %eax
addl %r14d, %eax
cltq
movq (%r13,%rax,8), %rdi
callq 0x15b98
movq %rax, (%rbp,%r14,8)
testq %rax, %rax
je 0x3d74
incq %r14
cmpq %r14, %r15
jne 0x3a3f
movb 0x48(%rsp), %al
movb %al, %r12b
movq 0x10(%rsp), %rbx
orl %r12d, %ebx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x17029
movq %rax, %r13
movq %rax, %rdi
movl %ebx, %esi
callq 0x1733d
movq 0x80(%rsp), %rsi
testq %rsi, %rsi
je 0x3aac
movq %r13, %rdi
callq 0x17341
testl %eax, %eax
jne 0x3d81
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
je 0x3ac6
movq %r13, %rdi
callq 0x17295
testl %eax, %eax
js 0x3d88
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0x3adc
movq %r13, %rdi
movl 0x2c(%rsp), %edx
callq 0x1731a
movq 0x40(%rsp), %rsi
testq %rsi, %rsi
movl 0x1c(%rsp), %r14d
movq 0x50(%rsp), %rbx
je 0x3b00
movq %r13, %rdi
callq 0x18381
testl %eax, %eax
js 0x3d8f
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
jle 0x3b12
movq %r13, %rdi
callq 0x172d9
testq %rbx, %rbx
je 0x3b44
movq %r13, %rdi
movq %rbx, %rsi
movq 0x30(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x173c3
movl %eax, %ebx
testl %eax, %eax
js 0x3d96
je 0x3d9f
testl %ebx, %ebx
js 0x3dd2
testl %r14d, %r14d
jle 0x3b72
movl %r14d, %r14d
xorl %r12d, %r12d
movq 0x90(%rsp,%r12,8), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1723f
testl %eax, %eax
js 0x3db0
incq %r12
cmpq %r12, %r14
jne 0x3b4f
movq %r13, %rdi
callq 0x183a4
cmpb $0x0, 0xc(%rsp)
je 0x3bef
movw $0x77, 0x68(%rsp)
movb 0xa(%rsp), %al
testb %al, 0xb(%rsp)
jne 0x3ba3
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 0x1c11e(%rip), %rsi     # 0x1fcdd
movl 0x88(%rsp), %edx
xorl %eax, %eax
callq 0x23f0
leaq 0x1a8e0(%rip), %rdi     # 0x1e4b4
movq %rbx, %rsi
xorl %edx, %edx
callq 0x6414
movq %rax, %rbx
movq 0x50(%r13), %rsi
movq %rax, %rdi
callq 0xc2f1
jmp 0x3bf1
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xb9db
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0x1a37c
testl %eax, %eax
sets %al
cmpq $0x0, 0x60(%rsp)
sete %cl
orb %al, %cl
jne 0x3c6b
movl $0x1, %r12d
testq %rbx, %rbx
je 0x3c32
movq 0x50(%r13), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1068d
cmpq $0x0, 0x40(%rsp)
je 0x3c4d
cmpl $0x0, 0x68(%r13)
jle 0x3c4d
movq 0x88(%r13), %rdi
callq 0x20e0
movq %r13, %rdi
movq %r14, %rsi
callq 0x1a37c
testl %eax, %eax
js 0x3c6b
leaq 0x1(%r12), %rax
cmpq 0x60(%rsp), %r12
movq %rax, %r12
jl 0x3c1e
movq %r14, %rdi
callq 0xb9ea
cmpb $0x0, 0xc(%rsp)
jne 0x3cfe
cmpl $0x0, 0x90(%r13)
jle 0x3cfe
testb $0x8, 0xc(%r13)
je 0x3ccd
leaq 0x8c(%rsp), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1a834
movl (%r14), %esi
movq %r13, %rdi
movq %rax, %rdx
callq 0x1ac09
movq %rax, %r14
movq 0x222c6(%rip), %rax     # 0x25f80
movq (%rax), %rsi
movq %r14, %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x2050
testb $0x4, 0xc(%r13)
je 0x3cfe
movq %r13, %rdi
callq 0x1aefb
movq %rax, %r14
testq %rax, %rax
je 0x3cf6
movq 0x22295(%rip), %rax     # 0x25f80
movq (%rax), %rsi
movq %r14, %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x2050
testq %rbx, %rbx
je 0x3d0b
movq %rbx, %rdi
callq 0x660f
movq %r13, %rdi
callq 0x170a6
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3d22
callq 0x146bd
cmpl $0x0, 0x20(%rsp)
jle 0x3d3d
xorl %ebx, %ebx
movq (%rbp,%rbx,8), %rdi
callq 0x15d86
incq %rbx
cmpq %rbx, %r15
jne 0x3d2b
movq %rbp, %rdi
callq 0x2050
xorl %ebx, %ebx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3dd7
callq 0x9ebe
jmp 0x3dd7
callq 0x2a5a
jmp 0x3dd2
movq %r13, %rdi
callq 0x2697
jmp 0x3dd2
callq 0x2a3b
jmp 0x3dd2
movq %r14, %rdi
movq %r13, %rsi
callq 0x2a05
jmp 0x3dd2
callq 0x298d
jmp 0x3dd2
callq 0x29ac
jmp 0x3dd2
callq 0x29cb
jmp 0x3dd2
leaq 0x1afe6(%rip), %rdi     # 0x1ed83
jmp 0x3da6
leaq 0x1affd(%rip), %rdi     # 0x1eda3
callq 0x29ea
jmp 0x3b3c
movq 0x22241(%rip), %rax     # 0x25ff8
movq (%rax), %rdi
leaq 0x1b000(%rip), %rsi     # 0x1edc1
leaq 0x1a7b6(%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