// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/misc/wgsim.c
// Function: wgsim_core
void wgsim_core(FILE *fpout1, FILE *fpout2, FILE *fp_fa, int is_hap, uint64_t N, int dist, int std_dev, int size_l, int size_r)
{
	seq_t seq;
    mutseq_t rseq[2];
	uint64_t tot_len, ii;
	int i, l, n_ref;
	char name[256], *qstr;
	int size[2], Q;
	uint8_t *tmp_seq[2];
    mut_t *target;

	INIT_SEQ(seq);
	srand48(time(0));
	seq_set_block_size(0x1000000);
	l = size_l > size_r? size_l : size_r;
	qstr = (char*)calloc(l+1, 1);
	tmp_seq[0] = (uint8_t*)calloc(l+2, 1);
	tmp_seq[1] = (uint8_t*)calloc(l+2, 1);
	size[0] = size_l; size[1] = size_r;

	Q = (int)(-10.0 * log(ERR_RATE) / log(10.0) + 0.499) + 33;

	tot_len = n_ref = 0;
	while ((l = seq_read_fasta(fp_fa, &seq, name, 0)) >= 0) {
		tot_len += l;
		++n_ref;
	}
	fprintf(stderr, "[wgsim_core] %d sequences, total length: %llu\n", n_ref, (long long)tot_len);
	rewind(fp_fa);

	while ((l = seq_read_fasta(fp_fa, &seq, name, 0)) >= 0) {
		uint64_t n_pairs = (uint64_t)((long double)l / tot_len * N + 0.5);
		if (l < dist + 3 * std_dev) {
			fprintf(stderr, "[wgsim_core] kkip sequence '%s' as it is shorter than %d!\n", name, dist + 3 * std_dev);
			continue;
		}

		// generate mutations and print them out
		maq_mut_diref(&seq, is_hap, rseq, rseq+1);
		maq_print_mutref(name, &seq, rseq, rseq+1);

		for (ii = 0; ii != n_pairs; ++ii) { // the core loop
			double ran;
			int d, pos, s[2], is_flip = 0;
			int n_sub[2], n_indel[2], n_err[2], ext_coor[2], j, k;
			FILE *fpo[2];

			do { // avoid boundary failure
				ran = ran_normal();
				ran = ran * std_dev + dist;
				d = (int)(ran + 0.5);
				pos = (int)((l - d + 1) * drand48());
			} while (pos < 0 || pos >= seq.l || pos + d - 1 >= seq.l);

			// flip or not
			if (drand48() < 0.5) {
				fpo[0] = fpout1; fpo[1] = fpout2;
				s[0] = size[0]; s[1] = size[1];
			} else {
				fpo[1] = fpout1; fpo[0] = fpout2;
				s[1] = size[0]; s[0] = size[1];
				is_flip = 1;
			}

			// generate the read sequences
			target = rseq[drand48()<0.5?0:1].s; // haplotype from which the reads are generated
			n_sub[0] = n_sub[1] = n_indel[0] = n_indel[1] = n_err[0] = n_err[1] = 0;

#define __gen_read(x, start, iter) do {									\
				for (i = (start), k = 0, ext_coor[x] = -10; i >= 0 && i < seq.l && k < s[x]; iter) {	\
					int c = target[i], mut_type = c & mutmsk;			\
					if (ext_coor[x] < 0) {								\
						if (mut_type != NOCHANGE && mut_type != SUBSTITUTE) continue; \
						ext_coor[x] = i;								\
					}													\
					if (mut_type == DELETE) ++n_indel[x];				\
					else if (mut_type == NOCHANGE || mut_type == SUBSTITUTE) { \
						tmp_seq[x][k++] = c & 0xf;						\
						if (mut_type == SUBSTITUTE) ++n_sub[x];			\
					} else {											\
						int n, ins;										\
						++n_indel[x];									\
						tmp_seq[x][k++] = c & 0xf;						\
						for (n = mut_type>>12, ins = c>>4; n > 0 && k < s[x]; --n, ins >>= 2) \
							tmp_seq[x][k++] = ins & 0x3;				\
					}													\
				}														\
				if (k != s[x]) ext_coor[x] = -10;						\
			} while (0)

			if (!IS_SOLID) {
				__gen_read(0, pos, ++i);
				__gen_read(1, pos + d - 1, --i);
				for (k = 0; k < s[1]; ++k) tmp_seq[1][k] = tmp_seq[1][k] < 4? 3 - tmp_seq[1][k] : 4; // complement
			} else {
				int c1, c2, c;
				++s[0]; ++s[1]; // temporarily increase read length by 1
				if (is_flip) { // RR pair
					__gen_read(0, pos + s[0], --i);
					__gen_read(1, pos + d - 1, --i);
				} else { // FF pair
					__gen_read(0, pos, ++i);
					__gen_read(1, pos + d - 1 - s[1], ++i);
					++ext_coor[0]; ++ext_coor[1];
				}
				// change to color sequence: (0,1,2,3) -> (A,C,G,T)
				for (j = 0; j < 2; ++j) {
					c1 = tmp_seq[j][0];
					for (i = 1; i < s[j]; ++i) {
						c2 = tmp_seq[j][i];
						c = (c1 >= 4 || c2 >= 4)? 4 : nst_color_space_table[(1<<c1)|(1<<c2)];
						tmp_seq[j][i-1] = c;
						c1 = c2;
					}
				}
				--s[0]; --s[1]; // change back
			}
			if (ext_coor[0] < 0 || ext_coor[1] < 0) { // fail to generate the read(s)
				--ii;
				continue;
			}

			// generate sequencing errors
			for (j = 0; j < 2; ++j) {
				for (i = 0; i < s[j]; ++i) {
					int c = tmp_seq[j][i];
					if (c >= 4) c = 4; // actually c should be never larger than 4 if everything is correct
					else if (drand48() < ERR_RATE) {
						c = (c + (int)(drand48() * 3.0 + 1)) & 3;
						++n_err[j];
					}
					tmp_seq[j][i] = c;
				}
			}

			// print
			for (j = 0; j < 2; ++j) {
				for (i = 0; i < s[j]; ++i) qstr[i] = Q;
				qstr[i] = 0;
				if (SHOW_MM_INFO) {
					fprintf(fpo[j], "@%s_%u_%u_%d:%d:%d_%d:%d:%d_%llx/%d\n", name, ext_coor[0]+1, ext_coor[1]+1,
							n_err[0], n_sub[0], n_indel[0], n_err[1], n_sub[1], n_indel[1],
							(long long)ii, j==0? is_flip+1 : 2-is_flip);
				} else {
					fprintf(fpo[j], "@%s_%u_%u_%llx/%d %d:%d:%d_%d:%d:%d\n", name, ext_coor[0]+1, ext_coor[1]+1,
							(long long)ii, j==0? is_flip+1 : 2-is_flip,
							n_err[0], n_sub[0], n_indel[0], n_err[1], n_sub[1], n_indel[1]);
				}
				for (i = 0; i < s[j]; ++i)
					fputc("ACGTN"[(int)tmp_seq[j][i]], fpo[j]);
				fprintf(fpo[j], "\n+\n%s\n", qstr);
			}
		}
		free(rseq[0].s); free(rseq[1].s);
	}
	free(seq.s); free(qstr);
	free(tmp_seq[0]); free(tmp_seq[1]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movl %r9d, 0x8(%rsp)
movq %r8, 0x90(%rsp)
movl %ecx, 0x9c(%rsp)
movq %rdx, %r14
movq %rsi, 0xd8(%rsp)
movq %rdi, 0xd0(%rsp)
movl 0x2b0(%rsp), %ebx
movl 0x2a8(%rsp), %ebp
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %r13
movaps %xmm0, (%r13)
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x1160
movq %rax, %rdi
callq 0x1190
movl $0x1000000, 0x4e8e(%rip) # imm = 0x1000000
cmpl %ebx, %ebp
cmovgl %ebp, %ebx
leal 0x1(%rbx), %eax
movslq %eax, %rdi
pushq $0x1
popq %r12
movq %r12, %rsi
callq 0x1110
movq %rax, 0x60(%rsp)
addl $0x2, %ebx
movslq %ebx, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1110
movq %rax, 0x48(%rsp)
movq %rax, 0xf0(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1110
movq %rax, 0x50(%rsp)
movq %rax, 0xf8(%rsp)
movsd 0x4e54(%rip), %xmm0     # 0x6130
callq 0x10f0
movsd %xmm0, 0x88(%rsp)
leaq 0x160(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x2651
movl $0x0, %r13d
testl %eax, %eax
js 0x133b
xorl %r13d, %r13d
leaq 0xc0(%rsp), %rbp
leaq 0x160(%rsp), %r12
xorl %r15d, %r15d
movl %eax, %eax
addq %rax, %r13
incl %r15d
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x2651
testl %eax, %eax
jns 0x131f
movq 0x4cb6(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x2f43(%rip), %rsi      # 0x428f
movl %r15d, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x1130
movq %r14, %rdi
callq 0x10b0
leaq 0xc0(%rsp), %rsi
leaq 0x160(%rsp), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x2651
testl %eax, %eax
movq %r14, 0x108(%rsp)
movq 0x60(%rsp), %rbx
movq 0x50(%rsp), %r14
js 0x2270
movsd 0x88(%rsp), %xmm0
mulsd 0x2ca2(%rip), %xmm0     # 0x4048
divsd 0x2ca2(%rip), %xmm0     # 0x4050
addsd 0x2ca2(%rip), %xmm0     # 0x4058
movl 0x2a0(%rsp), %edi
cvttsd2si %xmm0, %esi
movq %r13, 0x118(%rsp)
xorl %ecx, %ecx
testq %r13, %r13
sets %cl
fildll 0x118(%rsp)
leaq 0x2c81(%rip), %rdx      # 0x4060
fadds (%rdx,%rcx,4)
fstpt 0x134(%rsp)
movq 0x90(%rsp), %r8
movq %r8, 0x120(%rsp)
xorl %ecx, %ecx
testq %r8, %r8
sets %cl
fildll 0x120(%rsp)
fadds (%rdx,%rcx,4)
fstpt 0x128(%rsp)
leal (%rdi,%rdi,2), %ecx
movl 0x8(%rsp), %edx
addl %edx, %ecx
movl %ecx, 0x70(%rsp)
cvtsi2sd %edi, %xmm0
movsd %xmm0, 0x90(%rsp)
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0x88(%rsp)
addb $0x21, %sil
movl %esi, 0xa0(%rsp)
leaq 0xc0(%rsp), %r13
movl %eax, 0xa4(%rsp)
fldt 0x134(%rsp)
fidivrl 0xa4(%rsp)
fldt 0x128(%rsp)
fmulp %st, %st(1)
fadds 0x2bf8(%rip)            # 0x4068
flds 0x2bf6(%rip)            # 0x406c
xorl %r12d, %r12d
fxch %st(1)
fucomi %st(1), %st
fldz
fcmovnb %st(2), %st
fstp %st(2)
fsubp %st, %st(1)
setae %dl
fnstcw 0x46(%rsp)
movzwl 0x46(%rsp), %ecx
orl $0xc00, %ecx            # imm = 0xC00
movw %cx, 0x5e(%rsp)
fldcw 0x5e(%rsp)
fistpll 0x110(%rsp)
fldcw 0x46(%rsp)
movl %eax, 0x74(%rsp)
cmpl 0x70(%rsp), %eax
jl 0x224a
movb %dl, %r12b
shlq $0x3f, %r12
xorq 0x110(%rsp), %r12
movq %r13, %rdi
movl 0x9c(%rsp), %esi
leaq 0x140(%rsp), %rbp
movq %rbp, %rdx
leaq 0x150(%rsp), %r15
movq %r15, %rcx
callq 0x28c7
leaq 0x160(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x2be7
testq %r12, %r12
je 0x2204
incl 0x74(%rsp)
movl 0xc0(%rsp), %eax
movl %eax, 0x78(%rsp)
xorl %eax, %eax
movq %r12, 0xe0(%rsp)
movq %rax, 0x80(%rsp)
movl 0x74(%rsp), %ebx
movl 0x78(%rsp), %r12d
callq 0x256c
mulsd 0x90(%rsp), %xmm0
addsd 0x88(%rsp), %xmm0
addsd 0x2ae3(%rip), %xmm0     # 0x4038
cvttsd2si %xmm0, %r15d
movl %ebx, %eax
subl %r15d, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x11f0
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %ebp
testl %ebp, %ebp
js 0x1536
cmpl %ebp, %r12d
jle 0x1536
addl %ebp, %r15d
cmpl %r12d, %r15d
jg 0x1536
callq 0x11f0
movapd %xmm0, %xmm1
movsd 0x2a9e(%rip), %xmm0     # 0x4038
movsd %xmm1, 0x8(%rsp)
ucomisd %xmm1, %xmm0
jbe 0x15e6
movq 0xd0(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movl 0x2a8(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x2b0(%rsp), %eax
movl %eax, 0x24(%rsp)
movl $0x0, 0x40(%rsp)
jmp 0x1623
movq 0xd0(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl 0x2a8(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x2b0(%rsp), %eax
movl %eax, 0x20(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x40(%rsp)
leal -0x1(%r15), %ebx
callq 0x11f0
xorl %eax, %eax
movsd 0x2a02(%rip), %xmm1     # 0x4038
ucomisd %xmm0, %xmm1
setbe %al
shll $0x4, %eax
movq 0x148(%rsp,%rax), %rax
andq $0x0, 0xa8(%rsp)
movl 0x20(%rsp), %edx
cmpb $0x0, 0x4af4(%rip)      # 0x6150
movl %ebx, %edi
movl %ebp, %r9d
je 0x17e9
leal 0x1(%rdx), %r8d
movl 0x24(%rsp), %esi
leal 0x1(%rsi), %ecx
ucomisd 0x8(%rsp), %xmm1
movl %r8d, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movl %ecx, 0x24(%rsp)
movl %r8d, 0x68(%rsp)
jbe 0x1a90
xorl %edi, %edi
movl $0x0, %r10d
pushq $-0x9
popq %rbp
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
movl $0x0, %ecx
movq %rcx, 0x30(%rsp)
testl %edx, %edx
pushq $0x1
popq %r15
js 0x1d7c
movq $0x0, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
pushq $-0xa
popq %r14
xorl %r10d, %r10d
movzwl (%rax,%r9,2), %r11d
movl %r11d, %ebp
andl $0xf000, %ebp           # imm = 0xF000
testl %r14d, %r14d
js 0x175e
movl %r14d, %r8d
cmpl $0xf000, %ebp           # imm = 0xF000
jne 0x1700
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x8(%rsp)
jmp 0x173e
movslq %r10d, %r14
cmpl $0xe000, %ebp           # imm = 0xE000
je 0x170f
testl %ebp, %ebp
jne 0x1776
xorl %r15d, %r15d
cmpl $0xe000, %ebp           # imm = 0xE000
sete %r15b
andb $0xf, %r11b
leal 0x1(%r14), %r10d
movq 0x48(%rsp), %rcx
movb %r11b, (%rcx,%r14)
movq 0x30(%rsp), %rcx
addl %r15d, %ecx
movq %rcx, 0x30(%rsp)
pushq $0x1
popq %r15
movl %r8d, %ebp
incq %r9
cmpl %r9d, %r12d
jle 0x1d75
movl %ebp, %r14d
cmpl %edx, %r10d
jle 0x16d4
jmp 0x1d75
movl %r9d, %r8d
cmpl $0xe000, %ebp           # imm = 0xE000
je 0x16ea
testl %ebp, %ebp
je 0x16ea
movl %r14d, %ebp
jmp 0x1741
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x8(%rsp)
movl %r11d, %ebp
andb $0xf, %bpl
movq 0x48(%rsp), %rcx
movb %bpl, (%rcx,%r14)
leal 0x1(%r14), %ebp
cmpw $0x1000, %r11w          # imm = 0x1000
jb 0x17e1
cmpl %edx, %r10d
jge 0x17e1
movl %r11d, %ebp
shrl $0x4, %ebp
shrl $0xc, %r11d
incq %r14
movl %ebp, %r10d
andb $0x3, %r10b
movq 0x48(%rsp), %rcx
movb %r10b, (%rcx,%r14)
leaq 0x1(%r14), %r10
cmpl $0x2, %r11d
jl 0x173e
decl %r11d
shrl $0x2, %ebp
cmpq %rdx, %r14
movq %r10, %r14
jl 0x17b0
jmp 0x173e
movl %ebp, %r10d
jmp 0x173e
xorl %ecx, %ecx
movl $0x0, %esi
pushq $-0xa
popq %rbp
movl $0x0, %r8d
movq %r8, 0x8(%rsp)
movl $0x0, %r8d
movq %r8, 0x30(%rsp)
testl %edx, %edx
jle 0x1940
movq $0x0, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
pushq $-0xa
popq %r11
xorl %esi, %esi
movzwl (%rax,%r9,2), %r8d
movl %r8d, %r10d
andl $0xf000, %r10d          # imm = 0xF000
testl %r11d, %r11d
js 0x18a2
movl %r11d, %ebp
cmpl $0xf000, %r10d          # imm = 0xF000
jne 0x185b
movq 0x8(%rsp), %r8
incl %r8d
movq %r8, 0x8(%rsp)
jmp 0x192d
movslq %esi, %r11
cmpl $0xe000, %r10d          # imm = 0xE000
je 0x186c
testl %r10d, %r10d
jne 0x18b8
movl %ebp, %r13d
xorl %ebp, %ebp
cmpl $0xe000, %r10d          # imm = 0xE000
sete %bpl
andb $0xf, %r8b
leal 0x1(%r11), %esi
movq 0x48(%rsp), %r10
movb %r8b, (%r10,%r11)
movq 0x30(%rsp), %r8
addl %ebp, %r8d
movl %r13d, %ebp
movq %r8, 0x30(%rsp)
jmp 0x192d
movl %r9d, %ebp
cmpl $0xe000, %r10d          # imm = 0xE000
je 0x1840
testl %r10d, %r10d
je 0x1840
movl %r11d, %ebp
jmp 0x192d
movq 0x8(%rsp), %rsi
incl %esi
movq %rsi, 0x8(%rsp)
movl %r8d, %esi
andb $0xf, %sil
movq 0x48(%rsp), %r10
movb %sil, (%r10,%r11)
movl %r11d, %esi
incl %esi
cmpw $0x1000, %r8w           # imm = 0x1000
jb 0x192d
cmpl %edx, %esi
jge 0x192d
movl %ebp, %r13d
movl %r8d, %r10d
shrl $0x4, %r10d
shrl $0xc, %r8d
movslq %esi, %r11
incq %r11
movl %r10d, %ebp
andb $0x3, %bpl
movq 0x48(%rsp), %r14
movb %bpl, -0x1(%r14,%r11)
incl %esi
cmpl $0x2, %r8d
jl 0x1925
decl %r8d
shrl $0x2, %r10d
leaq 0x1(%r11), %r14
cmpq %rdx, %r11
movq %r14, %r11
jl 0x18f9
movq 0x50(%rsp), %r14
movl %r13d, %ebp
incq %r9
cmpl %r9d, %r12d
jle 0x1940
movl %ebp, %r11d
cmpl %edx, %esi
jl 0x1829
cmpl %edx, %esi
pushq $-0xa
popq %r8
cmovnel %r8d, %ebp
testl %r15d, %r15d
setle %dl
cmpl %r12d, %r15d
setg %sil
orb %dl, %sil
movl %r8d, %r13d
movl $0x0, %edx
movq %rdx, 0x10(%rsp)
movl $0x0, %edx
movq %rdx, 0x28(%rsp)
pushq $0x4
popq %r11
jne 0x1f63
movslq 0x24(%rsp), %rdx
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
cmpl %edx, %ecx
jge 0x1f60
movzwl (%rax,%rdi,2), %esi
movl %esi, %r9d
andl $0xf000, %r9d           # imm = 0xF000
testl %r8d, %r8d
js 0x1a04
movl %r8d, %r13d
cmpl $0xf000, %r9d           # imm = 0xF000
jne 0x19cc
movq 0x10(%rsp), %rsi
incl %esi
movq %rsi, 0x10(%rsp)
jmp 0x1a74
movslq %ecx, %r8
cmpl $0xe000, %r9d           # imm = 0xE000
je 0x19dd
testl %r9d, %r9d
jne 0x1a1a
xorl %r10d, %r10d
cmpl $0xe000, %r9d           # imm = 0xE000
sete %r10b
andb $0xf, %sil
incl %ecx
movb %sil, (%r14,%r8)
movq 0x28(%rsp), %rsi
addl %r10d, %esi
movq %rsi, 0x28(%rsp)
jmp 0x1a74
movl %edi, %r13d
cmpl $0xe000, %r9d           # imm = 0xE000
je 0x19b2
testl %r9d, %r9d
je 0x19b2
movl %r8d, %r13d
jmp 0x1a74
movq 0x10(%rsp), %r9
incl %r9d
movq %r9, 0x10(%rsp)
movl %esi, %r9d
andb $0xf, %r9b
movb %r9b, (%r14,%r8)
incl %ecx
cmpw $0x1000, %si            # imm = 0x1000
jb 0x1a74
cmpl %edx, %ecx
jge 0x1a74
movl %esi, %r8d
shrl $0x4, %r8d
shrl $0xc, %esi
movslq %ecx, %r9
incq %r9
movl %r8d, %r10d
andb $0x3, %r10b
movb %r10b, -0x1(%r14,%r9)
incl %ecx
cmpl $0x2, %esi
jl 0x1a74
decl %esi
shrl $0x2, %r8d
leaq 0x1(%r9), %r10
cmpq %rdx, %r9
movq %r10, %r9
jl 0x1a4f
testl %edi, %edi
jle 0x1f63
decq %rdi
movl %r13d, %r8d
cmpl %r12d, %ebx
jle 0x1994
jmp 0x1f63
addl %r8d, %ebp
cmpl %r12d, %ebp
setl %r9b
movl %ebp, %r10d
orl %edx, %r10d
setns %r10b
andb %r9b, %r10b
xorl %r9d, %r9d
movl $0x0, %r11d
pushq $-0xa
popq %r8
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
movl $0x0, %ecx
movq %rcx, 0x30(%rsp)
cmpb $0x1, %r10b
jne 0x1bf2
movl %ebp, %r10d
movq $0x0, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
pushq $-0xa
popq %r14
xorl %r11d, %r11d
movzwl (%rax,%r10,2), %ebp
movl %ebp, %r12d
andl $0xf000, %r12d          # imm = 0xF000
testl %r14d, %r14d
js 0x1b5e
movl %r14d, %r8d
cmpl $0xf000, %r12d          # imm = 0xF000
jne 0x1b1f
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x8(%rsp)
jmp 0x1bd9
movslq %r11d, %r14
cmpl $0xe000, %r12d          # imm = 0xE000
je 0x1b30
testl %r12d, %r12d
jne 0x1b74
xorl %r13d, %r13d
cmpl $0xe000, %r12d          # imm = 0xE000
sete %r13b
andb $0xf, %bpl
leal 0x1(%r14), %r11d
movq 0x48(%rsp), %r12
movb %bpl, (%r12,%r14)
movq 0x30(%rsp), %rcx
addl %r13d, %ecx
movq %rcx, 0x30(%rsp)
jmp 0x1bd9
movl %r10d, %r8d
cmpl $0xe000, %r12d          # imm = 0xE000
je 0x1b05
testl %r12d, %r12d
je 0x1b05
movl %r14d, %r8d
jmp 0x1bd9
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x8(%rsp)
movl %ebp, %r12d
andb $0xf, %r12b
movq 0x48(%rsp), %rcx
movb %r12b, (%rcx,%r14)
leal 0x1(%r14), %r12d
cmpw $0x1000, %bp            # imm = 0x1000
jb 0x1bd6
cmpl %edx, %r11d
jge 0x1bd6
movl %ebp, %r12d
shrl $0x4, %r12d
shrl $0xc, %ebp
incq %r14
movl %r12d, %r11d
andb $0x3, %r11b
movq 0x48(%rsp), %rcx
movb %r11b, (%rcx,%r14)
leaq 0x1(%r14), %r11
cmpl $0x2, %ebp
jl 0x1bd9
decl %ebp
shrl $0x2, %r12d
cmpq %rdx, %r14
movq %r11, %r14
jl 0x1bad
jmp 0x1bd9
movl %r12d, %r11d
testl %r10d, %r10d
movl 0x78(%rsp), %r12d
jle 0x1bf2
decq %r10
movl %r8d, %r14d
cmpl %edx, %r11d
jle 0x1aee
cmpl 0x68(%rsp), %r11d
pushq $-0xa
popq %rcx
cmovnel %ecx, %r8d
movl %r8d, 0x3c(%rsp)
testl %r15d, %r15d
setg %r8b
cmpl %r12d, %r15d
setle %r10b
testl %esi, %esi
setns %r11b
andb %r8b, %r11b
andb %r10b, %r11b
movl %ecx, %r13d
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
movl $0x0, %ecx
movq %rcx, 0x28(%rsp)
cmpb $0x1, %r11b
movq 0x50(%rsp), %r14
pushq $0x1
popq %r15
leaq 0x2548(%rip), %rbp      # 0x4190
jne 0x1d64
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
pushq $-0xa
popq %r10
xorl %r9d, %r9d
movzwl (%rax,%rdi,2), %r8d
movl %r8d, %r11d
andl $0xf000, %r11d          # imm = 0xF000
testl %r10d, %r10d
js 0x1cd7
movl %r10d, %r13d
cmpl $0xf000, %r11d          # imm = 0xF000
jne 0x1c98
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
jmp 0x1d4c
movslq %r9d, %r10
cmpl $0xe000, %r11d          # imm = 0xE000
je 0x1ca9
testl %r11d, %r11d
jne 0x1ced
xorl %ebp, %ebp
cmpl $0xe000, %r11d          # imm = 0xE000
sete %bpl
andb $0xf, %r8b
leal 0x1(%r10), %r9d
movb %r8b, (%r14,%r10)
movq 0x28(%rsp), %rcx
addl %ebp, %ecx
movq %rcx, 0x28(%rsp)
leaq 0x24bb(%rip), %rbp      # 0x4190
jmp 0x1d4c
movl %edi, %r13d
cmpl $0xe000, %r11d          # imm = 0xE000
je 0x1c7e
testl %r11d, %r11d
je 0x1c7e
movl %r10d, %r13d
jmp 0x1d4c
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
movl %r8d, %r11d
andb $0xf, %r11b
movb %r11b, (%r14,%r10)
leal 0x1(%r10), %r11d
cmpw $0x1000, %r8w           # imm = 0x1000
jb 0x1d49
cmpl %esi, %r9d
jge 0x1d49
movl %r8d, %r11d
shrl $0x4, %r11d
shrl $0xc, %r8d
incq %r10
movl %r11d, %r9d
andb $0x3, %r9b
movb %r9b, (%r14,%r10)
leaq 0x1(%r10), %r9
cmpl $0x2, %r8d
jl 0x1d4c
decl %r8d
shrl $0x2, %r11d
cmpq %rsi, %r10
movq %r9, %r10
jl 0x1d23
jmp 0x1d4c
movl %r11d, %r9d
testl %edi, %edi
jle 0x1d64
cmpl %r12d, %ebx
jg 0x1d64
decq %rdi
movl %r13d, %r10d
cmpl %esi, %r9d
jle 0x1c67
cmpl 0x1c(%rsp), %r9d
pushq $-0xa
popq %rax
cmovnel %eax, %r13d
jmp 0x1ee7
incl %ebp
movq 0x50(%rsp), %r14
subl 0x1c(%rsp), %ebx
cmpl %r12d, %ebx
setl %r9b
movl %ebx, %r11d
orl %esi, %r11d
setns %r11b
andb %r9b, %r11b
pushq $-0x9
popq %r13
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
movl $0x0, %ecx
movq %rcx, 0x28(%rsp)
cmpb $0x1, %r11b
jne 0x1ec9
movl %ebp, 0x3c(%rsp)
movl %ebx, %r9d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x10(%rsp)
pushq $-0xa
popq %rbx
xorl %edi, %edi
movzwl (%rax,%r9,2), %r11d
movl %r11d, %ebp
andl $0xf000, %ebp           # imm = 0xF000
testl %ebx, %ebx
js 0x1e42
movl %ebx, %r13d
cmpl $0xf000, %ebp           # imm = 0xF000
jne 0x1e02
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
jmp 0x1eaf
movslq %edi, %rbx
cmpl $0xe000, %ebp           # imm = 0xE000
je 0x1e11
testl %ebp, %ebp
jne 0x1e56
xorl %r14d, %r14d
cmpl $0xe000, %ebp           # imm = 0xE000
sete %r14b
andb $0xf, %r11b
leal 0x1(%rbx), %edi
movq 0x50(%rsp), %rcx
movb %r11b, (%rcx,%rbx)
movq 0x28(%rsp), %rcx
addl %r14d, %ecx
movq %rcx, 0x28(%rsp)
movq 0x50(%rsp), %r14
jmp 0x1eaf
movl %r9d, %r13d
cmpl $0xe000, %ebp           # imm = 0xE000
je 0x1de9
testl %ebp, %ebp
je 0x1de9
movl %ebx, %r13d
jmp 0x1eaf
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
movl %r11d, %ebp
andb $0xf, %bpl
movb %bpl, (%r14,%rbx)
leal 0x1(%rbx), %ebp
cmpw $0x1000, %r11w          # imm = 0x1000
jb 0x1ead
cmpl %esi, %edi
jge 0x1ead
movl %r11d, %ebp
shrl $0x4, %ebp
shrl $0xc, %r11d
incq %rbx
movl %ebp, %edi
andb $0x3, %dil
movb %dil, (%r14,%rbx)
leaq 0x1(%rbx), %rdi
cmpl $0x2, %r11d
jl 0x1eaf
decl %r11d
shrl $0x2, %ebp
cmpq %rsi, %rbx
movq %rdi, %rbx
jl 0x1e89
jmp 0x1eaf
movl %ebp, %edi
incq %r9
cmpl %r9d, %r12d
jle 0x1ec2
movl %r13d, %ebx
cmpl %esi, %edi
jle 0x1dd4
incl %r13d
movl 0x3c(%rsp), %ebp
cmpl 0x68(%rsp), %r10d
pushq $-0x9
popq %rax
cmovnel %eax, %ebp
movl %ebp, 0x3c(%rsp)
cmpl 0x1c(%rsp), %edi
cmovnel %eax, %r13d
leaq 0x22a9(%rip), %rbp      # 0x4190
xorl %eax, %eax
pushq $0x1
popq %r12
movslq 0x20(%rsp,%rax,4), %rdi
cmpq $0x2, %rdi
jl 0x1f41
movq 0xf0(%rsp,%rax,8), %r8
movzbl (%r8), %r10d
movq %r12, %r9
movb (%r8,%r9), %cl
cmpl $0x4, %r10d
setae %r11b
cmpb $0x4, %cl
setae %bl
orb %r11b, %bl
movb $0x4, %r11b
jne 0x1f30
movl %r15d, %r11d
shll %cl, %r11d
btsl %r10d, %r11d
movb (%rbp,%r11,4), %r11b
movzbl %cl, %r10d
movb %r11b, -0x1(%r8,%r9)
incq %r9
cmpq %r9, %rdi
jne 0x1f07
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0x1eed
movl %edx, 0x20(%rsp)
movl %esi, 0x24(%rsp)
movq 0x60(%rsp), %rbx
movl 0x3c(%rsp), %ebp
jmp 0x1fa3
movl %r8d, %r13d
movl 0x24(%rsp), %eax
cmpl %eax, %ecx
pushq $-0xa
popq %rcx
cmovnel %ecx, %r13d
testl %eax, %eax
jle 0x1f9e
xorl %ecx, %ecx
movq 0x60(%rsp), %rbx
movb (%r14,%rcx), %dl
movb $0x3, %sil
subb %dl, %sil
cmpb $0x4, %dl
movzbl %sil, %edx
cmovael %r11d, %edx
movb %dl, (%r14,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x1f7b
jmp 0x1fa3
movq 0x60(%rsp), %rbx
testl %ebp, %ebp
movq 0xe0(%rsp), %r12
movq 0x80(%rsp), %rax
js 0x21fb
testl %r13d, %r13d
js 0x21fb
movl %r13d, 0x1c(%rsp)
movl %ebp, %r13d
xorl %ebx, %ebx
movslq 0x20(%rsp,%rbx,4), %r14
testq %r14, %r14
jle 0x2037
movq 0xf0(%rsp,%rbx,8), %r15
xorl %r12d, %r12d
movb (%r15,%r12), %bpl
movb $0x4, %al
cmpb $0x3, %bpl
ja 0x202b
callq 0x11f0
movsd 0x4134(%rip), %xmm1     # 0x6130
ucomisd %xmm0, %xmm1
jbe 0x2029
callq 0x11f0
mulsd 0x2019(%rip), %xmm0     # 0x4028
addsd 0x1ff9(%rip), %xmm0     # 0x4010
cvttsd2si %xmm0, %eax
incl 0xa8(%rsp,%rbx,4)
addb %al, %bpl
andb $0x3, %bpl
movl %ebp, %eax
movb %al, (%r15,%r12)
incq %r12
cmpq %r12, %r14
jne 0x1fe3
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
je 0x1fce
movl %r13d, %ebp
incl %ebp
incl 0x1c(%rsp)
movl 0xa8(%rsp), %eax
movq %rax, 0x68(%rsp)
movl 0xac(%rsp), %eax
movq %rax, 0xe8(%rsp)
pushq $0x2
popq %r12
movl 0x40(%rsp), %eax
subl %eax, %r12d
movl %r12d, 0x7c(%rsp)
incl %eax
movl %eax, 0x40(%rsp)
xorl %r14d, %r14d
movq 0x60(%rsp), %rbx
movl %ebp, 0x3c(%rsp)
movslq 0x20(%rsp,%r14,4), %r13
testq %r13, %r13
jle 0x20ab
movzbl 0xa0(%rsp), %esi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x10d0
movq %r13, %rax
jmp 0x20ad
xorl %eax, %eax
movb $0x0, (%rbx,%rax)
movq 0xb0(%rsp,%r14,8), %rdi
cmpb $0x0, 0x4094(%rip)      # 0x6154
je 0x211d
testq %r14, %r14
movl 0x7c(%rsp), %eax
movl %eax, %r10d
cmovel 0x40(%rsp), %r10d
subq $0x8, %rsp
leaq 0x2241(%rip), %rsi      # 0x431e
leaq 0x168(%rsp), %rdx
movl %ebp, %ecx
movl 0x24(%rsp), %r8d
movq 0x88(%rsp), %r9
xorl %eax, %eax
pushq 0x18(%rsp)
pushq 0x38(%rsp)
pushq 0x100(%rsp)
pushq 0x28(%rsp)
pushq 0x58(%rsp)
pushq 0x98(%rsp)
pushq %r10
callq 0x1130
jmp 0x2173
testq %r14, %r14
movl 0x7c(%rsp), %eax
movl %eax, %r10d
cmovel 0x40(%rsp), %r10d
subq $0x8, %rsp
leaq 0x21c1(%rip), %rsi      # 0x42f9
leaq 0x168(%rsp), %rdx
movl %ebp, %ecx
movl 0x24(%rsp), %r8d
movq 0x70(%rsp), %r9
xorl %eax, %eax
pushq %r10
pushq 0x90(%rsp)
pushq 0x28(%rsp)
pushq 0x48(%rsp)
pushq 0x110(%rsp)
pushq 0x38(%rsp)
pushq 0x68(%rsp)
callq 0x1130
addq $0x40, %rsp
testl %r13d, %r13d
leaq 0x2086(%rip), %r12      # 0x4207
jle 0x21b1
movq 0xf0(%rsp,%r14,8), %rbp
movq 0xb0(%rsp,%r14,8), %rbx
xorl %r15d, %r15d
movzbl (%rbp,%r15), %eax
movsbl (%rax,%r12), %edi
movq %rbx, %rsi
callq 0x1100
incq %r15
cmpq %r15, %r13
jne 0x2196
movq 0xb0(%rsp,%r14,8), %rdi
leaq 0x2183(%rip), %rsi      # 0x4343
movq 0x60(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1130
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
movl 0x3c(%rsp), %ebp
je 0x2089
movq 0x80(%rsp), %rax
incq %rax
movq 0x50(%rsp), %r14
movq 0xe0(%rsp), %r12
cmpq %r12, %rax
jne 0x1525
movq 0x148(%rsp), %rdi
callq 0x1030
movq 0x158(%rsp), %rdi
callq 0x1030
leaq 0xc0(%rsp), %r13
movq 0x108(%rsp), %rdi
movq %r13, %rsi
leaq 0x160(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2651
testl %eax, %eax
jns 0x144c
jmp 0x2270
movq 0x3da7(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x2063(%rip), %rsi      # 0x42be
leaq 0x160(%rsp), %rdx
movl 0x70(%rsp), %ecx
xorl %eax, %eax
callq 0x1130
jmp 0x2226
movq 0xc8(%rsp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq 0x48(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq