// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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 0x1304
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movl $0xb8, %edx
callq 0x10b0
cmpl $0xb8, %eax
jne 0x177e
leaq 0xc8e(%rip), %r13       # 0x20e1
movzbl 0x96(%rsp), %eax
testb $0x10, %al
jne 0x147e
xorl %ecx, %ecx
testl %eax, %eax
setne %dl
testb %al, %al
setns %sil
cmpl $0xc0, %eax
sete %dil
orb %sil, %dil
je 0x147e
movb %dl, %cl
jmp 0x1483
movl $0x3, %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 0x14d3
cmpl $0x0, 0xa0(%rsp)
je 0x14d3
jle 0x14c4
testb $0x5, %al
jne 0x14d3
testb $0xa, %al
jne 0x14d0
jmp 0x14cc
testb $0x3, %al
jne 0x14d3
testb $0xc, %al
jne 0x14d0
testl %ecx, %ecx
je 0x14d3
orl $0x20, %ebp
movb 0x8f(%rsp), %bl
testl %eax, %eax
je 0x1538
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 0x1538
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 0xb70(%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 0x15cf
movsbl 0x8f(%rsp), %r12d
movzbl 0x97(%rsp), %esi
leaq 0xb3f(%rip), %rdi       # 0x20dd
xorl %eax, %eax
callq 0x1080
testl %r12d, %r12d
je 0x1605
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %ecx
testb %r12b, %r12b
jle 0x161f
subl %esi, %ecx
subl %r12d, %ecx
xorl %ebx, %ebx
leaq 0xae9(%rip), %rdi       # 0x20b6
jmp 0x162d
testb $0x4, %bpl
jne 0x15f5
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %edx
leaq 0xae5(%rip), %rdi       # 0x20d1
xorl %eax, %eax
callq 0x1080
jmp 0x1637
leaq 0xad0(%rip), %rdi       # 0x20cc
xorl %eax, %eax
callq 0x1080
jmp 0x1637
movzbl 0x90(%rsp), %esi
xorl %ebx, %ebx
leaq 0xabe(%rip), %rdi       # 0x20d4
xorl %eax, %eax
callq 0x1080
jmp 0x1637
negl %r12d
subl %esi, %ecx
xorl %ebx, %ebx
leaq 0xa94(%rip), %rdi       # 0x20c1
movl %r12d, %edx
xorl %eax, %eax
callq 0x1080
movl 0xa0(%rsp), %esi
leaq 0xa94(%rip), %rdi       # 0x20d9
xorl %eax, %eax
callq 0x1080
cmpb $0x0, 0x90(%rsp)
je 0x1688
xorl %r12d, %r12d
movzbl 0x10(%rsp,%r12), %eax
testq %rax, %rax
je 0x166e
shrl $0x6, %eax
movsbl (%rax,%r13), %edi
jmp 0x1673
movl $0x4e, %edi
callq 0x1050
incq %r12
movzbl 0x90(%rsp), %eax
cmpq %rax, %r12
jne 0x1659
movl $0x9, %edi
callq 0x1050
cmpb $0x0, 0x90(%rsp)
je 0x16c0
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 0x169f
movl $0x9, %edi
callq 0x1050
testq %r14, %r14
je 0x16e0
leaq 0xa10(%rip), %rdi       # 0x20e6
movq %r14, %rsi
xorl %eax, %eax
callq 0x1080
movzbl 0x96(%rsp), %esi
testb $0x4, %bpl
jne 0x1753
leaq 0xa03(%rip), %rdi       # 0x20f8
xorl %eax, %eax
callq 0x1080
cmpb $0x0, 0x96(%rsp)
je 0x171f
movzbl %bl, %edx
movzbl 0x97(%rsp), %esi
leaq 0x9e9(%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 0x9c8(%rip), %rdi       # 0x2112
xorl %eax, %eax
callq 0x1080
jmp 0x1761
leaq 0x995(%rip), %rdi       # 0x20ef
xorl %eax, %eax
callq 0x1080
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
movl $0xb8, %edx
callq 0x10b0
cmpl $0xb8, %eax
je 0x1453
testl %eax, %eax
jg 0x179e
movq 0x8(%rsp), %rdi
callq 0x12b4
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1155
jmp 0x1782