// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap2/format.c
// Function: mm_write_sam3
void mm_write_sam3(kstring_t *s, const mm_idx_t *mi, const mm_bseq1_t *t, int seg_idx, int reg_idx, int n_seg, const int *n_regss, const mm_reg1_t *const* regss, void *km, int64_t opt_flag, int rep_len)
{
	const int max_bam_cigar_op = 65535;
	int flag, n_regs = n_regss[seg_idx], cigar_in_tag = 0;
	int this_rid = -1, this_pos = -1;
	const mm_reg1_t *regs = regss[seg_idx], *r_prev = NULL, *r_next;
	const mm_reg1_t *r = n_regs > 0 && reg_idx < n_regs && reg_idx >= 0? &regs[reg_idx] : NULL;

	// find the primary of the previous and the next segments, if they are mapped
	if (n_seg > 1) {
		int i, next_sid = (seg_idx + 1) % n_seg;
		r_next = get_sam_pri(n_regss[next_sid], regss[next_sid]);
		if (n_seg > 2) {
			for (i = 1; i <= n_seg - 1; ++i) {
				int prev_sid = (seg_idx + n_seg - i) % n_seg;
				if (n_regss[prev_sid] > 0) {
					r_prev = get_sam_pri(n_regss[prev_sid], regss[prev_sid]);
					break;
				}
			}
		} else r_prev = r_next;
	} else r_prev = r_next = NULL;

	// write QNAME
	s->l = 0;
	mm_sprintf_lite(s, "%s", t->name);
	if (n_seg > 1) s->l = mm_qname_len(t->name); // trim the suffix like /1 or /2

	// write flag
	flag = n_seg > 1? 0x1 : 0x0;
	if (r == 0) {
		flag |= 0x4;
	} else {
		if (r->rev) flag |= 0x10;
		if (r->parent != r->id) flag |= 0x100;
		else if (!r->sam_pri) flag |= 0x800;
	}
	if (n_seg > 1) {
		if (r && r->proper_frag) flag |= 0x2; // TODO: this doesn't work when there are more than 2 segments
		if (seg_idx == 0) flag |= 0x40;
		else if (seg_idx == n_seg - 1) flag |= 0x80;
		if (r_next == NULL) flag |= 0x8;
		else if (r_next->rev) flag |= 0x20;
	}
	mm_sprintf_lite(s, "\t%d", flag);

	// write coordinate, MAPQ and CIGAR
	if (r == 0) {
		if (r_prev) {
			this_rid = r_prev->rid, this_pos = r_prev->rs;
			mm_sprintf_lite(s, "\t%s\t%d\t0\t*", mi->seq[this_rid].name, this_pos+1);
		} else mm_sprintf_lite(s, "\t*\t0\t0\t*");
	} else {
		this_rid = r->rid, this_pos = r->rs;
		mm_sprintf_lite(s, "\t%s\t%d\t%d\t", mi->seq[r->rid].name, r->rs+1, r->mapq);
		if ((opt_flag & MM_F_LONG_CIGAR) && r->p && r->p->n_cigar > max_bam_cigar_op - 2) {
			int n_cigar = r->p->n_cigar;
			if (r->qs != 0) ++n_cigar;
			if (r->qe != t->l_seq) ++n_cigar;
			if (n_cigar > max_bam_cigar_op)
				cigar_in_tag = 1;
		}
		if (cigar_in_tag) {
			int slen;
			if ((flag & 0x900) == 0 || (opt_flag & MM_F_SOFTCLIP)) slen = t->l_seq;
			else if ((flag & 0x100) && !(opt_flag & MM_F_SECONDARY_SEQ)) slen = 0;
			else slen = r->qe - r->qs;
			mm_sprintf_lite(s, "%dS%dN", slen, r->re - r->rs);
		} else write_sam_cigar(s, flag, 0, t->l_seq, r, opt_flag);
	}

	// write mate positions
	if (n_seg > 1) {
		int tlen = 0;
		if (this_rid >= 0 && r_next) {
			if (this_rid == r_next->rid) {
				if (r) {
					int this_pos5 = r->rev? r->re - 1 : this_pos;
					int next_pos5 = r_next->rev? r_next->re - 1 : r_next->rs;
					tlen = next_pos5 - this_pos5;
				}
				mm_sprintf_lite(s, "\t=\t");
			} else mm_sprintf_lite(s, "\t%s\t", mi->seq[r_next->rid].name);
			mm_sprintf_lite(s, "%d\t", r_next->rs + 1);
		} else if (r_next) { // && this_rid < 0
			mm_sprintf_lite(s, "\t%s\t%d\t", mi->seq[r_next->rid].name, r_next->rs + 1);
		} else if (this_rid >= 0) { // && r_next == NULL
			mm_sprintf_lite(s, "\t=\t%d\t", this_pos + 1); // next segment will take r's coordinate
		} else mm_sprintf_lite(s, "\t*\t0\t"); // neither has coordinates
		if (tlen > 0) ++tlen;
		else if (tlen < 0) --tlen;
		mm_sprintf_lite(s, "%d\t", tlen);
	} else mm_sprintf_lite(s, "\t*\t0\t0\t");

	// write SEQ and QUAL
	if (r == 0) {
		sam_write_sq(s, t->seq, t->l_seq, 0, 0);
		mm_sprintf_lite(s, "\t");
		if (t->qual) sam_write_sq(s, t->qual, t->l_seq, 0, 0);
		else mm_sprintf_lite(s, "*");
	} else {
		if ((flag & 0x900) == 0 || (opt_flag & MM_F_SOFTCLIP)) {
			sam_write_sq(s, t->seq, t->l_seq, r->rev, r->rev);
			mm_sprintf_lite(s, "\t");
			if (t->qual) sam_write_sq(s, t->qual, t->l_seq, r->rev, 0);
			else mm_sprintf_lite(s, "*");
		} else if ((flag & 0x100) && !(opt_flag & MM_F_SECONDARY_SEQ)){
			mm_sprintf_lite(s, "*\t*");
		} else {
			sam_write_sq(s, t->seq + r->qs, r->qe - r->qs, r->rev, r->rev);
			mm_sprintf_lite(s, "\t");
			if (t->qual) sam_write_sq(s, t->qual + r->qs, r->qe - r->qs, r->rev, 0);
			else mm_sprintf_lite(s, "*");
		}
	}

	// write tags
	if (mm_rg_id[0]) mm_sprintf_lite(s, "\tRG:Z:%s", mm_rg_id);
	if (n_seg > 2) mm_sprintf_lite(s, "\tFI:i:%d", seg_idx);
	if (r) {
		write_tags(s, r);
		if (r->parent == r->id && r->p && n_regs > 1 && regs && r >= regs && r - regs < n_regs) { // supplementary aln may exist
			int i, n_sa = 0; // n_sa: number of SA fields
			for (i = 0; i < n_regs; ++i)
				if (i != r - regs && regs[i].parent == regs[i].id && regs[i].p)
					++n_sa;
			if (n_sa > 0) {
				mm_sprintf_lite(s, "\tSA:Z:");
				for (i = 0; i < n_regs; ++i) {
					const mm_reg1_t *q = &regs[i];
					int l_M, l_I = 0, l_D = 0, clip5 = 0, clip3 = 0;
					if (r == q || q->parent != q->id || q->p == 0) continue;
					if (q->qe - q->qs < q->re - q->rs) l_M = q->qe - q->qs, l_D = (q->re - q->rs) - l_M;
					else l_M = q->re - q->rs, l_I = (q->qe - q->qs) - l_M;
					clip5 = q->rev? t->l_seq - q->qe : q->qs;
					clip3 = q->rev? q->qs : t->l_seq - q->qe;
					mm_sprintf_lite(s, "%s,%d,%c,", mi->seq[q->rid].name, q->rs+1, "+-"[q->rev]);
					if (clip5) mm_sprintf_lite(s, "%dS", clip5);
					if (l_M) mm_sprintf_lite(s, "%dM", l_M);
					if (l_I) mm_sprintf_lite(s, "%dI", l_I);
					if (l_D) mm_sprintf_lite(s, "%dD", l_D);
					if (clip3) mm_sprintf_lite(s, "%dS", clip3);
					mm_sprintf_lite(s, ",%d,%d;", q->mapq, q->blen - q->mlen + q->p->n_ambi);
				}
			}
		}
		if (r->p && (opt_flag & (MM_F_OUT_CS|MM_F_OUT_DS|MM_F_OUT_MD)))
			write_cs_ds_or_MD(km, s, mi, t, r, !(opt_flag&MM_F_OUT_CS_LONG), opt_flag&MM_F_OUT_MD, !!(opt_flag&MM_F_OUT_DS), 1, 0);
		if (cigar_in_tag)
			write_sam_cigar(s, flag, 1, t->l_seq, r, opt_flag);
	}
	if (rep_len >= 0) mm_sprintf_lite(s, "\trl:i:%d", rep_len);

	if ((opt_flag & MM_F_COPY_COMMENT) && t->comment)
		mm_sprintf_lite(s, "\t%s", t->comment);

	s->s[s->l] = 0; // we always have room for an extra byte (see str_enlarge)
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %r13d
movq %rdx, %r14
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rsi
movslq %r13d, %rax
movl (%rsi,%rax,4), %r10d
movq (%rcx,%rax,8), %r11
movl %r8d, %eax
leaq (%rax,%rax,4), %r15
shlq $0x4, %r15
addq %r11, %r15
xorl %ebp, %ebp
cmpl %r8d, %r10d
cmovbeq %rbp, %r15
testl %r10d, %r10d
cmovleq %rbp, %r15
movl $0x0, %r12d
cmpl $0x2, %r9d
movq %r9, 0x10(%rsp)
jl 0xffc0
leal 0x1(%r13), %eax
cltd
idivl %r9d
movslq %edx, %rdx
movslq (%rsi,%rdx,4), %rax
testq %rax, %rax
jle 0xff51
movq (%rcx,%rdx,8), %rbp
movq %rax, %rdx
testb $0x10, 0x3d(%rbp)
jne 0xff5b
addq $0x50, %rbp
decq %rdx
jne 0xff42
testl %eax, %eax
jne 0x108a8
xorl %ebp, %ebp
cmpl $0x2, %r9d
jne 0xff66
movq %rbp, %r12
jmp 0xffc0
leal (%r9,%r13), %edi
cmpl $0x3, %r9d
movl $0x2, %r8d
cmovgel %r9d, %r8d
movl $0x1, %r9d
xorl %r12d, %r12d
movl %edi, %eax
subl %r9d, %eax
cltd
idivl 0x10(%rsp)
movslq %edx, %rdx
movslq (%rsi,%rdx,4), %rax
testq %rax, %rax
jle 0xffb4
movq (%rcx,%rdx,8), %r12
movq %rax, %rdx
testb $0x10, 0x3d(%r12)
jne 0xffb4
addq $0x50, %r12
decq %rdx
jne 0xff9e
jmp 0x108a8
testl %eax, %eax
jg 0xffc0
incl %r9d
cmpl %r8d, %r9d
jne 0xff81
movq %r11, 0x38(%rsp)
movq %r10, 0x40(%rsp)
movq $0x0, (%rbx)
movq 0x8(%r14), %rdx
leaq 0x1cafd(%rip), %rsi     # 0x2cad9
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x10(%rsp), %rsi
cmpl $0x2, %esi
movq %r14, 0x28(%rsp)
jl 0x1002d
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x2130
cmpl $0x3, %eax
jl 0x10020
movl %eax, %ecx
decl %ecx
movb (%r14,%rcx), %cl
addb $-0x30, %cl
cmpb $0x9, %cl
ja 0x10020
leal -0x2(%rax), %ecx
cmpb $0x2f, (%r14,%rcx)
je 0x10022
movl %eax, %ecx
movslq %ecx, %rax
movq %rax, (%rbx)
movq 0x10(%rsp), %rsi
xorl %r14d, %r14d
cmpl $0x2, %esi
setge %r14b
testq %r15, %r15
je 0x10063
movl 0x20(%r15), %edx
movl 0x3c(%r15), %ecx
movl %ecx, %eax
shrl $0x6, %eax
andl $0x10, %eax
orl %r14d, %eax
cmpl (%r15), %edx
jne 0x10069
shrl %ecx
movl $0x800, %edx            # imm = 0x800
andl %edx, %ecx
orl %ecx, %eax
xorl %edx, %eax
jmp 0x1006e
orl $0x4, %r14d
jmp 0x10071
orl $0x100, %eax            # imm = 0x100
movl %eax, %r14d
cmpl $0x2, %esi
movq %rbx, 0x20(%rsp)
movq %r13, 0x30(%rsp)
jl 0x100c7
testq %r15, %r15
je 0x10092
movl 0x3c(%r15), %eax
shrl $0xc, %eax
andl $0x2, %eax
orl %eax, %r14d
testl %r13d, %r13d
je 0x100ac
leal -0x1(%rsi), %eax
movl %r14d, %ecx
orl $0x80, %ecx
cmpl %r13d, %eax
cmovel %ecx, %r14d
jmp 0x100b0
orl $0x40, %r14d
testq %rbp, %rbp
je 0x100c3
movl 0x3c(%rbp), %eax
shrl $0x5, %eax
andl $0x20, %eax
orl %eax, %r14d
jmp 0x100c7
orl $0x8, %r14d
movq 0x98(%rsp), %rbx
leaq 0x1c9e7(%rip), %rsi     # 0x2cabd
movq 0x20(%rsp), %r13
movq %r13, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe671
testq %r15, %r15
movl %r14d, 0x8(%rsp)
je 0x10196
movslq 0x8(%r15), %r14
movl 0x18(%r15), %r12d
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rdx
leal 0x1(%r12), %ecx
movzbl 0x3c(%r15), %r8d
leaq 0x1c9d0(%rip), %rsi     # 0x2caf0
movq %r13, %rdi
xorl %eax, %eax
callq 0xe671
btl $0x10, %ebx
jae 0x1016f
movq 0x48(%r15), %rax
testq %rax, %rax
je 0x1016f
movl 0x18(%rax), %esi
cmpl $0xfffe, %esi           # imm = 0xFFFE
jb 0x1016f
movl 0x10(%r15), %ecx
movl 0x14(%r15), %eax
cmpl $0x1, %ecx
sbbl $-0x1, %esi
movq 0x28(%rsp), %rdx
movl (%rdx), %edx
xorl %edi, %edi
cmpl %edx, %eax
setne %dil
addl %esi, %edi
cmpl $0x10000, %edi          # imm = 0x10000
jge 0x10309
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl 0x8(%rsp), %esi
xorl %edx, %edx
movq %r15, %r8
movq 0x98(%rsp), %r9
callq 0x108c7
jmp 0x101d5
testq %r12, %r12
je 0x10282
movslq 0x8(%r12), %r14
movl 0x18(%r12), %r12d
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rdx
leal 0x1(%r12), %ecx
leaq 0x1c916(%rip), %rsi     # 0x2cadc
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %r13
cmpl $0x2, 0x10(%rsp)
jl 0x10228
testq %rbp, %rbp
je 0x10246
testl %r14d, %r14d
js 0x10246
movslq 0x8(%rbp), %rax
cmpl %eax, %r14d
jne 0x102af
testq %r15, %r15
je 0x10356
testb $0x4, 0x3d(%r15)
je 0x10215
movl 0x1c(%r15), %r12d
decl %r12d
testb $0x4, 0x3d(%rbp)
jne 0x1035b
movl 0x18(%rbp), %r14d
jmp 0x10362
leaq 0x1c8f1(%rip), %rsi     # 0x2cb20
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x98(%rsp), %r12
jmp 0x103d9
testq %rbp, %rbp
je 0x102e1
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x8(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movl 0x18(%rbp), %ecx
incl %ecx
leaq 0x1c89b(%rip), %rsi     # 0x2cb0b
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
jmp 0x103aa
leaq 0x1c85e(%rip), %rsi     # 0x2cae7
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x101db
movq 0x18(%rsp), %rcx
movq 0x20(%rcx), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rdx
leaq 0x1c83f(%rip), %rsi     # 0x2cb06
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x98(%rsp), %r12
jmp 0x1037e
testl %r14d, %r14d
js 0x10396
incl %r12d
leaq 0x1c81f(%rip), %rsi     # 0x2cb13
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe671
jmp 0x103aa
movq 0x98(%rsp), %rsi
btl $0x13, %esi
movq 0x30(%rsp), %r13
jb 0x1087d
movl 0x8(%rsp), %esi
andl $0x900, %esi            # imm = 0x900
movq 0x20(%rsp), %rbx
je 0x10882
subl %ecx, %eax
xorl %edx, %edx
testl $0x100, 0x8(%rsp)       # imm = 0x100
cmovel %eax, %edx
btq $0x24, 0x98(%rsp)
cmovbl %eax, %edx
jmp 0x10882
xorl %r14d, %r14d
jmp 0x10365
movl 0x1c(%rbp), %r14d
decl %r14d
subl %r12d, %r14d
movq 0x98(%rsp), %r12
leaq 0x1c78e(%rip), %rsi     # 0x2cb02
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movl 0x18(%rbp), %edx
incl %edx
leaq 0x1c78c(%rip), %rsi     # 0x2cb16
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
jmp 0x103b2
leaq 0x1c77d(%rip), %rsi     # 0x2cb1a
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x98(%rsp), %r12
leal 0x1(%r14), %eax
leal -0x1(%r14), %ecx
movl %r14d, %edx
sarl $0x1f, %edx
andl %ecx, %edx
testl %r14d, %r14d
cmovgl %eax, %edx
leaq 0x1c747(%rip), %rsi     # 0x2cb16
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
testq %r15, %r15
movq 0x28(%rsp), %r14
je 0x1041b
btl $0x13, %r12d
jb 0x1045a
movl 0x8(%rsp), %eax
andl $0x900, %eax            # imm = 0x900
je 0x1045a
btq $0x24, %r12
jb 0x10499
movl 0x8(%rsp), %eax
andl $0x100, %eax            # imm = 0x100
je 0x10499
leaq 0x1c712(%rip), %rsi     # 0x2cb28
jmp 0x10504
movq 0x10(%r14), %rsi
movl (%r14), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x10af8
leaq 0x1c6e8(%rip), %rsi     # 0x2cb1e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x104fd
movl (%r14), %edx
movq %rbx, %rdi
xorl %ecx, %ecx
jmp 0x104f3
movq 0x10(%r14), %rsi
movl (%r14), %edx
movl 0x3c(%r15), %ecx
shrl $0xa, %ecx
andl $0x1, %ecx
movq %rbx, %rdi
movl %ecx, %r8d
callq 0x10af8
leaq 0x1c6a1(%rip), %rsi     # 0x2cb1e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x104fd
movl (%r14), %edx
movl 0x3c(%r15), %ecx
jmp 0x104ea
movslq 0x10(%r15), %rax
movq %rax, %rsi
addq 0x10(%r14), %rsi
movl 0x14(%r15), %edx
subl %eax, %edx
movl 0x3c(%r15), %ecx
shrl $0xa, %ecx
andl $0x1, %ecx
movq %rbx, %rdi
movl %ecx, %r8d
callq 0x10af8
leaq 0x1c658(%rip), %rsi     # 0x2cb1e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x104fd
movslq 0x10(%r15), %rax
addq %rax, %rsi
movl 0x14(%r15), %edx
movl 0x3c(%r15), %ecx
subl %eax, %edx
shrl $0xa, %ecx
andl $0x1, %ecx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x10af8
jmp 0x1050e
leaq 0x1c626(%rip), %rsi     # 0x2cb2a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
cmpb $0x0, 0x2542b(%rip)     # 0x35940
je 0x1052f
leaq 0x1c60e(%rip), %rsi     # 0x2cb2c
leaq 0x2541b(%rip), %rdx     # 0x35940
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
cmpl $0x3, 0x10(%rsp)
jl 0x1054a
leaq 0x1c5f8(%rip), %rsi     # 0x2cb35
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe671
movl 0xa0(%rsp), %r13d
testq %r15, %r15
je 0x10829
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfcdb
movl 0x20(%r15), %eax
cmpl (%r15), %eax
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %rdx
jne 0x107ad
cmpl $0x2, %r8d
jl 0x107ad
cmpq $0x0, 0x48(%r15)
je 0x107ad
testq %rdx, %rdx
je 0x107ad
movq %r15, %rcx
subq %rdx, %rcx
jb 0x107ad
sarq $0x4, %rcx
movabsq $-0x3333333333333333, %rax # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
cmpq %r8, %rax
jge 0x107ad
xorl %ecx, %ecx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x105da
movl 0x20(%rdx), %edi
cmpl (%rdx), %edi
jne 0x105da
cmpq $0x1, 0x48(%rdx)
sbbl $-0x1, %esi
incq %rcx
addq $0x50, %rdx
cmpq %rcx, %r8
jne 0x105c6
testl %esi, %esi
jle 0x107ad
leaq 0x1c549(%rip), %rsi     # 0x2cb3e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rbp
testl %ebp, %ebp
jle 0x107ad
cmpq %r15, %rdi
je 0x107a0
movl 0x20(%rdi), %eax
cmpl (%rdi), %eax
jne 0x107a0
cmpq $0x0, 0x48(%rdi)
je 0x107a0
movl 0x10(%rdi), %r8d
movl 0x14(%rdi), %eax
movl %eax, %edx
subl %r8d, %edx
movl 0x1c(%rdi), %r13d
movl 0x18(%rdi), %ecx
subl %ecx, %r13d
movl %edx, %r12d
subl %r13d, %r12d
negl %r12d
movl %edx, %r14d
subl %r13d, %r14d
cmovll %edx, %r13d
movl $0x0, %edx
cmovll %edx, %r14d
cmovgel %edx, %r12d
movl 0x3c(%rdi), %esi
btl $0xa, %esi
movl %r8d, %edx
jae 0x1067b
movq 0x28(%rsp), %rdx
movl (%rdx), %edx
subl %eax, %edx
movl %edx, 0x10(%rsp)
movq %rbp, 0x40(%rsp)
btl $0xa, %esi
jb 0x10695
movq 0x28(%rsp), %rdx
movl (%rdx), %r8d
subl %eax, %r8d
movl %r8d, %ebp
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq %rdi, 0x38(%rsp)
movslq 0x8(%rdi), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rdx
incl %ecx
btl $0xa, %esi
leaq 0x1c0ca(%rip), %rax     # 0x2c789
adcq $0x0, %rax
movsbl (%rax), %r8d
movq %rbx, %rdi
leaq 0x1c474(%rip), %rsi     # 0x2cb45
xorl %eax, %eax
callq 0xe671
movl 0x10(%rsp), %edx
testl %edx, %edx
je 0x106f1
movq %rbx, %rdi
leaq 0x1c465(%rip), %rsi     # 0x2cb4f
xorl %eax, %eax
callq 0xe671
testl %r13d, %r13d
je 0x1070a
movq %rbx, %rdi
leaq 0x1c453(%rip), %rsi     # 0x2cb53
movl %r13d, %edx
xorl %eax, %eax
callq 0xe671
testl %r14d, %r14d
je 0x10723
movq %rbx, %rdi
leaq 0x1c43e(%rip), %rsi     # 0x2cb57
movl %r14d, %edx
xorl %eax, %eax
callq 0xe671
testl %r12d, %r12d
movl 0xa0(%rsp), %r13d
je 0x10744
movq %rbx, %rdi
leaq 0x1c421(%rip), %rsi     # 0x2cb5b
movl %r12d, %edx
xorl %eax, %eax
callq 0xe671
testl %ebp, %ebp
movq 0x28(%rsp), %r14
je 0x10760
movq %rbx, %rdi
leaq 0x1c3f8(%rip), %rsi     # 0x2cb4f
movl %ebp, %edx
xorl %eax, %eax
callq 0xe671
movq 0x38(%rsp), %rbp
movzbl 0x3c(%rbp), %edx
movl 0x30(%rbp), %eax
subl 0x2c(%rbp), %eax
movq 0x48(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andl %esi, %ecx
addl %eax, %ecx
movq %rbx, %rdi
leaq 0x1c3d6(%rip), %rsi     # 0x2cb5f
xorl %eax, %eax
callq 0xe671
movq %rbp, %rdi
movq 0x40(%rsp), %rbp
movq 0x98(%rsp), %r12
addq $0x50, %rdi
decq %rbp
jne 0x10611
movabsq $0x2001000040, %rax     # imm = 0x2001000040
testq %rax, %r12
je 0x10808
cmpq $0x0, 0x48(%r15)
je 0x10808
movq 0x90(%rsp), %rdi
xorl %r9d, %r9d
btl $0xb, %r12d
setae %r9b
movl %r12d, %eax
andl $0x1000000, %eax        # imm = 0x1000000
movq %r12, %r10
shrq $0x25, %r10
andl $0x1, %r10d
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
pushq $0x0
pushq $0x1
pushq %r10
pushq %rax
callq 0xef18
addq $0x20, %rsp
cmpb $0x0, 0xc(%rsp)
jne 0x10829
movl (%r14), %ecx
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movl $0x1, %edx
movq %r15, %r8
movq %r12, %r9
callq 0x108c7
testl %r13d, %r13d
js 0x10842
leaq 0x1c26e(%rip), %rsi     # 0x2caa3
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe671
btl $0x19, %r12d
jae 0x10863
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x10863
leaq 0x1c27f(%rip), %rsi     # 0x2cad8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rbx
movl 0x1c(%r15), %ecx
subl 0x18(%r15), %ecx
leaq 0x1c26a(%rip), %rsi     # 0x2cafb
movl $0x0, 0xc(%rsp)
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe671
jmp 0x101e0
leaq 0x1c5cf(%rip), %rdi     # 0x2ce7e
leaq 0x1c14e(%rip), %rsi     # 0x2ca04
leaq 0x1c5cd(%rip), %rcx     # 0x2ce8a
movl $0x1e0, %edx            # imm = 0x1E0
callq 0x21a0