// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/main.c
// Function: bcf_main_ld
int bcf_main_ld(int argc, char *argv[])
{
	bcf_t *fp;
	bcf_hdr_t *h;
	bcf1_t **b, *b0;
	int i, j, m, n;
	double f[4];
	if (argc == 1) {
		fprintf(stderr, "Usage: bcftools ld <in.bcf>\n");
		return 1;
	}
	fp = bcf_open(argv[1], "rb");
	h = bcf_hdr_read(fp);
	// read the entire BCF
	m = n = 0; b = 0;
	b0 = calloc(1, sizeof(bcf1_t));
	while (bcf_read(fp, h, b0) >= 0) {
		if (m == n) {
			m = m? m<<1 : 16;
			b = realloc(b, sizeof(void*) * m);
		}
		b[n] = calloc(1, sizeof(bcf1_t));
		bcf_cpy(b[n++], b0);
	}
	bcf_destroy(b0);
	// compute pair-wise r^2
	printf("%d\n", n); // the number of loci
	for (i = 0; i < n; ++i) {
		printf("%s:%d", h->ns[b[i]->tid], b[i]->pos + 1);
		for (j = 0; j < i; ++j) {
			double r = bcf_pair_freq(b[i], b[j], f);
			printf("\t%.3f", r*r);
		}
		printf("\t1.000\n");
	}
	// free
	for (i = 0; i < n; ++i) bcf_destroy(b[i]);
	free(b);
	bcf_hdr_destroy(h);
	bcf_close(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x1, %edi
je 0x713b
movq 0x8(%rsi), %rdi
leaq 0x13b4f(%rip), %rsi     # 0x1aad7
callq 0xb4e8
movq %rax, %rbp
movq %rax, %rdi
callq 0xb658
movq %rax, %rbx
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, %r13
movq %rbp, %rdi
movq %rbx, 0x8(%rsp)
movq %rbx, %rsi
movq %rax, %rdx
callq 0xbcac
testl %eax, %eax
js 0x7036
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %r14d, %eax
cmpq %rax, %r12
jne 0x6fff
movq %rbp, %rbx
leal (%r14,%r14), %ebp
testl %r14d, %r14d
movl $0x10, %eax
cmovel %eax, %ebp
movslq %ebp, %rsi
shlq $0x3, %rsi
movq %r15, %rdi
callq 0x23d0
movq %rax, %r15
movl %ebp, %r14d
movq %rbx, %rbp
movl $0x1, %edi
movl $0x68, %esi
callq 0x2260
movq %rax, (%r15,%r12,8)
incq %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0xcfe8
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0xbcac
testl %eax, %eax
jns 0x6fcd
jmp 0x703c
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %r13, %rdi
callq 0xbdf9
leaq 0x141ca(%rip), %rdi     # 0x1b215
xorl %r14d, %r14d
movl %r12d, %esi
xorl %eax, %eax
callq 0x21b0
testl %r12d, %r12d
je 0x710f
movq %rbp, 0x18(%rsp)
movl %r12d, %eax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %rbx
leaq 0x13add(%rip), %r13     # 0x1ab57
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movq (%r15,%r14,8), %rcx
movslq (%rcx), %rdx
movq (%rax,%rdx,8), %rsi
movl 0x4(%rcx), %edx
incl %edx
leaq 0x13ab4(%rip), %rdi     # 0x1ab51
xorl %eax, %eax
callq 0x21b0
testq %r14, %r14
je 0x70d1
xorl %ebp, %ebp
movq (%r15,%r14,8), %rdi
movq (%r15,%rbp,8), %rsi
movq %rbx, %rdx
callq 0x15c37
mulsd %xmm0, %xmm0
movq %r13, %rdi
movb $0x1, %al
callq 0x21b0
incq %rbp
cmpq %rbp, %r14
jne 0x70ab
leaq 0x13c16(%rip), %rdi     # 0x1acee
callq 0x20d0
incq %r14
cmpq 0x10(%rsp), %r14
jne 0x707d
testl %r12d, %r12d
movq 0x18(%rsp), %rbp
movl $0x0, %r14d
movq 0x10(%rsp), %r12
je 0x710f
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0xbdf9
incq %rbx
cmpq %rbx, %r12
jne 0x70fe
movq %r15, %rdi
callq 0x2060
movq 0x8(%rsp), %rdi
callq 0xb87a
movq %rbp, %rdi
callq 0xb56e
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2735
movl $0x1, %r14d
jmp 0x7129