// File: /workspace/github_c_makefile_star2_O3/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 0x3ae5e
movq 0x18(%rbx), %rdx
leaq (%rdx,%rax), %rsi
decq %rax
xorl %ecx, %ecx
cmpb $0x0, (%rdx)
jne 0x3abe6
testq %rax, %rax
je 0x3abe6
cmpl $0x5, %ecx
je 0x3ae8d
leaq 0x1(%rdx), %rdi
movslq %ecx, %r8
incl %ecx
movq %rdi, (%rsp,%r8,8)
incq %rdx
decq %rax
cmpq %rsi, %rdx
jb 0x3abc6
cmpl $0x5, %ecx
jne 0x3ae60
movq (%rsp), %rax
movq %rax, 0x20(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0x28(%rbx)
movaps 0x10(%rsp), %xmm0
movups %xmm0, 0x30(%rbx)
movq 0x20(%rsp), %rdi
movq %rdi, 0x40(%rbx)
movb (%rax), %dl
movl $0x1, %r14d
movl $0x1, %ecx
testb %dl, %dl
je 0x3ac47
incq %rax
cmpb $0x2c, %dl
je 0x3ac3f
movzbl %dl, %edx
testl %edx, %edx
jne 0x3ac41
jmp 0x3ac45
incl %ecx
movb (%rax), %dl
jmp 0x3ac2e
incl %ecx
movl %ecx, 0x58(%rbx)
movq %rdi, %rax
movzbl (%rax), %ecx
cmpl $0x3a, %ecx
je 0x3ac5b
testl %ecx, %ecx
jne 0x3ac5e
jmp 0x3ac63
incl %r14d
incq %rax
jmp 0x3ac4d
movslq 0x4c(%rbx), %r12
cmpl %r12d, %r14d
jle 0x3acd2
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
movq 0x40(%rbx), %rdi
movl %r14d, 0x48(%rbx)
leaq 0x7154(%rip), %rsi      # 0x41e31
leaq 0x30(%rsp), %rdx
callq 0x21c66
testq %rax, %rax
je 0x3ad50
xorl %ecx, %ecx
movl $0x3, %ebp
leaq 0x30(%rsp), %r14
movl 0x58(%rsp), %edx
subl %eax, %edx
movl $0x0, %esi
testl %edx, %edx
jle 0x3ad2d
decl %edx
cmpl $0x3, %edx
cmovael %ebp, %edx
incl %edx
xorl %edi, %edi
xorl %esi, %esi
movsbl (%rax,%rdi), %r8d
testl %r8d, %r8d
je 0x3ad2d
shll $0x8, %esi
orl %r8d, %esi
incq %rdi
cmpq %rdi, %rdx
jne 0x3ad15
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 0x21c66
movq %r12, %rcx
testq %rax, %rax
jne 0x3acf8
cmpl $0x0, 0x48(%rbx)
jle 0x3ae4f
movq 0x50(%rbx), %rcx
movl $0x8, %r14d
xorl %r12d, %r12d
movl -0x8(%rcx,%r14), %eax
cmpl $0x4753, %eax           # imm = 0x4753
jg 0x3ad8d
cmpl $0x474b, %eax           # imm = 0x474B
jg 0x3adb2
cmpl $0x4450, %eax           # imm = 0x4450
je 0x3ada2
cmpl $0x4456, %eax           # imm = 0x4456
je 0x3ada2
jmp 0x3ae1e
cmpl $0x504b, %eax           # imm = 0x504B
jg 0x3add0
cmpl $0x4754, %eax           # imm = 0x4754
je 0x3adc0
cmpl $0x4851, %eax           # imm = 0x4851
jne 0x3ae1e
movl $0x2, -0x4(%rcx,%r14)
movl $0x2, %eax
jmp 0x3ae23
cmpl $0x474c, %eax           # imm = 0x474C
je 0x3adf2
cmpl $0x4751, %eax           # imm = 0x4751
jne 0x3ae1e
movl $0x1, -0x4(%rcx,%r14)
movl $0x1, %eax
jmp 0x3ae23
cmpl $0x5350, %eax           # imm = 0x5350
je 0x3ae0e
cmpl $0x504c, %eax           # imm = 0x504C
jne 0x3ae1e
movl 0x58(%rbx), %eax
leal 0x1(%rax), %edx
imull %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
addl %edx, %eax
sarl %eax
jmp 0x3ae07
movl 0x58(%rbx), %eax
leal 0x1(%rax), %edx
imull %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
addl %edx, %eax
addl %eax, %eax
andl $-0x4, %eax
movl %eax, -0x4(%rcx,%r14)
jmp 0x3ae23
movl $0x4, -0x4(%rcx,%r14)
movl $0x4, %eax
jmp 0x3ae23
movl -0x4(%rcx,%r14), %eax
movq (%rcx,%r14), %rdi
movslq %eax, %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 0x3ad67
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
movq 0x15181(%rip), %rax     # 0x4ffe8
movq (%rax), %rdi
movl (%rbx), %r8d
movl 0x4(%rbx), %r9d
leaq 0xaf13(%rip), %rsi      # 0x45d8b
leaq 0xaf40(%rip), %rdx      # 0x45dbf
xorl %eax, %eax
callq 0x3750
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3ae51
movl $0x6, %ecx
jmp 0x3ae60