// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_aln2sam
void mem_aln2sam(const mem_opt_t *opt, const bntseq_t *bns, kstring_t *str, bseq1_t *s, int n, const mem_aln_t *list, int which, const mem_aln_t *m_)
{
	int i, l_name;
	mem_aln_t ptmp = list[which], *p = &ptmp, mtmp, *m = 0; // make a copy of the alignment to convert
	if (m_) mtmp = *m_, m = &mtmp;

	// set flag
	p->flag |= m? 0x1 : 0; // is paired in sequencing
	p->flag |= p->rid < 0? 0x4 : 0; // is mapped
	p->flag |= m && m->rid < 0? 0x8 : 0; // is mate mapped
	if (p->rid < 0 && m && m->rid >= 0) // copy mate to alignment
		p->rid = m->rid, p->pos = m->pos, p->is_rev = m->is_rev, p->n_cigar = 0;
	if (m && m->rid < 0 && p->rid >= 0) // copy alignment to mate
		m->rid = p->rid, m->pos = p->pos, m->is_rev = p->is_rev, m->n_cigar = 0;
	p->flag |= p->is_rev? 0x10 : 0; // is on the reverse strand
	p->flag |= m && m->is_rev? 0x20 : 0; // is mate on the reverse strand


	// print up to CIGAR
	l_name = strlen(s->name);
	ks_resize(str, str->l + s->l_seq + l_name + (s->qual? s->l_seq : 0) + 20);
	kputsn(s->name, l_name, str); kputc('\t', str); // QNAME
	kputw((p->flag&0xffff) | (p->flag&0x10000? 0x100 : 0), str); kputc('\t', str); // FLAG
	if (p->rid >= 0) { // with coordinate
		kputs(bns->anns[p->rid].name, str); kputc('\t', str); // RNAME
		kputl(p->pos + 1, str); kputc('\t', str); // POS
		kputw(p->mapq, str); kputc('\t', str); // MAPQ
		if (p->n_cigar) { // aligned
			for (i = 0; i < p->n_cigar; ++i) {
				int c = p->cigar[i]&0xf;
				if (!(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt && (c == 3 || c == 4))
					c = which? 4 : 3; // use hard clipping for supplementary alignments
				kputw(p->cigar[i]>>4, str); kputc("MIDSH"[c], str);
			}
		} else kputc('*', str); // having a coordinate but unaligned (e.g. when copy_mate is true)
	} else kputsn("*\t0\t0\t*", 7, str); // without coordinte
	kputc('\t', str);

	// print the mate position if applicable
	if (m && m->rid >= 0) {
		if (p->rid == m->rid) kputc('=', str);
		else kputs(bns->anns[m->rid].name, str);
		kputc('\t', str);
		kputl(m->pos + 1, str); kputc('\t', str);
		if (p->rid == m->rid) {
			int64_t p0 = p->pos + (p->is_rev? get_rlen(p->n_cigar, p->cigar) - 1 : 0);
			int64_t p1 = m->pos + (m->is_rev? get_rlen(m->n_cigar, m->cigar) - 1 : 0);
			if (m->n_cigar == 0 || p->n_cigar == 0) kputc('0', str);
			else kputl(-(p0 - p1 + (p0 > p1? 1 : p0 < p1? -1 : 0)), str);
		} else kputc('0', str);
	} else kputsn("*\t0\t0", 5, str);
	kputc('\t', str);

	// print SEQ and QUAL
	if (p->flag & 0x100) { // for secondary alignments, don't write SEQ and QUAL
		kputsn("*\t*", 3, str);
	} else if (!p->is_rev) { // the forward strand
		int i, qb = 0, qe = s->l_seq;
		if (p->n_cigar && which && !(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt) { // have cigar && not the primary alignment && not softclip all
			if ((p->cigar[0]&0xf) == 4 || (p->cigar[0]&0xf) == 3) qb += p->cigar[0]>>4;
			if ((p->cigar[p->n_cigar-1]&0xf) == 4 || (p->cigar[p->n_cigar-1]&0xf) == 3) qe -= p->cigar[p->n_cigar-1]>>4;
		}
		ks_resize(str, str->l + (qe - qb) + 1);
		//OLD for (i = qb; i < qe; ++i) str->s[str->l++] = "ACGTN"[(int)s->seq[i]];
		for (i = qb; i < qe; ++i) str->s[(int)(str->l++)] = aa_ascii_hash[(int)(s->seq[i])];
		kputc('\t', str);
		if (s->qual) { // printf qual
			ks_resize(str, str->l + (qe - qb) + 1);
			for (i = qb; i < qe; ++i) str->s[str->l++] = s->qual[i];
			str->s[str->l] = 0;
		} else kputc('*', str);
	} else { // the reverse strand
		int i, qb = 0, qe = s->l_seq;
		if (p->n_cigar && which && !(opt->flag&MEM_F_SOFTCLIP) && !p->is_alt) {
			if ((p->cigar[0]&0xf) == 4 || (p->cigar[0]&0xf) == 3) qe -= p->cigar[0]>>4;
			if ((p->cigar[p->n_cigar-1]&0xf) == 4 || (p->cigar[p->n_cigar-1]&0xf) == 3) qb += p->cigar[p->n_cigar-1]>>4;
		}
		ks_resize(str, str->l + (qe - qb) + 1);
		//OLD for (i = qe-1; i >= qb; --i) str->s[str->l++] = "TGCAN"[(int)s->seq[i]];
		for (i = qe-1; i >= qb; --i) str->s[(int)(str->l++)] = aa_ascii_hash[(int)(s->seq[i])];
		kputc('\t', str);
		if (s->qual) { // printf qual
			ks_resize(str, str->l + (qe - qb) + 1);
			for (i = qe-1; i >= qb; --i) str->s[str->l++] = s->qual[i];
			str->s[str->l] = 0;
		} else kputc('*', str);
	}

	// print optional tags
	if (p->n_cigar) {
		kputsn("\tNM:i:", 6, str); kputw(p->NM, str);
		kputsn("\tMD:Z:", 6, str); kputs((char*)(p->cigar + p->n_cigar), str);
	}
	if (p->score >= 0) { kputsn("\tAS:i:", 6, str); kputw(p->score, str); }
	if (p->sub >= 0) { kputsn("\tXS:i:", 6, str); kputw(p->sub, str); }
	if (bwa_rg_id[0]) { kputsn("\tRG:Z:", 6, str); kputs(bwa_rg_id, str); }
	if (!(p->flag & 0x100)) { // not multi-hit
		for (i = 0; i < n; ++i)
			if (i != which && !(list[i].flag&0x100)) break;
		if (i < n) { // there are other primary hits; output them
			kputsn("\tSA:Z:", 6, str);
			for (i = 0; i < n; ++i) {
				const mem_aln_t *r = &list[i];
				int k;
				if (i == which || (r->flag&0x100)) continue; // proceed if: 1) different from the current; 2) not shadowed multi hit
				kputs(bns->anns[r->rid].name, str); kputc(',', str);
				kputl(r->pos+1, str); kputc(',', str);
				kputc("+-"[r->is_rev], str); kputc(',', str);
				for (k = 0; k < r->n_cigar; ++k) {
					kputw(r->cigar[k]>>4, str); kputc("MIDSH"[r->cigar[k]&0xf], str);
				}
				kputc(',', str); kputw(r->mapq, str);
				kputc(',', str); kputw(r->NM, str);
				kputc(';', str);
			}
		}
		if (p->alt_sc > 0)
			ksprintf(str, "\tpa:f:%.3f", (double)p->score / p->alt_sc);
	}
	if (p->XA) { kputsn("\tXA:Z:", 6, str); kputs(p->XA, str); }
	if (s->comment) { kputc('\t', str); kputs(s->comment, str); }
	if ((opt->flag&MEM_F_REF_HDR) && p->rid >= 0 && bns->anns[p->rid].anno != 0 && bns->anns[p->rid].anno[0] != 0) {
		int tmp;
		kputsn("\tXR:Z:", 6, str);
		tmp = str->l;
		kputs(bns->anns[p->rid].anno, str);
		for (i = tmp; i < str->l; ++i) // replace TAB in the comment to SPACE
			if (str->s[i] == '\t') str->s[i] = ' ';
	}
	kputc('\n', str);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r8, 0x60(%rsp)
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdi, 0x50(%rsp)
movslq 0xf0(%rsp), %rcx
movq 0xf8(%rsp), %rdx
movq %rcx, 0x58(%rsp)
imulq $0x38, %rcx, %rax
movl 0x8(%r9,%rax), %r12d
xorl %ecx, %ecx
testq %rdx, %rdx
movq %r9, 0x28(%rsp)
je 0x191e0
movq 0x30(%rdx), %rsi
leaq 0x80(%rsp), %r11
movq %rsi, 0x30(%r11)
movq 0x28(%rsp), %r9
movupd (%rdx), %xmm0
movupd 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movaps %xmm2, 0x20(%r11)
movapd %xmm1, 0x10(%r11)
movapd %xmm0, (%r11)
jmp 0x191e3
xorl %r11d, %r11d
movq (%r9,%rax), %rdx
movq %rdx, 0x48(%rsp)
movl 0xc(%r9,%rax), %edx
movl %edx, 0x1c(%rsp)
movl 0x10(%r9,%rax), %r14d
movl 0x14(%r9,%rax), %r10d
movl %r12d, %r13d
shrl $0x1d, %r13d
andl $-0x4, %r13d
xorl %ebp, %ebp
testq %r11, %r11
setne %bpl
movq %r11, 0x8(%rsp)
movl %ebp, 0x20(%rsp)
je 0x1925e
movl 0x8(%r11), %edx
movl %edx, %ecx
shrl $0x1f, %ecx
movl %r12d, %edi
testl %r12d, %r12d
js 0x19264
testl %edx, %edx
jns 0x19288
movl %edi, 0x8(%r11)
movq 0x48(%rsp), %rdx
movq %rdx, (%r11)
movl %r14d, %edx
andl $0x1, %edx
movl 0x10(%r11), %esi
andl $-0x2, %esi
orl %edx, %esi
movl %esi, 0x10(%r11)
movq 0x28(%rsp), %r9
andl $0x0, 0x14(%r11)
jmp 0x19288
movl %r10d, (%rsp)
jmp 0x192a0
testl %edx, %edx
js 0x19288
movq (%r11), %rsi
movq %rsi, 0x48(%rsp)
movl 0x10(%r11), %esi
andl $0x1, %esi
andl $-0x2, %r14d
orl %esi, %r14d
movq 0x28(%rsp), %r9
xorl %r10d, %r10d
jmp 0x1928a
movl %edi, %edx
movl %r10d, (%rsp)
leal (%r13,%rcx,8), %r13d
movl 0x10(%r11), %ecx
shll $0x5, %ecx
andl $0x20, %ecx
movl %edx, %r12d
movl %r14d, 0x14(%rsp)
movq 0x18(%r9,%rax), %rdx
movq %rdx, 0x38(%rsp)
movq 0x20(%r9,%rax), %rdx
movq %rdx, 0x78(%rsp)
movl 0x28(%r9,%rax), %edx
movl %edx, 0x4(%rsp)
movl 0x2c(%r9,%rax), %edx
movl %edx, 0x6c(%rsp)
movl 0x30(%r9,%rax), %eax
movl %eax, 0x44(%rsp)
andl $0x1, %r14d
movl %r14d, 0x40(%rsp)
shll $0x4, %r14d
orl %ecx, %r14d
movq 0x8(%r15), %rdi
callq 0x3100
movslq (%r15), %rcx
movslq %eax, %rbp
movq 0x20(%r15), %rax
testq %rax, %rax
cmovneq %rcx, %rax
movq (%rbx), %rdx
addq %rbp, %rdx
addq %rcx, %rdx
leaq (%rax,%rdx), %rsi
addq $0x14, %rsi
movq %rbx, %rdi
callq 0x19b95
movq 0x8(%r15), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x19bfa
pushq $0x9
popq %rbp
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movl 0x1c(%rsp), %edi
movzwl %di, %eax
orl 0x20(%rsp), %eax
shrl $0x8, %edi
andl $0x100, %edi            # imm = 0x100
orl %eax, %edi
orl %r13d, %edi
orl %r14d, %edi
movq %rbx, %rsi
callq 0x19d33
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movl %r12d, %ecx
testl %r12d, %r12d
movq %r15, 0x20(%rsp)
movl %r12d, 0x18(%rsp)
movq %rcx, 0x70(%rsp)
js 0x19464
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, %rcx, %rcx
movq 0x18(%rax,%rcx), %rdi
movq %rbx, %rsi
callq 0x19e09
pushq $0x9
popq %rbp
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movq 0x48(%rsp), %rax
leaq 0x1(%rax), %rdi
movq %rbx, %rsi
callq 0x19e2c
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movl 0x14(%rsp), %r15d
movl %r15d, %eax
shrl $0x2, %eax
movzbl %al, %edi
movq %rbx, %rsi
callq 0x19d33
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movl (%rsp), %eax
testl %eax, %eax
je 0x19478
cmpl $0x1, 0x58(%rsp)
pushq $0x4
popq %rbp
sbbl $0x0, %ebp
xorl %r14d, %r14d
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
andl $0x2, %r15d
cmpq %r14, %r13
je 0x19483
movq 0x38(%rsp), %rax
movl (%rax,%r14,4), %edi
movl %edi, %r12d
andl $0xf, %r12d
leal -0x3(%r12), %ecx
movl %ebp, %eax
cmpl $0x2, %ecx
jb 0x1942a
movl %r12d, %eax
movq 0x50(%rsp), %rcx
movl 0x48(%rcx), %ecx
movl $0x200, %edx            # imm = 0x200
andl %edx, %ecx
orl %r15d, %ecx
cmovel %eax, %r12d
shrl $0x4, %edi
movq %rbx, %rsi
callq 0x19d33
leaq 0xaa16(%rip), %rax      # 0x23e68
movsbl (%r12,%rax), %edi
movq %rbx, %rsi
callq 0x19c9f
incq %r14
jmp 0x19406
leaq 0xaa03(%rip), %rdi      # 0x23e6e
pushq $0x7
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
jmp 0x19483
pushq $0x2a
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x194be
movslq 0x8(%r15), %rax
testq %rax, %rax
js 0x194be
movl 0x18(%rsp), %ecx
movl %ecx, %r13d
cmpl %eax, %ecx
movl 0x4(%rsp), %r14d
jne 0x194e1
pushq $0x3d
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
jmp 0x194fb
leaq 0xa9b1(%rip), %rdi      # 0x23e76
pushq $0x5
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movq 0x20(%rsp), %r12
movl 0x18(%rsp), %r13d
movl 0x4(%rsp), %r14d
jmp 0x19554
movq 0x30(%rsp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, %rax, %rax
movq 0x18(%rcx,%rax), %rdi
movq %rbx, %rsi
callq 0x19e09
movq 0x20(%rsp), %r12
pushq $0x9
popq %rbp
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
movq 0x8(%rsp), %r15
movq (%r15), %rdi
incq %rdi
movq %rbx, %rsi
callq 0x19e2c
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19c9f
cmpl 0x8(%r15), %r13d
jne 0x19549
cmpl $0x0, 0x40(%rsp)
movl (%rsp), %edi
jne 0x19b1d
movq %r15, %rcx
xorl %r14d, %r14d
jmp 0x19b31
pushq $0x30
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movl (%rsp), %ebp
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
btl $0x8, 0x1c(%rsp)
movslq %ebp, %r15
jb 0x19644
movq %r15, 0x8(%rsp)
movl (%r12), %r15d
testl %ebp, %ebp
setne %cl
cmpl $0x0, 0x58(%rsp)
setne %al
andb %cl, %al
cmpl $0x0, 0x40(%rsp)
jne 0x1965b
xorl %r14d, %r14d
testb %al, %al
je 0x195eb
movl $0x200, %eax            # imm = 0x200
movq 0x50(%rsp), %rcx
andl 0x48(%rcx), %eax
movl 0x14(%rsp), %ecx
andl $0x2, %ecx
orl %eax, %ecx
jne 0x195eb
movq 0x38(%rsp), %rdx
movl (%rdx), %eax
movl %eax, %ecx
andl $0xf, %ecx
addl $-0x3, %ecx
shrl $0x4, %eax
xorl %r14d, %r14d
cmpl $0x2, %ecx
cmovbl %eax, %r14d
movq 0x8(%rsp), %rax
movl -0x4(%rdx,%rax,4), %eax
movl %eax, %ecx
andl $0xf, %ecx
addl $-0x3, %ecx
cmpl $0x1, %ecx
ja 0x195eb
shrl $0x4, %eax
subl %eax, %r15d
movl %r15d, %eax
subl %r14d, %eax
movslq %eax, %rbp
incq %rbp
movq (%rbx), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
callq 0x19b95
movl %r14d, %r14d
movslq %r15d, %r15
leaq 0x1372e(%rip), %rax     # 0x2cd40
movq %r14, %rcx
cmpq %r15, %rcx
jge 0x19708
movq 0x18(%r12), %rdx
movsbq (%rdx,%rcx), %rdx
movb (%rax,%rdx), %dl
movq (%rbx), %rsi
movq 0x10(%rbx), %rdi
leaq 0x1(%rsi), %r8
movq %r8, (%rbx)
movslq %esi, %rsi
movb %dl, (%rdi,%rsi)
incq %rcx
jmp 0x19615
leaq 0xa831(%rip), %rdi      # 0x23e7c
pushq $0x3
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
jmp 0x197c8
xorl %r14d, %r14d
testb %al, %al
je 0x196b5
movl $0x200, %eax            # imm = 0x200
movq 0x50(%rsp), %rcx
andl 0x48(%rcx), %eax
movl 0x14(%rsp), %ecx
andl $0x2, %ecx
orl %eax, %ecx
jne 0x196b5
movq 0x38(%rsp), %rsi
movl (%rsi), %eax
movl %eax, %ecx
andl $0xf, %ecx
addl $-0x3, %ecx
shrl $0x4, %eax
xorl %edx, %edx
cmpl $0x2, %ecx
cmovael %edx, %eax
subl %eax, %r15d
movq 0x8(%rsp), %rax
movl -0x4(%rsi,%rax,4), %r14d
movl %r14d, %eax
andl $0xf, %eax
addl $-0x3, %eax
shrl $0x4, %r14d
cmpl $0x2, %eax
cmovael %edx, %r14d
movl %r15d, %eax
subl %r14d, %eax
movslq %eax, %rbp
incq %rbp
movq (%rbx), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
callq 0x19b95
decl %r15d
leaq 0x13667(%rip), %rax     # 0x2cd40
movl %r15d, %ecx
cmpl %r14d, %ecx
jl 0x19754
movq 0x18(%r12), %rdx
movl %ecx, %esi
movsbq (%rdx,%rsi), %rdx
movb (%rax,%rdx), %dl
movq (%rbx), %rsi
movq 0x10(%rbx), %rdi
leaq 0x1(%rsi), %r8
movq %r8, (%rbx)
movslq %esi, %rsi
movb %dl, (%rdi,%rsi)
decl %ecx
jmp 0x196dc
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
cmpq $0x0, 0x20(%r12)
je 0x197b0
addq (%rbx), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x19b95
movl (%rsp), %ebp
cmpq %r15, %r14
jge 0x1979e
movq 0x20(%r12), %rax
movb (%rax,%r14), %al
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movb %al, (%rdx,%rcx)
incq %r14
jmp 0x19730
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
cmpq $0x0, 0x20(%r12)
je 0x197b0
addq (%rbx), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x19b95
movl (%rsp), %ebp
cmpl %r14d, %r15d
jl 0x1979e
movq 0x20(%r12), %rax
movl %r15d, %ecx
movb (%rax,%rcx), %al
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movb %al, (%rdx,%rcx)
decl %r15d
jmp 0x19778
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movl 0x4(%rsp), %r14d
jmp 0x197c3
pushq $0x2a
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movl 0x4(%rsp), %r14d
movl (%rsp), %ebp
movq 0x8(%rsp), %r15
testl %ebp, %ebp
je 0x19811
leaq 0xa6ad(%rip), %rdi      # 0x23e80
pushq $0x6
popq %rbp
movl %ebp, %esi
movq %rbx, %rdx
callq 0x19bfa
movl 0x14(%rsp), %edi
shrl $0xa, %edi
movq %rbx, %rsi
callq 0x19d33
leaq 0xa691(%rip), %rdi      # 0x23e87
movl %ebp, %esi
movq %rbx, %rdx
callq 0x19bfa
movq 0x38(%rsp), %rax
leaq (%rax,%r15,4), %rdi
movq %rbx, %rsi
callq 0x19e09
testl %r14d, %r14d
js 0x19833
leaq 0xa671(%rip), %rdi      # 0x23e8e
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movl %r14d, %edi
movq %rbx, %rsi
callq 0x19d33
movl 0x6c(%rsp), %ebp
testl %ebp, %ebp
js 0x19857
leaq 0xa653(%rip), %rdi      # 0x23e95
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movl %ebp, %edi
movq %rbx, %rsi
callq 0x19d33
leaq 0x13622(%rip), %rax     # 0x2ce80
cmpb $0x0, (%rax)
je 0x19884
leaq 0xa632(%rip), %rdi      # 0x23e9c
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
leaq 0x13604(%rip), %rdi     # 0x2ce80
movq %rbx, %rsi
callq 0x19e09
btl $0x8, 0x1c(%rsp)
jb 0x19a42
movl 0x58(%rsp), %r15d
xorl %eax, %eax
movq 0x60(%rsp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x60(%rsp)
imulq $0x38, %rcx, %rcx
imulq $0x38, %r15, %rdx
movq 0x28(%rsp), %rsi
cmpq %rax, %rcx
je 0x19a13
cmpq %rax, %rdx
je 0x198c8
testb $0x1, 0xd(%rsi,%rax)
je 0x198ce
addq $0x38, %rax
jmp 0x198b3
leaq 0xa5ce(%rip), %rdi      # 0x23ea3
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movq 0x28(%rsp), %rax
xorl %r13d, %r13d
leaq 0xa579(%rip), %rbp      # 0x23e68
cmpq 0x60(%rsp), %r13
je 0x19a13
cmpq %r15, %r13
je 0x19a0b
imulq $0x38, %r13, %r14
addq %rax, %r14
testb $0x1, 0xd(%r14)
jne 0x19a0b
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x8(%r14), %rcx
imulq $0x28, %rcx, %rcx
movq 0x18(%rax,%rcx), %rdi
movq %rbx, %rsi
callq 0x19e09
pushq $0x2c
popq %r12
movl %r12d, %edi
movq %rbx, %rsi
callq 0x19c9f
movq (%r14), %rdi
incq %rdi
movq %rbx, %rsi
callq 0x19e2c
movl %r12d, %edi
movq %rbx, %rsi
callq 0x19c9f
movl 0x10(%r14), %eax
andl $0x1, %eax
leaq 0x9f74(%rip), %rcx      # 0x238dd
movsbl (%rax,%rcx), %edi
movq %rbx, %rsi
callq 0x19c9f
movl %r12d, %edi
movq %rbx, %rsi
callq 0x19c9f
xorl %r12d, %r12d
movslq 0x14(%r14), %rax
cmpq %rax, %r12
jge 0x199bb
movq 0x18(%r14), %rax
movl (%rax,%r12,4), %edi
shrl $0x4, %edi
movq %rbx, %rsi
callq 0x19d33
movq 0x18(%r14), %rax
movl (%rax,%r12,4), %eax
andl $0xf, %eax
movsbl (%rax,%rbp), %edi
movq %rbx, %rsi
callq 0x19c9f
incq %r12
jmp 0x19983
pushq $0x2c
popq %r12
movl %r12d, %edi
movq %rbx, %rsi
callq 0x19c9f
movl 0x10(%r14), %eax
shrl $0x2, %eax
movzbl %al, %edi
movq %rbx, %rsi
callq 0x19d33
movl %r12d, %edi
movq %rbx, %rsi
callq 0x19c9f
movl 0x10(%r14), %edi
shrl $0xa, %edi
movq %rbx, %rsi
callq 0x19d33
pushq $0x3b
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rax
incq %r13
jmp 0x198ef
cmpl $0x0, 0x44(%rsp)
movl 0x18(%rsp), %r13d
movl 0x4(%rsp), %eax
jle 0x19a42
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x44(%rsp), %xmm1
divsd %xmm1, %xmm0
leaq 0xa472(%rip), %rsi      # 0x23eaa
movq %rbx, %rdi
movb $0x1, %al
callq 0xd490
movq 0x78(%rsp), %r14
testq %r14, %r14
je 0x19a69
leaq 0xa462(%rip), %rdi      # 0x23eb5
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movq %r14, %rdi
movq %rbx, %rsi
callq 0x19e09
cmpq $0x0, 0x10(%r12)
je 0x19a89
pushq $0x9
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movq 0x10(%r12), %rdi
movq %rbx, %rsi
callq 0x19e09
testl %r13d, %r13d
js 0x19b00
movl $0x100, %eax            # imm = 0x100
movq 0x50(%rsp), %rcx
andl 0x48(%rcx), %eax
je 0x19b00
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x70(%rsp), %r15
movq 0x20(%rax,%r15), %rax
testq %rax, %rax
je 0x19b00
cmpb $0x0, (%rax)
je 0x19b00
leaq 0xa3fa(%rip), %rdi      # 0x23ebc
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x19bfa
movslq (%rbx), %r14
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax,%r15), %rdi
movq %rbx, %rsi
callq 0x19e09
cmpq %r14, (%rbx)
jbe 0x19b00
movq 0x10(%rbx), %rax
cmpb $0x9, (%rax,%r14)
jne 0x19afb
movb $0x20, (%rax,%r14)
incq %r14
jmp 0x19ae6
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x38(%rsp), %rsi
callq 0x19f1c
movq 0x8(%rsp), %rcx
decl %eax
movslq %eax, %r14
movq (%rcx), %r15
testb $0x1, 0x10(%rcx)
movl 0x14(%rcx), %ebp
jne 0x19b41
xorl %eax, %eax
jmp 0x19b50
movq 0x18(%rcx), %rsi
movl %ebp, %edi
callq 0x19f1c
decl %eax
cltq
testl %ebp, %ebp
movl (%rsp), %ebp
je 0x19b80
testl %ebp, %ebp
je 0x19b80
addq 0x48(%rsp), %r14
addq %r15, %rax
xorl %ecx, %ecx
subq %r14, %rax
setg %cl
pushq $-0x1
popq %rdx
cmovgeq %rcx, %rdx
leaq (%rax,%rdx), %rdi
movq %rbx, %rsi
callq 0x19e2c
jmp 0x19b8b
pushq $0x30
popq %rdi
movq %rbx, %rsi
callq 0x19c9f
movl 0x4(%rsp), %r14d
jmp 0x19557