// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_mate.c
// Function: bam_template_cigar
void bam_template_cigar(bam1_t *b1, bam1_t *b2, kstring_t *str)
{
	bam1_t *swap;
	int i, end;
	uint32_t *cigar;
	str->l = 0;
	if (b1->core.tid != b2->core.tid || b1->core.tid < 0) return; // coordinateless or not on the same chr; skip
	if (b1->core.pos > b2->core.pos) swap = b1, b1 = b2, b2 = swap; // make sure b1 has a smaller coordinate
	kputc((b1->core.flag & BAM_FREAD1)? '1' : '2', str); // segment index
	kputc((b1->core.flag & BAM_FREVERSE)? 'R' : 'F', str); // strand
	for (i = 0, cigar = bam1_cigar(b1); i < b1->core.n_cigar; ++i) {
		kputw(bam_cigar_oplen(cigar[i]), str);
		kputc(bam_cigar_opchr(cigar[i]), str);
	}
	end = bam_calend(&b1->core, cigar);
	kputw(b2->core.pos - end, str);
	kputc('T', str);
	kputc((b2->core.flag & BAM_FREAD1)? '1' : '2', str); // segment index
	kputc((b2->core.flag & BAM_FREVERSE)? 'R' : 'F', str); // strand
	for (i = 0, cigar = bam1_cigar(b2); i < b2->core.n_cigar; ++i) {
		kputw(bam_cigar_oplen(cigar[i]), str);
		kputc(bam_cigar_opchr(cigar[i]), str);
	}
	bam_aux_append(b1, "CT", 'Z', str->l+1, (uint8_t*)str->s); 
}

// Assembly:
movq $0x0, (%rdx)
movl (%rdi), %eax
testl %eax, %eax
js 0xdc65
cmpl (%rsi), %eax
jne 0xdc65
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
movl 0x4(%rdi), %eax
cmpl 0x4(%rsi), %eax
movq %rsi, %rax
cmovgq %rdi, %rax
movq %rax, (%rsp)
cmovgq %rsi, %rbx
movabsq $0x4000000000, %r12     # imm = 0x4000000000
movq 0x8(%rbx), %r15
cmpq $0x2, 0x8(%rdx)
jb 0xdc66
movq 0x10(%r14), %rax
movl $0x1, %edx
xorl %ecx, %ecx
jmp 0xdc87
retq
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x2, %esi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
andq %r12, %r15
movabsq $0x1000000000, %r12     # imm = 0x1000000000
xorl %esi, %esi
cmpq $0x1, %r15
adcb $0x31, %sil
movq %rdx, (%r14)
movb %sil, (%rax,%rcx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq 0x8(%rbx), %r15
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xdcc7
movq 0x10(%r14), %rax
jmp 0xdd13
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
testq %r12, %r15
movl $0x46, %esi
movl $0x52, %edi
cmovel %esi, %edi
movq %rcx, (%r14)
movb %dil, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq 0x8(%rbx), %rax
movl %eax, %r15d
shrl $0x18, %r15d
addq 0x30(%rbx), %r15
shrq $0x30, %rax
je 0xddf3
xorl %r13d, %r13d
leaq 0x33518(%rip), %rbp     # 0x41270
movl (%r15,%r13,4), %edi
shrl $0x4, %edi
movq %r14, %rsi
callq 0xe09e
movl (%r15,%r13,4), %eax
andl $0xf, %eax
movb (%rax,%rbp), %r12b
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xdd85
movq 0x10(%r14), %rax
jmp 0xddd1
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r14)
movb %r12b, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
incq %r13
movzwl 0xe(%rbx), %eax
cmpq %rax, %r13
jb 0xdd58
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2343c
movq (%rsp), %rcx
movl 0x4(%rcx), %edi
subl %eax, %edi
movq %r14, %rsi
callq 0xe09e
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xde22
movq 0x10(%r14), %rax
jmp 0xde6e
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r14)
movb $0x54, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xde9b
movq 0x10(%r14), %rax
jmp 0xdee7
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
movabsq $0x1000000000, %r12     # imm = 0x1000000000
movabsq $0x1000000000000, %r13  # imm = 0x1000000000000
movabsq $0x4000000000, %rsi     # imm = 0x4000000000
andq %rsi, %r15
xorl %esi, %esi
cmpq $0x1, %r15
adcb $0x31, %sil
movq %rcx, (%r14)
movb %sil, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xdf3f
movq 0x10(%r14), %rax
jmp 0xdf8b
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
testq %r12, %r15
movl $0x46, %esi
movl $0x52, %edi
cmovel %esi, %edi
movq %rcx, (%r14)
movb %dil, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
cmpq %r13, %r15
jb 0xe073
shrl $0x18, %r15d
movq (%rsp), %rax
addq 0x30(%rax), %r15
xorl %r13d, %r13d
leaq 0x3329c(%rip), %rbp     # 0x41270
movl (%r15,%r13,4), %edi
shrl $0x4, %edi
movq %r14, %rsi
callq 0xe09e
movl (%r15,%r13,4), %eax
andl $0xf, %eax
movb (%rax,%rbp), %r12b
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x8(%r14), %rcx
jae 0xe001
movq 0x10(%r14), %rax
jmp 0xe04d
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%r14)
movb %r12b, (%rax,%rdx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
incq %r13
movq (%rsp), %rax
movzwl 0xe(%rax), %eax
cmpq %rax, %r13
jb 0xdfd4
movl (%r14), %ecx
incl %ecx
movq 0x10(%r14), %r8
leaq 0x331f8(%rip), %rsi     # 0x4127b
movq %rbx, %rdi
movl $0x5a, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x222b8