// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/misc/maq2sam.c
// Function: maq2tam_core
void maq2tam_core(gzFile fp, const char *rg)
{
	maqmap_t *mm;
	maqmap1_t mm1, *m1;
	int ret;
	m1 = &mm1;
	mm = maqmap_read_header(fp);
	while ((ret = gzread(fp, m1, sizeof(maqmap1_t))) == sizeof(maqmap1_t)) {
		int j, flag = 0, se_mapq = m1->seq[MAX_READLEN-1];
		if (m1->flag) flag |= 1;
		if ((m1->flag&PAIRFLAG_PAIRED) || ((m1->flag&PAIRFLAG_SW) && m1->flag != 192)) flag |= 2;
		if (m1->flag == 192) flag |= 4;
		if (m1->flag == 64) flag |= 8;
		if (m1->pos&1) flag |= 0x10;
		if ((flag&1) && m1->dist != 0) {
			int c;
			if (m1->dist > 0) {
				if (m1->flag&(PAIRFLAG_FF|PAIRFLAG_RF)) c = 0;
				else if (m1->flag&(PAIRFLAG_FR|PAIRFLAG_RR)) c = 1;
				else c = m1->pos&1;				
			} else {
				if (m1->flag&(PAIRFLAG_FF|PAIRFLAG_FR)) c = 0;
				else if (m1->flag&(PAIRFLAG_RF|PAIRFLAG_RR)) c = 1;
				else c = m1->pos&1;
			}
			if (c) flag |= 0x20;
		}
		if (m1->flag) {
			int l = strlen(m1->name);
			if (m1->name[l-2] == '/') {
				flag |= (m1->name[l-1] == '1')? 0x40 : 0x80;
				m1->name[l-2] = '\0';
			}
		}
		printf("%s\t%d\t", m1->name, flag);
		printf("%s\t%d\t", mm->ref_name[m1->seqid], (m1->pos>>1)+1);
		if (m1->flag == 130) {
			int c = (int8_t)m1->seq[MAX_READLEN-1];
			printf("%d\t", m1->alt_qual);
			if (c == 0) printf("%dM\t", m1->size);
			else {
				if (c > 0) printf("%dM%dI%dM\t", m1->map_qual, c, m1->size - m1->map_qual - c);
				else printf("%dM%dD%dM\t", m1->map_qual, -c, m1->size - m1->map_qual);
			}
			se_mapq = 0; // zero SE mapQ for reads aligned by SW
		} else {
			if (flag&4) printf("0\t*\t");
			else printf("%d\t%dM\t", m1->map_qual, m1->size);
		}
		printf("*\t0\t%d\t", m1->dist);
		for (j = 0; j != m1->size; ++j) {
			if (m1->seq[j] == 0) putchar('N');
			else putchar("ACGT"[m1->seq[j]>>6&3]);
		}
		putchar('\t');
		for (j = 0; j != m1->size; ++j)
			putchar((m1->seq[j]&0x3f) + 33);
		putchar('\t');
		if (rg) printf("RG:Z:%s\t", rg);
		if (flag&4) { // unmapped
			printf("MF:i:%d\n", m1->flag);
		} else {
			printf("MF:i:%d\t", m1->flag);
			if (m1->flag) printf("AM:i:%d\tSM:i:%d\t", m1->alt_qual, se_mapq);
			printf("NM:i:%d\tUQ:i:%d\tH0:i:%d\tH1:i:%d\n", m1->info1&0xf, m1->info2, m1->c[0], m1->c[1]);
		}
	}
	if (ret > 0)
		fprintf(stderr, "Truncated! Continue anyway.\n");
	maq_delete_maqmap(mm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
movq %rdi, %r15
callq 0x1314
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movl $0xb8, %edx
callq 0x10c0
cmpl $0xb8, %eax
jne 0x17a2
leaq 0xc7e(%rip), %r13       # 0x20e1
movzbl 0x96(%rsp), %eax
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
testb $0x10, %al
jne 0x1489
testb %al, %al
setns %dl
cmpl $0xc0, %eax
sete %sil
orb %dl, %sil
jne 0x148c
orl $0x2, %ecx
leal 0x4(%rcx), %edx
cmpl $0xc0, %eax
cmovnel %ecx, %edx
leal 0x8(%rdx), %esi
cmpl $0x40, %eax
cmovnel %edx, %esi
movl 0x9c(%rsp), %ecx
andl $0x1, %ecx
movl %ecx, %ebp
shll $0x4, %ebp
orl %esi, %ebp
testb $0x1, %sil
je 0x14e7
cmpl $0x0, 0xa0(%rsp)
je 0x14e7
jle 0x14cb
testb $0x5, %al
jne 0x14cf
testb $0xa, %al
jmp 0x14d5
testb $0x3, %al
je 0x14d3
xorl %ecx, %ecx
jmp 0x14dd
testb $0xc, %al
movl $0x1, %edx
cmovnel %edx, %ecx
leal 0x20(%rbp), %edx
testl %ecx, %ecx
cmovel %ebp, %edx
movl %edx, %ebp
movb 0x8f(%rsp), %bl
testl %eax, %eax
je 0x154c
leaq 0xa4(%rsp), %rdi
callq 0x1070
shlq $0x20, %rax
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %rax, %rcx
sarq $0x20, %rcx
cmpb $0x2f, 0xa4(%rsp,%rcx)
jne 0x154c
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %rax
sarq $0x20, %rax
xorl %edx, %edx
cmpb $0x31, 0xa4(%rsp,%rax)
setne %dl
shll $0x6, %edx
addl %edx, %ebp
addl $0x40, %ebp
movb $0x0, 0xa4(%rsp,%rcx)
leaq 0xb5c(%rip), %r12       # 0x20af
movq %r12, %rdi
leaq 0xa4(%rsp), %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1080
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x98(%rsp), %ecx
movl 0x9c(%rsp), %edx
movq (%rax,%rcx,8), %rsi
shrl %edx
incl %edx
movq %r12, %rdi
xorl %eax, %eax
callq 0x1080
cmpb $-0x7e, 0x96(%rsp)
jne 0x15e3
movsbl 0x8f(%rsp), %r12d
movzbl 0x97(%rsp), %esi
leaq 0xb2b(%rip), %rdi       # 0x20dd
xorl %eax, %eax
callq 0x1080
testl %r12d, %r12d
je 0x1619
testb %r12b, %r12b
jle 0x1633
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %ecx
subl %esi, %ecx
subl %r12d, %ecx
xorl %ebx, %ebx
leaq 0xad5(%rip), %rdi       # 0x20b6
jmp 0x1651
testb $0x4, %bpl
jne 0x1609
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %edx
leaq 0xad1(%rip), %rdi       # 0x20d1
xorl %eax, %eax
callq 0x1080
jmp 0x165b
leaq 0xabc(%rip), %rdi       # 0x20cc
xorl %eax, %eax
callq 0x1080
jmp 0x165b
movzbl 0x90(%rsp), %esi
xorl %ebx, %ebx
leaq 0xaaa(%rip), %rdi       # 0x20d4
xorl %eax, %eax
callq 0x1080
jmp 0x165b
negl %r12d
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %ecx
subl %esi, %ecx
xorl %ebx, %ebx
leaq 0xa70(%rip), %rdi       # 0x20c1
movl %r12d, %edx
xorl %eax, %eax
callq 0x1080
movl 0xa0(%rsp), %esi
leaq 0xa70(%rip), %rdi       # 0x20d9
xorl %eax, %eax
callq 0x1080
cmpb $0x0, 0x90(%rsp)
je 0x16ac
xorl %r12d, %r12d
movzbl 0x10(%rsp,%r12), %eax
testq %rax, %rax
je 0x1692
shrl $0x6, %eax
movsbl (%rax,%r13), %edi
jmp 0x1697
movl $0x4e, %edi
callq 0x1050
incq %r12
movzbl 0x90(%rsp), %eax
cmpq %rax, %r12
jne 0x167d
movl $0x9, %edi
callq 0x1050
cmpb $0x0, 0x90(%rsp)
je 0x16e4
xorl %r12d, %r12d
movzbl 0x10(%rsp,%r12), %edi
andl $0x3f, %edi
addl $0x21, %edi
callq 0x1050
incq %r12
movzbl 0x90(%rsp), %eax
cmpq %rax, %r12
jne 0x16c3
movl $0x9, %edi
callq 0x1050
testq %r14, %r14
je 0x1704
leaq 0x9ec(%rip), %rdi       # 0x20e6
movq %r14, %rsi
xorl %eax, %eax
callq 0x1080
movzbl 0x96(%rsp), %esi
testb $0x4, %bpl
jne 0x1777
leaq 0x9df(%rip), %rdi       # 0x20f8
xorl %eax, %eax
callq 0x1080
cmpb $0x0, 0x96(%rsp)
je 0x1743
movzbl %bl, %edx
movzbl 0x97(%rsp), %esi
leaq 0x9c5(%rip), %rdi       # 0x2101
xorl %eax, %eax
callq 0x1080
movzbl 0x92(%rsp), %esi
andl $0xf, %esi
movzbl 0x93(%rsp), %edx
movzbl 0x94(%rsp), %ecx
movzbl 0x95(%rsp), %r8d
leaq 0x9a4(%rip), %rdi       # 0x2112
xorl %eax, %eax
callq 0x1080
jmp 0x1785
leaq 0x971(%rip), %rdi       # 0x20ef
xorl %eax, %eax
callq 0x1080
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
movl $0xb8, %edx
callq 0x10c0
cmpl $0xb8, %eax
je 0x1463
testl %eax, %eax
jg 0x17c2
movq 0x8(%rsp), %rdi
callq 0x12c4
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1165
jmp 0x17a6