// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/ALElike.c
// Function: realign
void realign(bam1_t *thisRead, assemblyT *theAssembly) {
	assert(realignParameters != NULL && realignParameters->scoringMatrix != NULL);
	int i;

	if ((thisRead->core.flag & BAM_FUNMAP) == BAM_FUNMAP)
		return;

	bam1_core_t *core = &thisRead->core;
	if (core->n_cigar == 1)
		return; // no need to realign such a simple match

	//fprintf(stderr, "Realigning %s %d %d\n", bam1_qname(thisRead), thisRead->core.flag, thisRead->core.pos);

	uint32_t *cigar = bam1_cigar(thisRead);
	uint32_t cigarLen = core->n_cigar;
	int32_t seqLen = core->l_qseq;

	uint8_t *seq = bam1_seq(thisRead);
	STACK_OR_MALLOC(int8_t, seqNum, seqLen);

	// translate sequence to seqNum (which is BAM 4-bit encoding)
	for(i=0; i < seqLen; i++) {
		seqNum[i] = bam1_seqi(seq, i);
	}
	s_profile *profile = ssw_init(seqNum, seqLen, realignParameters->scoringMatrix, NUM_NT_CHARACTERS, 2);
	contig_t *contig = theAssembly->contigs[ core->tid ];
	assert(contig->seqNum != NULL);

	int32_t refAlnLen = bam_calend(core, cigar) - core->pos;
	assert(refAlnLen > 0);
	int32_t maskLen = seqLen / 2;
	if (maskLen < 15)
		maskLen = 15;

	// allow left and right soft clip to re-align upto edges of reference (if there is any)
	int32_t offset = core->pos;
	if (cigarLen > 1 && bam_cigar_op(*cigar) == BAM_CSOFT_CLIP) {
		offset -= bam_cigar_oplen(*cigar);
		refAlnLen += bam_cigar_oplen(*cigar);
		if (offset < 0) {
			refAlnLen += offset; // subtract overhanging fraction
			offset = 0;
		}
		//fprintf(stderr, "extended left soft clip of %s %d pos %d to offset: %d, refAlnLen: %d\n", bam1_qname(thisRead), thisRead->core.flag, thisRead->core.pos, offset, refAlnLen);
	}
	if (cigarLen > 1 && bam_cigar_op(*(cigar + cigarLen - 1)) == BAM_CSOFT_CLIP) {
		refAlnLen += bam_cigar_oplen(*(cigar + cigarLen - 1));
		if (offset + refAlnLen > contig->seqLen) {
			refAlnLen = contig->seqLen - offset;
		}
		//fprintf(stderr, "extended right soft clip of %s %d pos %d to offset: %d refAlnLen: %d\n", bam1_qname(thisRead), thisRead->core.flag, thisRead->core.pos, offset, refAlnLen);
	}
	assert(refAlnLen + offset <= contig->seqLen);

	s_align *result = ssw_align(profile, contig->seqNum + offset, refAlnLen, realignParameters->gapOpenPenalty, realignParameters->gapExtendPenalty, 1, 0, 0, maskLen);
	init_destroy( profile );

	if (result == NULL) {
		fprintf(stderr, "Could not realign %s %d\n", bam1_qname(thisRead), thisRead->core.flag);
	} else {

		// fix softclipping (if needed)
		if (result->read_begin1 != 0 || result->read_end1 != seqLen) {
			// prepare and allocate 4 new cigar operation (all may not be needed)
			result->cigar = realloc(result->cigar, sizeof(int32_t) * (result->cigarLen + 4));
			if (result->cigar == NULL) {
				fprintf(stderr, "Could not allocate 4 more cigar operations!\n");
				abort();
			}

			// handle left side of read / ref
			if (result->read_begin1 != 0) {
				int32_t overlap = result->read_begin1;
				if (overlap > result->ref_begin1)
					overlap = result->ref_begin1;
				assert(overlap >= 0);
				uint32_t c = result->cigar[0];
				if (overlap >= realignParameters->minSoftClip || overlap == 0) {
					// prepend new softclip
					result->cigarLen += 1;
					for(i = result->cigarLen; i > 0 ; i--) {
						result->cigar[i] = result->cigar[i-1];
					}
					// softclip the entire unmapped region of the read
					result->cigar[0] = (result->read_begin1 << 4) | BAM_CSOFT_CLIP;
				} else {
					if (bam_cigar_op(c) == BAM_CMATCH || bam_cigar_op(c) == BAM_CDIFF) {
						// extend existing match/diff length: overlap + existing
						result->cigar[0] = ((bam_cigar_oplen(c) + overlap) << 4) | bam_cigar_op(c);
					} else {
						// prepend new match length: overlap
						result->cigarLen += 1;
						for(i = result->cigarLen; i > 0 ; i--) {
							result->cigar[i] = result->cigar[i-1];
						}
						result->cigar[0] = (overlap << 4) | BAM_CMATCH;
					}
					if (overlap != result->read_begin1) {
						assert(overlap < result->read_begin1);
						// prepend a new softclip (too)
						result->cigarLen += 1;
						for(i = result->cigarLen; i > 0 ; i--) {
							result->cigar[i] = result->cigar[i-1];
						}
						result->cigar[0] = ((result->read_begin1 - overlap) << 4) | BAM_CSOFT_CLIP;
					}
					// match was added or extended, adjust the alignment parameters
					result->read_begin1 -= overlap;
					result->ref_begin1 -= overlap;
				}
			}

			// handle right side of read / ref
			if (result->read_end1 != seqLen - 1) {
				int32_t oplen = seqLen - result->read_end1 - 1;
				int32_t overlap = oplen;
				if (oplen + result->ref_end1 >= refAlnLen ) {
					overlap = refAlnLen - result->ref_end1 - 1;
				}
				assert(overlap >= 0);
				//fprintf(stderr, "Right soft clip fix: oplen %d overlap %d refAlnLen %d read_end %d ref_end %d\n", oplen, overlap, refAlnLen, result->read_end1, result->ref_end1);
				uint32_t c = result->cigar[ result->cigarLen - 1 ];
				if (overlap >= realignParameters->minSoftClip || overlap == 0) {
					// append new softclip for entire remainder of the read
					result->cigar[ result->cigarLen ] = (oplen << 4) | BAM_CSOFT_CLIP;
					result->cigarLen += 1;
				} else {
					if (bam_cigar_op(c) == BAM_CMATCH || bam_cigar_op(c) == BAM_CDIFF) {
						// extend existing match/diff length: overlap + existing
						result->cigar[ result->cigarLen - 1 ] = ((overlap + bam_cigar_oplen(c)) << 4) | bam_cigar_op(c);
					} else {
						// add new match
						result->cigar[ result->cigarLen ] = (oplen << 4) | BAM_CMATCH;
						result->cigarLen += 1;
					}
					if (oplen != overlap) {
						// append a new softclip (too) for the remainder of the read after the reference ends
						assert(oplen > overlap);
						result->cigar[ result->cigarLen ] = ((oplen - overlap) << 4) | BAM_CSOFT_CLIP;
						result->cigarLen += 1;
					} else {
						assert(overlap == oplen);
					}
					// match was added or extended, adjust the alignment parameters
					result->read_end1 += overlap;
					result->ref_end1 += overlap;
				}
			}
		}

		if (result->ref_begin1 != core->pos - offset || result->cigarLen != core->n_cigar || memcmp(result->cigar, cigar, result->cigarLen) != 0) {
			// alignment has changed.  Replace with new alignment
			int printit = 0;
			if (printit) {
				int len = (result->cigarLen + core->n_cigar) * 5;
				char buf[len];
				buildCigarString(buf, cigar, thisRead->core.n_cigar);
				fprintf(stderr, "new alignment for %s %d. old %d-%d qlen %d, %s", bam1_qname(thisRead), core->flag, core->pos, bam_calend(core, cigar), bam_cigar2qlen(core, cigar), buf);

				buildCigarString(buf, result->cigar, result->cigarLen);
				fprintf(stderr, "\tnew %d, %s ", result->ref_begin1 + offset, buf);
			}
			// assign new cigar to this bam record
			int deltaCigarLen = result->cigarLen - thisRead->core.n_cigar;
			assert(thisRead->core.n_cigar + deltaCigarLen >= 1);
			int remainderLen = thisRead->data_len - ((uint8_t*) (bam1_cigar(thisRead) + thisRead->core.n_cigar) - thisRead->data);
			assert(remainderLen >= 0);
			assert(remainderLen ==  thisRead->core.l_qseq + (thisRead->core.l_qseq+1)/2 + thisRead->l_aux);
			if (deltaCigarLen > 0) {
				int deltaDatalen = deltaCigarLen*sizeof(uint32_t);
				if (thisRead->data_len + deltaDatalen > thisRead->m_data) {
					// allocate a new data and copy
					thisRead->m_data = thisRead->data_len + deltaDatalen;
					kroundup32(thisRead->m_data);
					thisRead->data = (uint8_t*) realloc(thisRead->data, thisRead->m_data);
					fprintf(stderr, "reallocated thisread to %d bytes\n", thisRead->m_data);
				}
			}
			// calculate pointers to memory that needs shifting
			cigar = bam1_cigar(thisRead);
			uint8_t *src  = (uint8_t*) (cigar + thisRead->core.n_cigar);
			uint8_t *dest = (uint8_t*) (cigar + (thisRead->core.n_cigar + deltaCigarLen));

			// shift right or left seq, qual, aux
			memmove(dest, src, remainderLen);
			// replace cigar
			memcpy(bam1_cigar(thisRead), result->cigar, result->cigarLen * sizeof(uint32_t));
			// change data_len
			thisRead->data_len += deltaCigarLen * sizeof(uint32_t);
			// change alignment parameters
			thisRead->core.n_cigar = result->cigarLen;
			thisRead->core.pos = result->ref_begin1 + offset;
			bam_fillmd1_core_ALE(thisRead, contig->seq);
			cigar = bam1_cigar(thisRead);
			if (printit) {
				fprintf(stderr, "new pos %d endcoord %d qlen: %d\n", thisRead->core.pos, bam_calend(&thisRead->core, cigar), bam_cigar2qlen(&thisRead->core, cigar));
			}
		}
		align_destroy( result );
	}
	STACK_OR_FREE(seqNum);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, 0x2f66d(%rip)     # 0x3a138
je 0xaadc
movq 0x2f664(%rip), %rax     # 0x3a138
cmpq $0x0, (%rax)
je 0xaadc
jmp 0xaafb
leaq 0x26496(%rip), %rdi     # 0x30f79
leaq 0x252db(%rip), %rsi     # 0x2fdc5
movl $0x966, %edx            # imm = 0x966
leaq 0x264c9(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x4, %eax
jne 0xab1a
jmp 0xb997
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
cmpl $0x1, %eax
jne 0xab38
jmp 0xb997
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movslq -0x30(%rbp), %rax
shlq $0x0, %rax
cmpq $0x400, %rax            # imm = 0x400
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0xabd9
xorl %eax, %eax
movl %eax, -0xd4(%rbp)
jmp 0xabe2
movl -0x30(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq %rsp, %rax
movq %rax, -0x48(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, %rsp
movq %rcx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0xac26
movslq -0x30(%rbp), %rdi
shlq $0x0, %rdi
callq 0x3420
movq %rax, -0x58(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xac6e
movq -0x38(%rbp), %rax
movl -0x14(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x14(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, %dl
movq -0x58(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xac2d
movq -0x58(%rbp), %rdi
movl -0x30(%rbp), %esi
movq 0x2f4bc(%rip), %rax     # 0x3a138
movq (%rax), %rdx
movl $0x10, %ecx
movl $0x2, %r8d
callq 0x10530
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xacba
jmp 0xacd9
leaq 0x26322(%rip), %rdi     # 0x30fe3
leaq 0x250fd(%rip), %rsi     # 0x2fdc5
movl $0x97f, %edx            # imm = 0x97F
leaq 0x262eb(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15e60
movq -0x20(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jle 0xacf8
jmp 0xad17
leaq 0x262fb(%rip), %rdi     # 0x30ffa
leaq 0x250bf(%rip), %rsi     # 0x2fdc5
movl $0x982, %edx            # imm = 0x982
leaq 0x262ad(%rip), %rcx     # 0x30fbf
callq 0x3220
movl -0x30(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x70(%rbp)
cmpl $0xf, -0x70(%rbp)
jge 0xad32
movl $0xf, -0x70(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x74(%rbp)
cmpl $0x1, -0x2c(%rbp)
jbe 0xad88
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0xad88
movq -0x28(%rbp), %rax
movl (%rax), %ecx
shrl $0x4, %ecx
movl -0x74(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x74(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x74(%rbp)
jge 0xad86
movl -0x74(%rbp), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x74(%rbp)
jmp 0xad88
cmpl $0x1, -0x2c(%rbp)
jbe 0xadd3
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl -0x4(%rax,%rcx,4), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0xadd3
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl -0x4(%rax,%rcx,4), %eax
shrl $0x4, %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x74(%rbp), %eax
addl -0x6c(%rbp), %eax
movq -0x68(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0xadd1
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x74(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0xadd3
movl -0x6c(%rbp), %eax
addl -0x74(%rbp), %eax
movq -0x68(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jg 0xade4
jmp 0xae03
leaq 0x2621d(%rip), %rdi     # 0x31008
leaq 0x24fd3(%rip), %rsi     # 0x2fdc5
movl $0x999, %edx            # imm = 0x999
leaq 0x261c1(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rsi
movslq -0x74(%rbp), %rax
addq %rax, %rsi
movl -0x6c(%rbp), %edx
movq 0x2f318(%rip), %rax     # 0x3a138
movb 0xa(%rax), %cl
movq 0x2f30e(%rip), %rax     # 0x3a138
movb 0xb(%rax), %r8b
movl -0x70(%rbp), %eax
movl $0x1, %r9d
xorl %r10d, %r10d
subq $0x20, %rsp
movzbl %cl, %ecx
movzbl %r8b, %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x10920
addq $0x20, %rsp
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
callq 0x108e0
cmpq $0x0, -0x80(%rbp)
jne 0xaeae
movq 0x2e17c(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
leaq 0x2618b(%rip), %rsi     # 0x3102d
movb $0x0, %al
callq 0x3350
jmp 0xb981
movq -0x80(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0xaec8
movq -0x80(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x30(%rbp), %eax
je 0xb3bd
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
addl $0x4, %eax
movslq %eax, %rsi
shlq $0x2, %rsi
callq 0x3470
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x80(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xaf19
movq 0x2e0f5(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
leaq 0x26139(%rip), %rsi     # 0x31046
movb $0x0, %al
callq 0x3350
callq 0x3080
movq -0x80(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0xb186
movq -0x80(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0xaf50
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
jl 0xaf5b
jmp 0xaf7a
leaq 0x26111(%rip), %rdi     # 0x31073
leaq 0x24e5c(%rip), %rsi     # 0x2fdc5
movl $0x9b0, %edx            # imm = 0x9B0
leaq 0x2604a(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
movq 0x2f1a1(%rip), %rcx     # 0x3a138
movsbl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jge 0xafa8
cmpl $0x0, -0x84(%rbp)
jne 0xb00f
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0xaff3
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xafbf
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
shll $0x4, %ecx
orl $0x4, %ecx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
jmp 0xb184
movl -0x88(%rbp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0xb02b
movl -0x88(%rbp), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0xb054
movl -0x88(%rbp), %ecx
shrl $0x4, %ecx
addl -0x84(%rbp), %ecx
shll $0x4, %ecx
movl -0x88(%rbp), %eax
andl $0xf, %eax
orl %eax, %ecx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
jmp 0xb0b5
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0xb09f
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb06b
movl -0x84(%rbp), %ecx
shll $0x4, %ecx
orl $0x0, %ecx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
movl -0x84(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0xb160
movl -0x84(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xb0d9
jmp 0xb0f8
leaq 0x25fa0(%rip), %rdi     # 0x31080
leaq 0x24cde(%rip), %rsi     # 0x2fdc5
movl $0x9c7, %edx            # imm = 0x9C7
leaq 0x25ecc(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0xb143
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb10f
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
subl -0x84(%rbp), %ecx
shll $0x4, %ecx
orl $0x4, %ecx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
movl -0x84(%rbp), %edx
movq -0x80(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
movl -0x84(%rbp), %edx
movq -0x80(%rbp), %rax
movl 0x4(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x4(%rax)
jmp 0xb186
movq -0x80(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xb3bb
movl -0x30(%rbp), %eax
movq -0x80(%rbp), %rcx
subl 0x10(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x8c(%rbp), %eax
movq -0x80(%rbp), %rcx
addl 0x8(%rcx), %eax
cmpl -0x6c(%rbp), %eax
jl 0xb1df
movl -0x6c(%rbp), %eax
movq -0x80(%rbp), %rcx
subl 0x8(%rcx), %eax
subl $0x1, %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jl 0xb1ea
jmp 0xb209
leaq 0x25e82(%rip), %rdi     # 0x31073
leaq 0x24bcd(%rip), %rsi     # 0x2fdc5
movl $0x9dc, %edx            # imm = 0x9DC
leaq 0x25dbb(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x94(%rbp)
movl -0x90(%rbp), %eax
movq 0x2ef04(%rip), %rcx     # 0x3a138
movsbl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jge 0xb245
cmpl $0x0, -0x90(%rbp)
jne 0xb276
movl -0x8c(%rbp), %edx
shll $0x4, %edx
orl $0x4, %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movslq 0x20(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0xb3b9
movl -0x94(%rbp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0xb292
movl -0x94(%rbp), %eax
andl $0xf, %eax
cmpl $0x8, %eax
jne 0xb2cb
movl -0x90(%rbp), %edx
movl -0x94(%rbp), %eax
shrl $0x4, %eax
addl %eax, %edx
shll $0x4, %edx
movl -0x94(%rbp), %eax
andl $0xf, %eax
orl %eax, %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xb2f7
movl -0x8c(%rbp), %edx
shll $0x4, %edx
orl $0x0, %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movslq 0x20(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movl -0x8c(%rbp), %eax
cmpl -0x90(%rbp), %eax
je 0xb368
movl -0x8c(%rbp), %eax
cmpl -0x90(%rbp), %eax
jle 0xb315
jmp 0xb334
leaq 0x25d82(%rip), %rdi     # 0x3109e
leaq 0x24aa2(%rip), %rsi     # 0x2fdc5
movl $0x9ee, %edx            # imm = 0x9EE
leaq 0x25c90(%rip), %rcx     # 0x30fbf
callq 0x3220
movl -0x8c(%rbp), %edx
subl -0x90(%rbp), %edx
shll $0x4, %edx
orl $0x4, %edx
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x80(%rbp), %rcx
movslq 0x20(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0xb399
movl -0x90(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jne 0xb378
jmp 0xb397
leaq 0x25d2f(%rip), %rdi     # 0x310ae
leaq 0x24a3f(%rip), %rsi     # 0x2fdc5
movl $0x9f2, %edx            # imm = 0x9F2
leaq 0x25c2d(%rip), %rcx     # 0x30fbf
callq 0x3220
jmp 0xb399
movl -0x90(%rbp), %ecx
movq -0x80(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x90(%rbp), %ecx
movq -0x80(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
jmp 0xb3bb
jmp 0xb3bd
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl -0x74(%rbp), %ecx
cmpl %ecx, %eax
jne 0xb40b
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jne 0xb40b
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x80(%rbp), %rax
movslq 0x20(%rax), %rdx
callq 0x32e0
cmpl $0x0, %eax
je 0xb978
movl $0x0, -0x98(%rbp)
cmpl $0x0, -0x98(%rbp)
je 0xb585
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x20(%rbp), %rax
movzwl 0xe(%rax), %eax
addl %eax, %ecx
movl %ecx, %eax
leal (%rax,%rax,4), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0xa8(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0xe0(%rbp)
movq %rdi, %rsp
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
movl %eax, %edx
callq 0xb9a0
movq 0x2db6a(%rip), %rax     # 0x38ff8
movq (%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0xec(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xe8(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15e60
movl %eax, -0xe4(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16010
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
movl -0xec(%rbp), %ecx
movl -0xe8(%rbp), %r8d
movl -0xe4(%rbp), %r9d
movl %eax, %r10d
movq -0xe0(%rbp), %rax
leaq 0x25ba0(%rip), %rsi     # 0x310bf
subq $0x10, %rsp
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x3350
movq -0xe0(%rbp), %rdi
addq $0x10, %rsp
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x80(%rbp), %rax
movl 0x20(%rax), %edx
callq 0xb9a0
movq -0xe0(%rbp), %rcx
movq 0x2da98(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x80(%rbp), %rax
movl 0x4(%rax), %edx
addl -0x74(%rbp), %edx
leaq 0x25b7a(%rip), %rsi     # 0x310ee
movb $0x0, %al
callq 0x3350
movq -0xa8(%rbp), %rax
movq %rax, %rsp
movq -0x80(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
subl %ecx, %eax
movl %eax, -0xb4(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
addl -0xb4(%rbp), %eax
cmpl $0x1, %eax
jl 0xb5b9
jmp 0xb5d8
leaq 0x25b3b(%rip), %rdi     # 0x310fb
leaq 0x247fe(%rip), %rsi     # 0x2fdc5
movl $0xa09, %edx            # imm = 0xA09
leaq 0x259ec(%rip), %rcx     # 0x30fbf
callq 0x3220
movq -0x8(%rbp), %rax
movslq 0x24(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x18, %rdx
andq $0xff, %rdx
movslq %edx, %rdx
addq %rdx, %rcx
movq -0x8(%rbp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x30, %rdx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq -0x8(%rbp), %rdx
movq 0x30(%rdx), %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
jl 0xb636
jmp 0xb655
leaq 0x25aea(%rip), %rdi     # 0x31127
leaq 0x24781(%rip), %rsi     # 0x2fdc5
movl $0xa0b, %edx            # imm = 0xA0B
leaq 0x2596f(%rip), %rcx     # 0x30fbf
callq 0x3220
movl -0xb8(%rbp), %eax
movl %eax, -0x104(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x104(%rbp), %eax
addl %edx, %ecx
movq -0x8(%rbp), %rdx
addl 0x20(%rdx), %ecx
cmpl %ecx, %eax
jne 0xb691
jmp 0xb6b0
leaq 0x25aa1(%rip), %rdi     # 0x31139
leaq 0x24726(%rip), %rsi     # 0x2fdc5
movl $0xa0c, %edx            # imm = 0xA0C
leaq 0x25914(%rip), %rcx     # 0x30fbf
callq 0x3220
cmpl $0x0, -0xb4(%rbp)
jle 0xb7ba
movslq -0xb4(%rbp), %rax
shlq $0x2, %rax
movl %eax, -0xbc(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
addl -0xbc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jle 0xb7b8
movq -0x8(%rbp), %rax
movl 0x24(%rax), %ecx
addl -0xbc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
sarl %ecx
movq -0x8(%rbp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
sarl $0x2, %ecx
movq -0x8(%rbp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
sarl $0x4, %ecx
movq -0x8(%rbp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
sarl $0x8, %ecx
movq -0x8(%rbp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
sarl $0x10, %ecx
movq -0x8(%rbp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0x28(%rax), %rsi
callq 0x3470
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq 0x2d858(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x28(%rax), %edx
leaq 0x259de(%rip), %rsi     # 0x3118f
movb $0x0, %al
callq 0x3350
jmp 0xb7ba
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
addl -0xb4(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movslq -0xb8(%rbp), %rdx
callq 0x34c0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
cltq
addq %rax, %rdi
movq -0x80(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x80(%rbp), %rax
movslq 0x20(%rax), %rdx
shlq $0x2, %rdx
callq 0x33b0
movslq -0xb4(%rbp), %rdx
shlq $0x2, %rdx
movq -0x8(%rbp), %rax
movslq 0x24(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x24(%rax)
movq -0x80(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x30, %rdx
movabsq $0xffffffffffff, %rsi   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
movl 0x4(%rax), %ecx
addl -0x74(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2a2b0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x98(%rbp)
je 0xb976
movq 0x2d6dd(%rip), %rax     # 0x38ff8
movq (%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x10c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15e60
movl %eax, -0x108(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x16010
movq -0x118(%rbp), %rdi
movl -0x10c(%rbp), %edx
movl -0x108(%rbp), %ecx
movl %eax, %r8d
leaq 0x25842(%rip), %rsi     # 0x311b1
movb $0x0, %al
callq 0x3350
jmp 0xb978
movq -0x80(%rbp), %rdi
callq 0x14180
cmpl $0x0, -0x3c(%rbp)
je 0xb990
movq -0x58(%rbp), %rdi
callq 0x3050
movq -0x48(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)