// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/main.c
// Function: bcf_main_ldpair
int bcf_main_ldpair(int argc, char *argv[])
{
	bcf_t *fp;
	bcf_hdr_t *h;
	bcf1_t *b0, *b1;
	bcf_idx_t *idx;
	kstring_t str;
	void *str2id;
	gzFile fplist;
	kstream_t *ks;
	int dret, lineno = 0;
	if (argc < 3) {
		fprintf(stderr, "Usage: bcftools ldpair <in.bcf> <in.list>\n");
		return 1;
	}
	fplist = gzopen(argv[2], "rb");
	ks = ks_init(fplist);
	memset(&str, 0, sizeof(kstring_t));
	fp = bcf_open(argv[1], "rb");
	h = bcf_hdr_read(fp);
	str2id = bcf_build_refhash(h);
	idx = bcf_idx_load(argv[1]);
	if (idx == 0) {
		fprintf(stderr, "[%s] No bcf index is found. Abort!\n", __func__);
		return 1;
	}
	b0 = calloc(1, sizeof(bcf1_t));
	b1 = calloc(1, sizeof(bcf1_t));
	while (ks_getuntil(ks, '\n', &str, &dret) >= 0) {
		char *p, *q;
		int k;
		int tid0 = -1, tid1 = -1, pos0 = -1, pos1 = -1;
		++lineno;
		for (p = q = str.s, k = 0; *p; ++p) {
			if (*p == ' ' || *p == '\t') {
				*p = '\0';
				if (k == 0) tid0 = bcf_str2id(str2id, q);
				else if (k == 1) pos0 = atoi(q) - 1;
				else if (k == 2) tid1 = strcmp(q, "=")? bcf_str2id(str2id, q) : tid0;
				else if (k == 3) pos1 = atoi(q) - 1;
				q = p + 1;
				++k;
			}
		}
		if (k == 3) pos1 = atoi(q) - 1;
		if (tid0 >= 0 && tid1 >= 0 && pos0 >= 0 && pos1 >= 0) {
			uint64_t off;
			double r, f[4];
			off = bcf_idx_query(idx, tid0, pos0);
			bgzf_seek(fp->fp, off, SEEK_SET);
			while (bcf_read(fp, h, b0) >= 0 && b0->pos != pos0);
			off = bcf_idx_query(idx, tid1, pos1);
			bgzf_seek(fp->fp, off, SEEK_SET);
			while (bcf_read(fp, h, b1) >= 0 && b1->pos != pos1);
			r = bcf_pair_freq(b0, b1, f);
			r *= r;
			printf("%s\t%d\t%s\t%d\t%.4g\t%.4g\t%.4g\t%.4g\t%.4g\n", h->ns[tid0], pos0+1, h->ns[tid1], pos1+1,
				r, f[0], f[1], f[2], f[3]);
		} //else fprintf(stderr, "[%s] Parse error at line %d.\n", __func__, lineno);
	}
	bcf_destroy(b0); bcf_destroy(b1);
	bcf_idx_destroy(idx);
	bcf_str2id_destroy(str2id);
	bcf_hdr_destroy(h);
	bcf_close(fp);
	free(str.s);
	ks_destroy(ks);
	gzclose(fplist);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
cmpl $0x2, %edi
jle 0x6f53
movq %rsi, %rbx
movq 0x10(%rsi), %rdi
leaq 0x13fb9(%rip), %r15     # 0x1aad7
movq %r15, %rsi
callq 0x22c0
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x2260
movq %rax, %r14
movq %r12, 0x38(%rsp)
movq %r12, 0x18(%rax)
movl $0x10000, %edi          # imm = 0x10000
callq 0x2360
movq %rax, (%r14)
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0xb4e8
movq %rax, %r13
movq %rax, %rdi
callq 0xb658
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0xe470
movq %rax, 0x30(%rsp)
movq 0x8(%rbx), %rdi
callq 0x1779e
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x6f5a
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, 0x10(%rsp)
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, 0x28(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %r13, 0x40(%rsp)
cmpl %eax, %ecx
jl 0x6bd6
cmpl $0x0, 0x10(%r14)
jne 0x6ee6
xorl %ebx, %ebx
cmpl %eax, %ecx
jl 0x6c1d
cmpl $0x0, 0x10(%r14)
jne 0x6cdb
movl $0x0, 0x8(%r14)
movq (%r14), %rsi
movq 0x18(%r14), %rdi
movl $0x10000, %edx          # imm = 0x10000
callq 0x2280
movl %eax, 0xc(%r14)
xorl %ecx, %ecx
cmpl $0xffff, %eax           # imm = 0xFFFF
jg 0x6c1d
movl $0x1, 0x10(%r14)
testl %eax, %eax
je 0x6cdb
movl %ecx, %r12d
cmpl %eax, %ecx
jge 0x6c40
movslq %ecx, %rdx
addq (%r14), %rdx
movl %ecx, %r12d
cmpb $0xa, (%rdx)
je 0x6c40
incl %r12d
incq %rdx
cmpl %r12d, %eax
jne 0x6c2d
movl %eax, %r12d
movq %r15, %rdx
subq %rbx, %rdx
movl %r12d, %eax
subl %ecx, %eax
leal 0x1(%rax), %esi
movslq %esi, %rsi
cmpq %rsi, %rdx
jae 0x6ca6
cltq
addq %rbx, %rax
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 %rbp, %rdi
movq %r15, %rsi
callq 0x23d0
movq %rax, %rbp
movl 0x8(%r14), %ecx
movl %r12d, %eax
subl %ecx, %eax
leaq (%rbx,%rbp), %rdi
movslq %ecx, %rsi
addq (%r14), %rsi
movslq %eax, %rdx
callq 0x22e0
movslq 0x8(%r14), %rax
movslq %r12d, %rcx
subq %rax, %rcx
addq %rcx, %rbx
leal 0x1(%r12), %ecx
movl %ecx, 0x8(%r14)
movl 0xc(%r14), %eax
cmpl %eax, %r12d
jge 0x6bd8
testq %rbp, %rbp
jne 0x6cf8
movl $0x1, %r15d
movl $0x1, %edi
movl $0x1, %esi
callq 0x2260
movq %rax, %rbp
movb $0x0, (%rbp,%rbx)
testl %ebx, %ebx
js 0x6ee6
leaq 0x1(%rbp), %r12
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq %rbp, 0x48(%rsp)
movq %rbp, %rsi
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movzbl -0x1(%r12), %eax
cmpl $0x9, %eax
je 0x6d44
cmpl $0x20, %eax
je 0x6d44
testl %eax, %eax
jne 0x6dae
jmp 0x6dbc
movb $0x0, -0x1(%r12)
cmpl $0x3, %r13d
ja 0x6da8
movl %r13d, %eax
leaq 0x13d42(%rip), %rcx     # 0x1aa9c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x30(%rsp), %rdi
callq 0xe784
movl %eax, 0x8(%rsp)
jmp 0x6da8
cmpb $0x3d, (%rsi)
jne 0x6d7e
cmpb $0x0, 0x1(%rsi)
je 0x6db6
movq 0x30(%rsp), %rdi
callq 0xe784
movl %eax, 0xc(%rsp)
jmp 0x6da8
movq %rsi, %rdi
callq 0x2470
movl %eax, %ebp
decl %ebp
jmp 0x6da8
movq %rsi, %rdi
callq 0x2470
movl %eax, %ebx
decl %ebx
incl %r13d
movq %r12, %rsi
incq %r12
jmp 0x6d2e
movl 0x8(%rsp), %eax
jmp 0x6d88
cmpl $0x3, %r13d
jne 0x6dce
movq %rsi, %rdi
callq 0x2470
movl %eax, %ebp
decl %ebp
cmpl $0x0, 0x8(%rsp)
movq 0x40(%rsp), %r13
movl 0xc(%rsp), %r12d
js 0x6ed4
testl %r12d, %r12d
js 0x6ed4
testl %ebx, %ebx
js 0x6ed4
testl %ebp, %ebp
js 0x6ed4
movq 0x20(%rsp), %rdi
movl 0x8(%rsp), %esi
movl %ebx, %edx
callq 0x17b49
movq 0x10(%r13), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x8cb8
movq 0x10(%rsp), %rdx
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0xbcac
testl %eax, %eax
movq 0x10(%rsp), %rdx
js 0x6e3a
cmpl %ebx, 0x4(%rdx)
jne 0x6e1f
movq 0x20(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x17b49
movq 0x10(%r13), %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x8cb8
movq 0x28(%rsp), %rdx
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0xbcac
testl %eax, %eax
movq 0x28(%rsp), %rdx
js 0x6e77
cmpl %ebp, 0x4(%rdx)
jne 0x6e5c
movq 0x10(%rsp), %rdi
movq %rdx, %rsi
leaq 0x50(%rsp), %rdx
callq 0x15c37
mulsd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
movl 0x8(%rsp), %ecx
movq (%rax,%rcx,8), %rsi
incl %ebx
movl %r12d, %ecx
movq (%rax,%rcx,8), %rcx
incl %ebp
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm2
movsd 0x60(%rsp), %xmm3
movsd 0x68(%rsp), %xmm4
leaq 0x13c46(%rip), %rdi     # 0x1ab0e
movl %ebx, %edx
movl %ebp, %r8d
movb $0x5, %al
callq 0x21b0
movl 0x8(%r14), %ecx
movl 0xc(%r14), %eax
movq 0x48(%rsp), %rbp
jmp 0x6bc7
movq 0x10(%rsp), %rdi
callq 0xbdf9
movq 0x28(%rsp), %rdi
callq 0xbdf9
movq 0x20(%rsp), %rdi
callq 0x175cc
movq 0x30(%rsp), %rdi
callq 0xe6dc
movq 0x18(%rsp), %rdi
callq 0xb87a
movq %r13, %rdi
callq 0xb56e
movq %rbp, %rdi
callq 0x2060
movq (%r14), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2060
movq 0x38(%rsp), %rdi
callq 0x2050
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2719
jmp 0x6f5f
callq 0x26fa
movl $0x1, %eax
jmp 0x6f44