// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/bcf.c
// Function: bcf_sync
int bcf_sync(bcf1_t *b)
{
	char *p, *tmp[5];
	int i, n, n_smpl = b->n_smpl;
	ks_tokaux_t aux;
	// set ref, alt, flt, info, fmt
	b->ref = b->alt = b->flt = b->info = b->fmt = 0;
	for (p = b->str, n = 0; p < b->str + b->l_str; ++p) {
		if (*p == 0 && p+1 != b->str + b->l_str) {
			if (n == 5) {
				++n;
				break;
			} else tmp[n++] = p + 1;
		}
	}
	if (n != 5) {
		fprintf(stderr, "[%s] incorrect number of fields (%d != 5) at %d:%d\n", __func__, n, b->tid, b->pos);
		return -1;
	}
	b->ref = tmp[0]; b->alt = tmp[1]; b->flt = tmp[2]; b->info = tmp[3]; b->fmt = tmp[4];
	// set n_alleles
	if (*b->alt == 0) b->n_alleles = 1;
	else {
		for (p = b->alt, n = 1; *p; ++p)
			if (*p == ',') ++n;
		b->n_alleles = n + 1;
	}
	// set n_gi and gi[i].fmt
	for (p = b->fmt, n = 1; *p; ++p)
		if (*p == ':') ++n;
	if (n > b->m_gi) {
		int old_m = b->m_gi;
		b->m_gi = n;
		kroundup32(b->m_gi);
		b->gi = realloc(b->gi, b->m_gi * sizeof(bcf_ginfo_t));
		memset(b->gi + old_m, 0, (b->m_gi - old_m) * sizeof(bcf_ginfo_t));
	}
	b->n_gi = n;
	for (p = kstrtok(b->fmt, ":", &aux), n = 0; p; p = kstrtok(0, 0, &aux))
		b->gi[n++].fmt = bcf_str2int(p, aux.p - p);
	// set gi[i].len
	for (i = 0; i < b->n_gi; ++i) {
		if (b->gi[i].fmt == bcf_str2int("PL", 2)) {
			b->gi[i].len = b->n_alleles * (b->n_alleles + 1) / 2;
		} else if (b->gi[i].fmt == bcf_str2int("DP", 2) || b->gi[i].fmt == bcf_str2int("HQ", 2) || b->gi[i].fmt == bcf_str2int("DV", 2)) {
			b->gi[i].len = 2;
		} else if (b->gi[i].fmt == bcf_str2int("GQ", 2) || b->gi[i].fmt == bcf_str2int("GT", 2)) {
			b->gi[i].len = 1;
		} else if (b->gi[i].fmt == bcf_str2int("SP", 2)) {
			b->gi[i].len = 4;
		} else if (b->gi[i].fmt == bcf_str2int("GL", 2)) {
			b->gi[i].len = b->n_alleles * (b->n_alleles + 1) / 2 * 4;
		}
		b->gi[i].data = realloc(b->gi[i].data, n_smpl * b->gi[i].len);
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movslq 0x5c(%rdi), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movq $0x0, 0x40(%rdi)
movslq 0x8(%rdi), %rax
testq %rax, %rax
jle 0x3a49b
movq 0x18(%rbx), %rdx
leaq (%rdx,%rax), %rsi
decq %rax
xorl %ecx, %ecx
cmpb $0x0, (%rdx)
jne 0x3a48e
testq %rax, %rax
je 0x3a48e
cmpl $0x5, %ecx
je 0x3a49f
leaq 0x1(%rdx), %rdi
movslq %ecx, %r8
incl %ecx
movq %rdi, (%rsp,%r8,8)
incq %rdx
decq %rax
cmpq %rsi, %rdx
jb 0x3a472
jmp 0x3a4a4
xorl %ecx, %ecx
jmp 0x3a4a4
movl $0x6, %ecx
cmpl $0x5, %ecx
jne 0x3a6fc
movq (%rsp), %rax
movq %rax, 0x20(%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x28(%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rbx)
movl $0x1, %r14d
cmpb $0x0, (%rcx)
movl $0x1, %edx
je 0x3a500
movzbl (%rcx), %esi
cmpl $0x2c, %esi
je 0x3a4f7
testl %esi, %esi
jne 0x3a4f9
jmp 0x3a4fe
incl %edx
incq %rcx
jmp 0x3a4e9
incl %edx
movl %edx, 0x58(%rbx)
movzbl (%rax), %ecx
cmpl $0x3a, %ecx
je 0x3a511
testl %ecx, %ecx
jne 0x3a514
jmp 0x3a519
incl %r14d
incq %rax
jmp 0x3a503
movslq 0x4c(%rbx), %r12
cmpl %r12d, %r14d
jle 0x3a584
leal -0x1(%r14), %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
movslq %ecx, %rax
movq %rax, %rsi
shlq $0x4, %rsi
incl %eax
movl %eax, 0x4c(%rbx)
movq 0x50(%rbx), %rdi
addq $0x10, %rsi
callq 0x3720
movq %rax, 0x50(%rbx)
movq %r12, %rdi
shlq $0x4, %rdi
addq %rax, %rdi
movslq 0x4c(%rbx), %rdx
subq %r12, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x3080
movl %r14d, 0x48(%rbx)
movq 0x40(%rbx), %rdi
leaq 0x685e(%rip), %rsi      # 0x40df1
leaq 0x30(%rsp), %rdx
callq 0x21696
testq %rax, %rax
je 0x3a606
xorl %ecx, %ecx
movl $0x3, %ebp
leaq 0x30(%rsp), %r14
movl 0x58(%rsp), %edx
subl %eax, %edx
movl $0x0, %esi
testl %edx, %edx
jle 0x3a5e3
decl %edx
cmpl $0x3, %edx
cmovael %ebp, %edx
incl %edx
xorl %edi, %edi
xorl %esi, %esi
movsbl (%rax,%rdi), %r8d
testl %r8d, %r8d
je 0x3a5e3
shll $0x8, %esi
orl %r8d, %esi
incq %rdi
cmpq %rdi, %rdx
jne 0x3a5cb
movq 0x50(%rbx), %rax
leaq 0x1(%rcx), %r12
shlq $0x4, %rcx
movl %esi, (%rax,%rcx)
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0x21696
movq %r12, %rcx
testq %rax, %rax
jne 0x3a5ae
cmpl $0x0, 0x48(%rbx)
jle 0x3a6ed
movl $0x8, %r14d
xorl %r12d, %r12d
movq 0x50(%rbx), %rax
movl -0x8(%rax,%r14), %edx
movl $0x2, %ecx
cmpl $0x4753, %edx           # imm = 0x4753
jg 0x3a649
cmpl $0x474b, %edx           # imm = 0x474B
jg 0x3a663
cmpl $0x4450, %edx           # imm = 0x4450
je 0x3a6ba
cmpl $0x4456, %edx           # imm = 0x4456
je 0x3a6ba
jmp 0x3a6bf
cmpl $0x504b, %edx           # imm = 0x504B
jg 0x3a67a
cmpl $0x4754, %edx           # imm = 0x4754
je 0x3a673
cmpl $0x4851, %edx           # imm = 0x4851
je 0x3a6ba
jmp 0x3a6bf
cmpl $0x474c, %edx           # imm = 0x474C
je 0x3a69e
cmpl $0x4751, %edx           # imm = 0x4751
jne 0x3a6bf
movl $0x1, %ecx
jmp 0x3a6ba
cmpl $0x5350, %edx           # imm = 0x5350
je 0x3a6b5
cmpl $0x504c, %edx           # imm = 0x504C
jne 0x3a6bf
movl 0x58(%rbx), %ecx
leal 0x1(%rcx), %edx
imull %ecx, %edx
movl %edx, %ecx
shrl $0x1f, %ecx
addl %edx, %ecx
sarl %ecx
jmp 0x3a6ba
movl 0x58(%rbx), %ecx
leal 0x1(%rcx), %edx
imull %ecx, %edx
movl %edx, %ecx
shrl $0x1f, %ecx
addl %edx, %ecx
addl %ecx, %ecx
andl $-0x4, %ecx
jmp 0x3a6ba
movl $0x4, %ecx
movl %ecx, -0x4(%rax,%r14)
movq (%rax,%r14), %rdi
movslq -0x4(%rax,%r14), %rsi
imulq %r15, %rsi
callq 0x3720
movq 0x50(%rbx), %rcx
movq %rax, (%rcx,%r14)
incq %r12
movslq 0x48(%rbx), %rax
addq $0x10, %r14
cmpq %rax, %r12
jl 0x3a619
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x148e5(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
movl (%rbx), %r8d
movl 0x4(%rbx), %r9d
leaq 0xa597(%rip), %rsi      # 0x44cab
leaq 0xa5c4(%rip), %rdx      # 0x44cdf
xorl %eax, %eax
callq 0x3750
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3a6ef