// File: /workspace/github_c_makefile_star2_O0/lh3[P]bgt/atomic.c
// Function: bcf_atomize
void bcf_atomize(const bcf_hdr_t *h, bcf1_t *b, bcf_atom_v *a)
{
	int i, cid, l_ref, l_cigar = 0;
	kstring_t cigar = {0,0,0};
	char *p_cigar = 0;

	for (i = 0; i < a->n; ++i)
		a->a[i].from_new = 0;

	cid = bcf_id2int(h, BCF_DT_ID, "CIGAR");
	if (cid >= 0) {
		bcf_unpack(b, BCF_UN_INFO);
		for (i = 0; i < b->n_info; ++i)
			if (b->d.info[i].key == cid) break;
		if (i < b->n_info && b->d.info[i].type == BCF_BT_CHAR) { // CIGAR in INFO
			p_cigar = (char*)b->d.info[i].vptr;
			l_cigar = b->d.info[i].len;
		}
	} else bcf_unpack(b, BCF_UN_STR);
	l_ref = strlen(b->d.allele[0]);

	for (i = 1; i < b->n_allele; ++i) { // traverse each allele
		char *p;
		int x, y, j, l, l_alt;
		l_alt = strlen(b->d.allele[i]);
		if (b->rlen != l_ref || (b->d.allele[i][0] == '<' && b->d.allele[i][l_alt-1] == '>')) { // symbolic allele
			bcf_add_atom(a, b->rid, b->pos, b->rlen, i, -1, b->d.allele[0], -1, b->d.allele[i]);
			continue;
		}
		// extract or generate CIGAR between REF and the current ALT
		cigar.l = 0;
		if (p_cigar) {
			for (p = p_cigar; p < p_cigar + l_cigar && *p != ','; ++p);
			assert(p - p_cigar > 0); // otherwise, incomplete CIGAR
			kputsn(p_cigar, p - p_cigar, &cigar);
			l_cigar -= p + 1 - p_cigar;
			p_cigar = p + 1;
		} else if (strlen(b->d.allele[i]) == b->rlen) {
			kputw(b->rlen, &cigar);
			kputc('M', &cigar);
		} else {
			int rest;
			l = l_alt - b->rlen;
			kputsn("1M", 2, &cigar);
			if (l > 0) {
				kputw(l, &cigar);
				kputc('I', &cigar);
				rest = b->rlen - 1;
			} else {
				kputw(-l, &cigar);
				kputc('D', &cigar);
				rest = l_alt - 1;
			}
			if (rest) {
				kputw(rest, &cigar);
				kputc('M', &cigar);
			}
		}
		// extract difference
		x = y = 0;
		for (p = cigar.s; *p; ++p) {
			l = strtol(p, &p, 10);
			if (*p == 'M' || *p == '=' || *p == 'X') {
				for (j = 0; j < l; ++j)
					if (b->d.allele[0][x+j] != b->d.allele[i][y+j])
						bcf_add_atom(a, b->rid, b->pos + x + j, 1, i, 1, &b->d.allele[0][x+j], 1, &b->d.allele[i][y+j]);
				x += l, y += l;
			} else if (*p == 'I') {
				if (x == 0 || y == 0)
					fprintf(stderr, "[W::%s] invalid insertion (%d,%d) at %s:%d\n", __func__, x, y, h->id[BCF_DT_CTG][b->rid].key, b->pos + 1);
				else bcf_add_atom(a, b->rid, b->pos + x - 1, 1, i, 1, &b->d.allele[0][x-1], l+1, &b->d.allele[i][y-1]);
				y += l;
			} else if (*p == 'D') {
				assert(x > 0 && y > 0);
				bcf_add_atom(a, b->rid, b->pos + x - 1, l+1, i, l+1, &b->d.allele[0][x-1], 1, &b->d.allele[i][y-1]);
				x += l;
			}
		}
	}
	free(cigar.s);
	a->n = bcf_atom_gen_at(h, b, a->n, a->a);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21e0
movq $0x0, -0x48(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x167f5
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x30(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, 0x30(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x167bd
movq -0x8(%rbp), %rdi
xorl %esi, %esi
leaq 0x11b08(%rip), %rdx     # 0x2830a
callq 0x14b90
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x168cd
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x13d00
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
cmpl %ecx, %eax
jge 0x16868
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x1685b
jmp 0x16868
jmp 0x1685d
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16829
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
cmpl %ecx, %eax
jge 0x168cb
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x7, 0x4(%rax)
jne 0x168cb
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
jmp 0x168db
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x13d00
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %rdi
callq 0x2170
movl %eax, -0x24(%rbp)
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
shrq $0x10, %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
cmpl %ecx, %eax
jge 0x16e83
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2170
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x16971
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x3c, %eax
jne 0x169c9
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x64(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3e, %eax
jne 0x169c9
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0x1c(%rbp), %r8d
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %r10
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %r9
movq (%rax,%r9,8), %rax
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %r10, (%rsp)
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
callq 0x16ec0
jmp 0x16e75
movq $0x0, -0x40(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x16a9c
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
movslq -0x28(%rbp), %rax
addq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x69(%rbp)
jae 0x16a0d
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x16a16
jmp 0x16a26
jmp 0x16a18
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x169e4
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rcx, %rax
cmpq $0x0, %rax
jle 0x16a39
jmp 0x16a58
leaq 0x118d0(%rip), %rdi     # 0x28310
leaq 0x118d9(%rip), %rsi     # 0x28320
movl $0x83, %edx
leaq 0x118d6(%rip), %rcx     # 0x28329
callq 0x21b0
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
leaq -0x40(%rbp), %rdx
callq 0x17070
movq -0x50(%rbp), %rcx
addq $0x1, %rcx
movq -0x48(%rbp), %rax
subq %rax, %rcx
movslq -0x28(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x28(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x16b7b
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2170
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
jne 0x16ae1
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0x40(%rbp), %rsi
callq 0x171c0
movl $0x4d, %edi
leaq -0x40(%rbp), %rsi
callq 0x173b0
jmp 0x16b79
movl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, -0x60(%rbp)
leaq 0x11870(%rip), %rdi     # 0x28365
movl $0x2, %esi
leaq -0x40(%rbp), %rdx
callq 0x17070
cmpl $0x0, -0x60(%rbp)
jle 0x16b32
movl -0x60(%rbp), %edi
leaq -0x40(%rbp), %rsi
callq 0x171c0
movl $0x49, %edi
leaq -0x40(%rbp), %rsi
callq 0x173b0
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x16b57
xorl %edi, %edi
subl -0x60(%rbp), %edi
leaq -0x40(%rbp), %rsi
callq 0x171c0
movl $0x44, %edi
leaq -0x40(%rbp), %rsi
callq 0x173b0
movl -0x64(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
je 0x16b77
movl -0x68(%rbp), %edi
leaq -0x40(%rbp), %rsi
callq 0x171c0
movl $0x4d, %edi
leaq -0x40(%rbp), %rsi
callq 0x173b0
jmp 0x16b79
jmp 0x16b7b
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
je 0x16e73
movq -0x50(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0xa, %edx
callq 0x2280
movl %eax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x4d, %eax
je 0x16bdb
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
je 0x16bdb
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x58, %eax
jne 0x16cba
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0x16ca3
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %rax
movl -0x54(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x68(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl -0x58(%rbp), %edx
addl -0x5c(%rbp), %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x16c93
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
addl -0x54(%rbp), %edx
addl -0x5c(%rbp), %edx
movl -0x1c(%rbp), %r8d
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %r10
movl -0x54(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
addq %rax, %r10
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x58(%rbp), %ecx
addl -0x5c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl $0x1, %r9d
movl %r9d, %ecx
movq %r10, (%rsp)
movl $0x1, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x16ec0
jmp 0x16c95
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x16be2
movl -0x60(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x60(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x16e60
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x49, %eax
jne 0x16da3
cmpl $0x0, -0x54(%rbp)
je 0x16cd6
cmpl $0x0, -0x58(%rbp)
jne 0x16d24
movq 0x1731b(%rip), %rax     # 0x2dff8
movq (%rax), %rdi
movl -0x54(%rbp), %ecx
movl -0x58(%rbp), %r8d
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rdx
movslq (%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rax), %r9
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
leaq 0x11657(%rip), %rsi     # 0x28368
leaq 0x1167c(%rip), %rdx     # 0x28394
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2260
jmp 0x16d95
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
addl -0x54(%rbp), %edx
subl $0x1, %edx
movl -0x1c(%rbp), %r8d
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %r11
movl -0x54(%rbp), %eax
subl $0x1, %eax
cltq
addq %rax, %r11
movl -0x60(%rbp), %r10d
addl $0x1, %r10d
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x58(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl $0x1, %r9d
movl %r9d, %ecx
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x16ec0
movl -0x60(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x16e5e
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x44, %eax
jne 0x16e5c
cmpl $0x0, -0x54(%rbp)
jle 0x16dc1
cmpl $0x0, -0x58(%rbp)
jle 0x16dc1
jmp 0x16de0
leaq 0x115d8(%rip), %rdi     # 0x283a0
leaq 0x11551(%rip), %rsi     # 0x28320
movl $0xab, %edx
leaq 0x1154e(%rip), %rcx     # 0x28329
callq 0x21b0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
addl -0x54(%rbp), %edx
subl $0x1, %edx
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movl -0x1c(%rbp), %r8d
movl -0x60(%rbp), %r9d
addl $0x1, %r9d
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax), %r10
movl -0x54(%rbp), %eax
subl $0x1, %eax
cltq
addq %rax, %r10
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x1c(%rbp), %r11
movq (%rax,%r11,8), %rax
movl -0x58(%rbp), %r11d
subl $0x1, %r11d
movslq %r11d, %r11
addq %r11, %rax
movq %r10, (%rsp)
movl $0x1, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x16ec0
movl -0x60(%rbp), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x16e5e
jmp 0x16e60
jmp 0x16e62
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x16b91
jmp 0x16e75
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x168f5
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x174e0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)