// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/padding.c
// Function: bam_pad2unpad
int bam_pad2unpad(samfile_t *in, samfile_t *out, faidx_t *fai)
{
	bam_header_t *h = 0;
	bam1_t *b = 0;
	kstring_t r, q;
	int r_tid = -1;
	uint32_t *cigar2 = 0;
	int ret = 0, n2 = 0, m2 = 0, *posmap = 0;

	b = bam_init1();
	r.l = r.m = q.l = q.m = 0; r.s = q.s = 0;
	int read_ret;
	h = in->header;
	while ((read_ret = samread(in, b)) >= 0) { // read one alignment from `in'
		uint32_t *cigar = bam1_cigar(b);
		n2 = 0;
		if (b->core.pos == 0 && b->core.tid >= 0 && strcmp(bam1_qname(b), h->target_name[b->core.tid]) == 0) {
			// fprintf(stderr, "[depad] Found embedded reference '%s'\n", bam1_qname(b));
			r_tid = b->core.tid;
			unpad_seq(b, &r);
			if (h->target_len[r_tid] != r.l) {
				fprintf(stderr, "[depad] ERROR: (Padded) length of '%s' is %d in BAM header, but %ld in embedded reference\n", bam1_qname(b), h->target_len[r_tid], r.l);
				return -1;
			}
			if (fai) {
				// Check the embedded reference matches the FASTA file
				if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &q)) {
					fprintf(stderr, "[depad] ERROR: Failed to load embedded reference '%s' from FASTA\n", h->target_name[b->core.tid]);
					return -1;
				}
				assert(r.l == q.l);
				int i;
				for (i = 0; i < r.l; ++i) {
					if (r.s[i] != q.s[i]) {
						// Show gaps as ASCII 45
						fprintf(stderr, "[depad] ERROR: Embedded sequence and reference FASTA don't match for %s base %i, '%c' vs '%c'\n",
							h->target_name[b->core.tid], i+1,
							r.s[i] ? bam_nt16_rev_table[(int)r.s[i]] : 45,
							q.s[i] ? bam_nt16_rev_table[(int)q.s[i]] : 45);
						return -1;
					}
				}
			}
			write_cigar(cigar2, n2, m2, bam_cigar_gen(b->core.l_qseq, BAM_CMATCH));
			replace_cigar(b, n2, cigar2);
			posmap = update_posmap(posmap, r);
		} else if (b->core.n_cigar > 0) {
			int i, k, op;
			if (b->core.tid < 0) {
				fprintf(stderr, "[depad] ERROR: Read '%s' has CIGAR but no RNAME\n", bam1_qname(b));
				return -1;
			} else if (b->core.tid == r_tid) {
				; // good case, reference available
				//fprintf(stderr, "[depad] Have ref '%s' for read '%s'\n", h->target_name[b->core.tid], bam1_qname(b));
			} else if (fai) {
				if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &r)) {
					fprintf(stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]);
					return -1;
				}
				posmap = update_posmap(posmap, r);
				r_tid = b->core.tid;
				// fprintf(stderr, "[depad] Loaded %s from FASTA file\n", h->target_name[b->core.tid]);
			} else {				
				fprintf(stderr, "[depad] ERROR: Missing %s embedded reference sequence (and no FASTA file)\n", h->target_name[b->core.tid]);
				return -1;
			}
			unpad_seq(b, &q);
			if (bam_cigar_op(cigar[0]) == BAM_CSOFT_CLIP) {
				write_cigar(cigar2, n2, m2, cigar[0]);
			} else if (bam_cigar_op(cigar[0]) == BAM_CHARD_CLIP) {
				write_cigar(cigar2, n2, m2, cigar[0]);
				if (b->core.n_cigar > 2 && bam_cigar_op(cigar[1]) == BAM_CSOFT_CLIP) {
					write_cigar(cigar2, n2, m2, cigar[1]);
				}
			}
			/* Determine CIGAR operator for each base in the aligned read */
			for (i = 0, k = b->core.pos; i < q.l; ++i, ++k)
				q.s[i] = q.s[i]? (r.s[k]? BAM_CMATCH : BAM_CINS) : (r.s[k]? BAM_CDEL : BAM_CPAD);
			/* Include any pads if starts with an insert */
			if (q.s[0] == BAM_CINS) {
				for (k = 0; k+1 < b->core.pos && !r.s[b->core.pos - k - 1]; ++k);
				if (k) write_cigar(cigar2, n2, m2, bam_cigar_gen(k, BAM_CPAD));
			}
			/* Count consecutive CIGAR operators to turn into a CIGAR string */
			for (i = k = 1, op = q.s[0]; i < q.l; ++i) {
				if (op != q.s[i]) {
					write_cigar(cigar2, n2, m2, bam_cigar_gen(k, op));
					op = q.s[i]; k = 1;
				} else ++k;
			}
			write_cigar(cigar2, n2, m2, bam_cigar_gen(k, op));
			if (bam_cigar_op(cigar[b->core.n_cigar-1]) == BAM_CSOFT_CLIP) {
				write_cigar(cigar2, n2, m2, cigar[b->core.n_cigar-1]);
                        } else if (bam_cigar_op(cigar[b->core.n_cigar-1]) == BAM_CHARD_CLIP) {
				if (b->core.n_cigar > 2 && bam_cigar_op(cigar[b->core.n_cigar-2]) == BAM_CSOFT_CLIP) {
					write_cigar(cigar2, n2, m2, cigar[b->core.n_cigar-2]);
			  	}
				write_cigar(cigar2, n2, m2, cigar[b->core.n_cigar-1]);
			}
			/* Remove redundant P operators between M/X/=/D operators, e.g. 5M2P10M -> 15M */
			int pre_op, post_op;
			for (i = 2; i < n2; ++i)
				if (bam_cigar_op(cigar2[i-1]) == BAM_CPAD) {
					pre_op = bam_cigar_op(cigar2[i-2]);
					post_op = bam_cigar_op(cigar2[i]);
					/* Note don't need to check for X/= as code above will use M only */
					if ((pre_op == BAM_CMATCH || pre_op == BAM_CDEL) && (post_op == BAM_CMATCH || post_op == BAM_CDEL)) {
						/* This is a redundant P operator */
						cigar2[i-1] = 0; // i.e. 0M
						/* If had same operator either side, combine them in post_op */
						if (pre_op == post_op) {
							/* If CIGAR M, could treat as simple integers since BAM_CMATCH is zero*/
							cigar2[i] = bam_cigar_gen(bam_cigar_oplen(cigar2[i-2]) + bam_cigar_oplen(cigar2[i]), post_op);
							cigar2[i-2] = 0; // i.e. 0M
						}
					}
				}
			/* Remove the zero'd operators (0M) */
			for (i = k = 0; i < n2; ++i)
				if (cigar2[i]) cigar2[k++] = cigar2[i];
			n2 = k;
			replace_cigar(b, n2, cigar2);
			b->core.pos = posmap[b->core.pos];
			if (b->core.mtid < 0 || b->core.mpos < 0) {
				/* Nice case, no mate to worry about*/
				// fprintf(stderr, "[depad] Read '%s' mate not mapped\n", bam1_qname(b));
				/* TODO - Warning if FLAG says mate should be mapped? */
				/* Clean up funny input where mate position is given but mate reference is missing: */
				b->core.mtid = -1;
				b->core.mpos = -1;
			} else if (b->core.mtid == b->core.tid) {
				/* Nice case, same reference */
				// fprintf(stderr, "[depad] Read '%s' mate mapped to same ref\n", bam1_qname(b));
				b->core.mpos = posmap[b->core.mpos];
			} else {
				/* Nasty case, Must load alternative posmap */
				// fprintf(stderr, "[depad] Loading reference '%s' temporarily\n", h->target_name[b->core.mtid]);
				if (!fai) {
					fprintf(stderr, "[depad] ERROR: Needed reference %s sequence for mate (and no FASTA file)\n", h->target_name[b->core.mtid]);
					return -1;
				}
				/* Temporarily load the other reference sequence */
				if (load_unpadded_ref(fai, h->target_name[b->core.mtid], h->target_len[b->core.mtid], &r)) {
					fprintf(stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.mtid]);
					return -1;
				}
				posmap = update_posmap(posmap, r);
				b->core.mpos = posmap[b->core.mpos];
				/* Restore the reference and posmap*/
				if (load_unpadded_ref(fai, h->target_name[b->core.tid], h->target_len[b->core.tid], &r)) {
					fprintf(stderr, "[depad] ERROR: Failed to load '%s' from reference FASTA\n", h->target_name[b->core.tid]);
					return -1;
				}
				posmap = update_posmap(posmap, r);
			}
		}
		samwrite(out, b);
	}
	if (read_ret < -1) {
		fprintf(stderr, "[depad] truncated file.\n");
		ret = 1;
	}
	free(r.s); free(q.s); free(posmap);
	bam_destroy1(b);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdi, %rbx
movl $0x1, %edi
movl $0x38, %esi
callq 0x3610
movq %rax, %r14
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x20(%rsp), %rcx
movaps %xmm0, (%rcx)
xorl %ebp, %ebp
movq %rbp, 0x10(%rax)
movq %rbp, 0x10(%rcx)
movq %rbx, 0x80(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x40(%rsp)
addq $0x8, %rax
movq %rax, 0x18(%rsp)
leaq 0x14(%r14), %rax
movq %rax, 0x68(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %eax, %eax
movq %r14, 0x70(%rsp)
movq %rax, (%rsp)
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x27d67
testl %eax, %eax
js 0x1c1ad
movq 0x8(%r14), %r15
movq 0x30(%r14), %rbx
cmpl $0x0, 0x4(%r14)
je 0x1ba15
movq %r15, %rax
shrq $0x30, %rax
je 0x1bf44
movslq (%r14), %rax
testq %rax, %rax
js 0x1c067
cmpl 0xc(%rsp), %eax
je 0x1b9b9
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x1c080
movq 0x40(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movq (%rcx,%rax,8), %rsi
movl (%rdx,%rax,4), %edx
leaq 0x20(%rsp), %rcx
callq 0x1b578
testl %eax, %eax
jne 0x1c0a3
movq %rbx, 0x10(%rsp)
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r12
shlq $0x2, %rsi
movq (%rsp), %rdi
callq 0x3720
testq %rbx, %rbx
je 0x1b9a9
xorl %edx, %edx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx,4)
cmpb $0x1, (%r12,%rdx)
sbbl $-0x1, %ecx
incq %rdx
cmpq %rdx, %rbx
jne 0x1b996
movq %rax, (%rsp)
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rbx
shrl $0x18, %r15d
addq %r15, %rbx
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
callq 0x1c22d
movl (%rbx), %eax
andl $0xf, %eax
cmpl $0x5, %eax
je 0x1bb4e
xorl %r12d, %r12d
cmpl $0x4, %eax
movq %r13, %r9
jne 0x1bbba
testl %r9d, %r9d
jne 0x1ba05
movl $0x10, %esi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl $0x4, %r9d
movl (%rbx), %eax
movl %eax, (%rbp)
movl $0x1, %r12d
jmp 0x1bbba
movslq (%r14), %r12
testq %r12, %r12
js 0x1b915
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rsi
movq %rbx, %rdi
callq 0x35a0
testl %eax, %eax
jne 0x1b915
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0x1c22d
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r12,4), %ecx
movq 0x20(%rsp), %r15
cmpq %rcx, %r15
jne 0x1c0b2
cmpq $0x0, 0x48(%rsp)
movq %r13, %r8
je 0x1bad3
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movslq (%r14), %rdx
movq (%rcx,%rdx,8), %rsi
movl (%rax,%rdx,4), %edx
movq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rcx
callq 0x1b578
testl %eax, %eax
jne 0x1c135
cmpq 0x50(%rsp), %r15
jne 0x1c20e
testq %r15, %r15
movq %r13, %r8
je 0x1bad3
movq 0x30(%rsp), %rdx
movq 0x60(%rsp), %rsi
xorl %ecx, %ecx
movsbq (%rdx,%rcx), %rdi
movsbq (%rsi,%rcx), %rax
cmpb %al, %dil
jne 0x1c149
incq %rcx
cmpq %rcx, %r15
jne 0x1bab8
testl %r8d, %r8d
jne 0x1baee
movl $0x10, %esi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl $0x4, %r13d
movl 0x10(%r14), %eax
shll $0x4, %eax
movl %eax, (%rbp)
movq %r14, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0x1c427
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r15
shlq $0x2, %rsi
movq (%rsp), %rdi
callq 0x3720
testq %rbx, %rbx
movq %rax, (%rsp)
je 0x1bb44
xorl %edx, %edx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx,4)
cmpb $0x1, (%r15,%rdx)
sbbl $-0x1, %ecx
incq %rdx
cmpq %rdx, %rbx
jne 0x1bb31
movl %r12d, 0xc(%rsp)
jmp 0x1bf44
movq %r13, %r9
testl %r9d, %r9d
jne 0x1bb6c
movl $0x10, %esi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl $0x4, %r9d
movl (%rbx), %eax
movl %eax, (%rbp)
movl $0x1, %r12d
movabsq $0x2ffffffffffff, %rax  # imm = 0x2FFFFFFFFFFFF
cmpq %rax, 0x8(%r14)
jbe 0x1bbba
movl 0x4(%rbx), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x1bbba
cmpl $0x1, %r9d
jne 0x1bbae
movl $0x8, %esi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl $0x2, %r9d
movl 0x4(%rbx), %eax
movl %eax, 0x4(%rbp)
movl $0x2, %r12d
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x1bc02
movslq 0x4(%r14), %rcx
movq 0x60(%rsp), %rdx
addq 0x30(%rsp), %rcx
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x0, (%rcx,%rsi)
sete %dil
leal (,%rdi,4), %r8d
orb $0x2, %r8b
cmpb $0x0, (%rdx,%rsi)
movzbl %r8b, %r8d
cmovnel %edi, %r8d
movb %r8b, (%rdx,%rsi)
incq %rsi
cmpq %rsi, %rax
jne 0x1bbd4
movq 0x60(%rsp), %rax
cmpb $0x1, (%rax)
movq %rbx, 0x10(%rsp)
jne 0x1bc8d
movl 0x4(%r14), %edx
movq 0x30(%rsp), %rax
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
decl %ecx
decl %edx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rcx, %rsi
subq $0x1, %rsi
jb 0x1bc47
movslq %edx, %rdi
incl %ebx
leal -0x1(%rdi), %edx
cmpb $0x0, (%rax,%rdi)
je 0x1bc31
jmp 0x1bc49
movl %ecx, %ebx
testl %ebx, %ebx
je 0x1bc88
cmpl %r9d, %r12d
jne 0x1bc78
leal (%r9,%r9), %r15d
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %r15d
leal (,%r15,4), %esi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %r15d, %r9d
shll $0x4, %ebx
orl $0x6, %ebx
movl %r12d, %eax
incl %r12d
movl %ebx, (%rbp,%rax,4)
movq 0x10(%rsp), %rbx
movq 0x60(%rsp), %rax
movsbl (%rax), %r15d
movl $0x10, %r13d
cmpq $0x2, 0x50(%rsp)
jb 0x1bd29
movl $0x1, %r13d
movl $0x1, %ebx
movq 0x60(%rsp), %rax
movsbl (%rax,%rbx), %eax
cmpl %eax, %r15d
jne 0x1bcc6
incl %r13d
jmp 0x1bd16
cmpl %r9d, %r12d
jne 0x1bcf4
leal (%r9,%r9), %r14d
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %r14d
leal (,%r14,4), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %r14d, %r9d
shll $0x4, %r13d
orl %r15d, %r13d
movslq %r12d, %rax
incl %r12d
movl %r13d, (%rbp,%rax,4)
movq 0x60(%rsp), %rax
movsbl (%rax,%rbx), %r15d
movl $0x1, %r13d
incq %rbx
cmpq %rbx, 0x50(%rsp)
ja 0x1bcb3
shll $0x4, %r13d
movq 0x10(%rsp), %rbx
cmpl %r9d, %r12d
jne 0x1bd5a
leal (%r9,%r9), %ebx
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %ebx
leal (,%rbx,4), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %ebx, %r9d
movq 0x10(%rsp), %rbx
orl %r15d, %r13d
leal 0x1(%r12), %r15d
movslq %r12d, %rax
movl %r13d, (%rbp,%rax,4)
movq 0x70(%rsp), %r14
movq 0x8(%r14), %rcx
movq %rcx, %rax
shrq $0x30, %rax
movl -0x4(%rbx,%rax,4), %edx
andl $0xf, %edx
cmpl $0x5, %edx
je 0x1bdc9
cmpl $0x4, %edx
jne 0x1be76
cmpl %r9d, %r15d
jne 0x1bdc0
leal (%r9,%r9), %ebx
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %ebx
leal (,%rbx,4), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %ebx, %r9d
movq 0x10(%rsp), %rbx
addl $0x2, %r12d
jmp 0x1be63
movabsq $0x2ffffffffffff, %rdx  # imm = 0x2FFFFFFFFFFFF
cmpq %rdx, %rcx
jbe 0x1be2e
addl $-0x2, %eax
movl (%rbx,%rax,4), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x1be2e
cmpl %r9d, %r15d
jne 0x1be17
leal (%r9,%r9), %ebx
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %ebx
leal (,%rbx,4), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %ebx, %r9d
movq 0x10(%rsp), %rbx
movzwl 0xe(%r14), %eax
movl -0x8(%rbx,%rax,4), %eax
addl $0x2, %r12d
movslq %r15d, %rcx
movl %eax, (%rbp,%rcx,4)
movl %r12d, %r15d
cmpl %r9d, %r15d
jne 0x1be5f
leal (%r9,%r9), %ebx
testl %r9d, %r9d
movl $0x4, %eax
cmovel %eax, %ebx
leal (,%rbx,4), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3720
movq %rax, %rbp
movl %ebx, %r9d
movq 0x10(%rsp), %rbx
leal 0x1(%r15), %r12d
movzwl 0xe(%r14), %eax
movl -0x4(%rbx,%rax,4), %eax
movslq %r15d, %rcx
movl %eax, (%rbp,%rcx,4)
movl %r12d, %r15d
movl %r15d, %eax
cmpl $0x3, %r15d
jl 0x1becd
movl $0x2, %ecx
movl -0x4(%rbp,%rcx,4), %edx
andl $0xf, %edx
cmpl $0x6, %edx
jne 0x1bec5
movl -0x8(%rbp,%rcx,4), %edx
movl (%rbp,%rcx,4), %esi
movl %edx, %edi
orl %esi, %edi
testb $0xd, %dil
jne 0x1bec5
movl $0x0, -0x4(%rbp,%rcx,4)
movl %esi, %edi
xorl %edx, %edi
testb $0x2, %dil
jne 0x1bec5
andl $-0x10, %edx
addl %edx, %esi
movl %esi, (%rbp,%rcx,4)
movl $0x0, -0x8(%rbp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x1be84
testl %r15d, %r15d
jle 0x1bef1
xorl %ecx, %ecx
xorl %esi, %esi
movl (%rbp,%rcx,4), %edx
testl %edx, %edx
je 0x1bee7
movslq %esi, %rdi
incl %esi
movl %edx, (%rbp,%rdi,4)
incq %rcx
cmpq %rcx, %rax
jne 0x1bed6
jmp 0x1bef3
xorl %esi, %esi
movq %r9, %r13
movq %r14, %rdi
movq %rbp, %rdx
callq 0x1c427
movslq 0x4(%r14), %rcx
movq (%rsp), %rax
movl (%rax,%rcx,4), %ecx
movl %ecx, 0x4(%r14)
movslq 0x14(%r14), %r8
testq %r8, %r8
js 0x1bf30
movslq 0x18(%r14), %rcx
testq %rcx, %rcx
js 0x1bf30
cmpl (%r14), %r8d
jne 0x1bf7b
movl (%rax,%rcx,4), %ecx
movl %ecx, 0x18(%r14)
jmp 0x1bf38
movq $-0x1, 0x14(%r14)
movb $0x1, %r15b
testb %r15b, %r15b
je 0x1bf60
movq %rax, (%rsp)
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x27d9c
movb $0x1, %bl
movl 0xc(%rsp), %eax
movl %eax, %r12d
movq (%rsp), %rax
jmp 0x1bf69
xorl %ebx, %ebx
movl 0xc(%rsp), %ecx
movl %ecx, %r12d
movl %r12d, 0xc(%rsp)
testb %bl, %bl
jne 0x1b8e6
jmp 0x1c1e9
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x1c0d8
movq 0x40(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movq (%rcx,%r8,8), %rsi
movl (%rdx,%r8,4), %edx
leaq 0x20(%rsp), %rcx
callq 0x1b578
testl %eax, %eax
jne 0x1c102
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r15
shlq $0x2, %rsi
movq (%rsp), %rdi
callq 0x3720
testq %rbx, %rbx
je 0x1bfe8
xorl %edx, %edx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx,4)
cmpb $0x1, (%r15,%rdx)
sbbl $-0x1, %ecx
incq %rdx
cmpq %rdx, %rbx
jne 0x1bfd5
movslq 0x18(%r14), %rcx
movl (%rax,%rcx,4), %ecx
movl %ecx, 0x18(%r14)
movslq (%r14), %rdi
movq 0x40(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movq (%rcx,%rdi,8), %rsi
movl (%rdx,%rdi,4), %edx
movq %rax, %r15
movq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rcx
callq 0x1b578
testl %eax, %eax
jne 0x1c11d
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %r12
shlq $0x2, %rsi
movq %r15, %rdi
callq 0x3720
movb $0x1, %r15b
testq %rbx, %rbx
je 0x1bf3b
xorl %edx, %edx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx,4)
cmpb $0x1, (%r12,%rdx)
sbbl $-0x1, %ecx
incq %rdx
cmpq %rdx, %rbx
jne 0x1c04f
jmp 0x1bf3b
movq 0x32f7a(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
xorl %r15d, %r15d
leaq 0x25756(%rip), %rsi     # 0x417d1
movq %rbx, %rdx
jmp 0x1c0f9
movq 0x32f61(%rip), %rcx     # 0x4efe8
movq (%rcx), %rdi
movq 0x40(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%rax,8), %rdx
xorl %r15d, %r15d
leaq 0x2579a(%rip), %rsi     # 0x4183b
jmp 0x1c0f9
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x4543
jmp 0x1c111
movq 0x32f2f(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
movq 0x30(%r14), %rdx
xorl %ebx, %ebx
leaq 0x255ca(%rip), %rsi     # 0x41693
movq %r15, %r8
xorl %eax, %eax
callq 0x3750
jmp 0x1bf5a
movq 0x32f09(%rip), %rcx     # 0x4efe8
movq (%rcx), %rdi
movq 0x40(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%r8,8), %rdx
xorl %r15d, %r15d
leaq 0x2578d(%rip), %rsi     # 0x41886
xorl %eax, %eax
callq 0x3750
jmp 0x1c114
movq 0x18(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x4568
xorl %r15d, %r15d
movq (%rsp), %rax
jmp 0x1bf3b
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x458d
movq %r15, %rax
xorl %r15d, %r15d
jmp 0x1bf3b
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x45b2
xorl %ebx, %ebx
jmp 0x1bf5a
movl $0x2d, %r9d
movl $0x2d, %r8d
testb %dil, %dil
je 0x1c169
leaq 0x33f7f(%rip), %rdx     # 0x500e0
movq (%rdx), %rdx
movsbl (%rdx,%rdi), %r8d
testb %al, %al
je 0x1c17c
leaq 0x33f6c(%rip), %rdx     # 0x500e0
movq (%rdx), %rdx
movsbl (%rdx,%rax), %r9d
movq 0x32e65(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq (%r14), %rdx
movq (%rax,%rdx,8), %rdx
incq %rcx
xorl %ebx, %ebx
leaq 0x255d1(%rip), %rsi     # 0x41772
xorl %eax, %eax
callq 0x3750
jmp 0x1bf5a
xorl %ebp, %ebp
cmpl $-0x1, %eax
jne 0x1c202
movq 0x30(%rsp), %rdi
callq 0x3350
movq 0x60(%rsp), %rdi
callq 0x3350
movq (%rsp), %rdi
callq 0x3350
testq %r14, %r14
je 0x1c1ee
movq 0x30(%r14), %rdi
callq 0x3350
movq %r14, %rdi
callq 0x3350
jmp 0x1c1ee
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4527
movl $0x1, %ebp
jmp 0x1c1b4
leaq 0x2551b(%rip), %rdi     # 0x41730
leaq 0x25368(%rip), %rsi     # 0x41584
leaq 0x25518(%rip), %rcx     # 0x4173b
movl $0xb6, %edx
callq 0x31b0