// File: /workspace/github_c_makefile_star2_O1/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 0xdd76
cmpl (%rsi), %eax
jne 0xdd76
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 $0x1, 0x8(%rdx)
ja 0xd96e
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x2, %esi
callq 0x3720
movq %rax, 0x10(%r14)
andq %r12, %r15
movabsq $0x1000000000, %r12     # imm = 0x1000000000
xorl %eax, %eax
cmpq $0x1, %r15
adcb $0x31, %al
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movb %al, (%rdx,%rcx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq 0x8(%rbx), %r15
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
jb 0xd9f4
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
testq %r12, %r15
movl $0x46, %eax
movl $0x52, %ecx
cmovel %eax, %ecx
movq (%r14), %rax
movq 0x10(%r14), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%r14)
movb %cl, (%rdx,%rax)
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 0xdadb
xorl %r13d, %r13d
leaq 0x327ed(%rip), %rbp     # 0x40230
movl (%r15,%r13,4), %edi
shrl $0x4, %edi
movq %r14, %rsi
callq 0xdd77
movl (%r15,%r13,4), %eax
andl $0xf, %eax
movb (%rax,%rbp), %r12b
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
jb 0xdaae
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movb %r12b, (%rcx,%rax)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
incq %r13
movzwl 0xe(%rbx), %eax
cmpq %rax, %r13
jb 0xda43
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22d1c
movq (%rsp), %rcx
movl 0x4(%rcx), %edi
subl %eax, %edi
movq %r14, %rsi
callq 0xdd77
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
jb 0xdb48
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movb $0x54, (%rcx,%rax)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
movabsq $0x4000000000, %r12     # imm = 0x4000000000
jb 0xdbc8
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movabsq $0x1000000000000, %r13  # imm = 0x1000000000000
andq %r12, %r15
xorl %eax, %eax
cmpq $0x1, %r15
adcb $0x31, %al
movq (%r14), %rcx
movq 0x10(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movb %al, (%rdx,%rcx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
movabsq $0x1000000000, %r12     # imm = 0x1000000000
jb 0xdc5c
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
testq %r12, %r15
movl $0x46, %eax
movl $0x52, %ecx
cmovel %eax, %ecx
movq (%r14), %rax
movq 0x10(%r14), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, (%r14)
movb %cl, (%rdx,%rax)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rax
movq 0x8(%rax), %r15
cmpq %r13, %r15
jb 0xdd4b
shrl $0x18, %r15d
movq (%rsp), %rax
addq 0x30(%rax), %r15
xorl %r13d, %r13d
leaq 0x32581(%rip), %rbp     # 0x40230
movl (%r15,%r13,4), %edi
shrl $0x4, %edi
movq %r14, %rsi
callq 0xdd77
movl (%r15,%r13,4), %eax
andl $0xf, %eax
movb (%rax,%rbp), %r12b
movq (%r14), %rax
incq %rax
cmpq 0x8(%r14), %rax
jb 0xdd1a
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
callq 0x3720
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movb %r12b, (%rcx,%rax)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
incq %r13
movq (%rsp), %rax
movzwl 0xe(%rax), %eax
cmpq %rax, %r13
jb 0xdcaf
movl (%r14), %ecx
incl %ecx
movq 0x10(%r14), %r8
leaq 0x324e0(%rip), %rsi     # 0x4023b
movq %rbx, %rdi
movl $0x5a, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21bc8
retq