// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/ALElike.c
// Function: getContributionsForPositions
double getContributionsForPositions(bam1_t *read, contig_t *contig, int qOff, int alignmentLength, float *depthPositions, double *loglikelihoodPositions, int applySoftClip) {
  int i,j;
  int seqPos = 0;
  int refPos = 0;
  int matches = 0;
  int readlen = read->core.l_qseq;
  char *contigSeq = contig->seq;
  double softclipContribution = 0.0;

  if(read == NULL){
	for(refPos = 0; refPos < alignmentLength; refPos++) {
		depthPositions[refPos] = 0.0;
		loglikelihoodPositions[refPos] = getMinLogLike();
	}
	return softclipContribution;
  }
  assert((read->core.flag & BAM_FUNMAP) == 0);

  // read CIGAR first
  uint32_t *cigar = bam1_cigar(read);
  char *readQual = (char*) bam1_qual(read);
  char *MD = getMD(read, contigSeq);
  int numCigarOperations = read->core.n_cigar;
  int ref2seqPos[alignmentLength];

  // initialize loglikelihoodPositions
  for(j=0; j < alignmentLength; j++) {
    loglikelihoodPositions[j] = 0.0;
  }

  for(i=0 ; i < numCigarOperations ; i++) {
    uint32_t cigarInt = *(cigar+i);
    uint32_t cigarFlag = (cigarInt & BAM_CIGAR_MASK);
    uint32_t count = (cigarInt >> BAM_CIGAR_SHIFT);
    ////printf("CIGAR: %u %u %u\n", cigarInt, cigarFlag, count);
    switch (cigarFlag) {
      case(BAM_CMATCH): // match or mismatch
      case(BAM_CEQUAL): // match
      case(BAM_CDIFF):  // mismatch (will be distinguished from match in MD field)
        matches += count;
        for(j=0; j < count; j++) {
        	loglikelihoodPositions[refPos+j] += loglikeMatch(readQual, seqPos+j, 1, qOff);
        	depthPositions[refPos+j] = 1.0;
		    ref2seqPos[refPos+j] = seqPos+j;
        }
        seqPos += count;
        refPos += count;
        break;
      case(BAM_CINS)   : // insertion to the reference.
	if (refPos + 1 < contig->seqLen) {
		double insPenalty = loglikeInsertion(readQual, seqPos, count, qOff) / 2;
		loglikelihoodPositions[refPos] += insPenalty;
		loglikelihoodPositions[refPos+1] += insPenalty;
	} else
		loglikelihoodPositions[refPos] += loglikeInsertion(readQual, seqPos, count, qOff);
        // only increment seqPos
        seqPos += count;
        break;
      case(BAM_CDEL): // deletion from the reference
	{
		assert(refPos + count <= contig->seqLen);
		double delPenalty = loglikeDeletion(readQual, seqPos, count, qOff, readlen) / count;
		for(j=refPos; j < refPos+count; j++) {
			loglikelihoodPositions[j] += delPenalty;
			depthPositions[j] = 0.0;
			ref2seqPos[j] = seqPos;
		}
	}
        // only increment refPos
        refPos += count;
        break;
      case(BAM_CREF_SKIP):
        // assume this is a spliced alignment for RNA, so okay, but no data
        // only increment refPos
		for(j=refPos; j < refPos+count; j++) {
			depthPositions[j] = 0.0;
			ref2seqPos[j] = seqPos;
		}
		refPos += count;
        break;
      case(BAM_CPAD): // silent deletion from padded reference (not in reference or query)
      case(BAM_CHARD_CLIP):
		// hard clipped region is not represented in sequence or quality string, so no information is available for analysis
        break;
      case(BAM_CSOFT_CLIP):
        // soft clipped sequences present in SEQ
        // apply mismatches to clipped portion of the read against the contig past the alignment
        if (seqPos == 0) {
        	// SoftClipped to the left
        	int refPos2 = refPos - count;
        	if (refPos2 < 0) refPos2 = 0;
        	int span = refPos - refPos2;
        	double logMiss = loglikeMiss(readQual, seqPos + count - span, span, qOff);
        	if (applySoftClip)
        		for(j=refPos2; j < refPos; j++)
        			contig->matchLogLikelihood[j] += logMiss / span;
        	softclipContribution += logMiss; // Zmatch already accounts for clipped bases (entire read)
        } else {
        	// SoftClipped to the right
        	int refPos2 = refPos + count;
        	if (refPos2 >= contig->seqLen) refPos2 = contig->seqLen - 1;
        	int span = refPos2 - refPos;
        	double logMiss = loglikeMiss(readQual, seqPos, span, qOff);
        	if (applySoftClip)
        		for(j=refPos; j < refPos2; j++)
        			contig->matchLogLikelihood[j] += logMiss / span;
        	softclipContribution += logMiss; // Zmatch already accounts for clipped bases (entire read)
        }
        seqPos += count;
        readlen -= count;
        break;
    }
  }
  if ((seqPos != read->core.l_qseq) || (refPos != alignmentLength)) {
        fprintf(stderr, "WARNING: Read CIGAR does not match sequence and/or reference alignment lengths: %s %d: seqPos %d seqLen: %d refPos %d alignmentLen: %d\n", bam1_qname(read), read->core.flag, seqPos, read->core.l_qseq, refPos, alignmentLength);
  }

  // now process MD field
  refPos = 0;
  if (MD != NULL && MD[0] == 'Z') {
	  int stop = 0;
	  int pos = 1;

	  // parse MD field
	  while(stop == 0){
	    // matches
	    int seqCount = 0;
	    while(isdigit(MD[pos])){
	        seqCount = seqCount*10 + (int)(MD[pos]) - 48; // chr(48) == '0'
	        pos++;
	    }
	    refPos += seqCount;

	    double logMatch;
	    double logMiss;
	    // misses
	    int baseAmbiguity = 0;
	    while((baseAmbiguity = getBaseAmbibuity(MD[pos])) > 0){
	      char seqBase = contig->seq[refPos + read->core.pos];
	      if (seqBase != MD[pos]) {
	    	  fprintf(stderr, "WARNING: MD field calls mismatch but it does agree with the reference! %s %d: refpos %d MDpos %d: '%c' vs '%c'\n", bam1_qname(read), read->core.flag, refPos+read->core.pos, pos, seqBase, MD[pos]);
	      }
          seqPos = ref2seqPos[refPos];
	      logMatch = loglikeMatch(readQual, seqPos, 1, qOff);
	      if(baseAmbiguity == 1){
	          logMiss = loglikeMiss(readQual, seqPos, 1, qOff);
	      } else {
	    	  if (baseAmbiguity == 4 || isAmbiguousMatch(seqBase, bam1_seq(read)[seqPos]) == 0) {
	    		  logMiss = log(1.0/(float)baseAmbiguity);
	    	  } else {
	    		  // ambiguous match, so offset this mismatch hit (i.e. make the following statements a noop)
	    		  matches++;
	    		  logMiss = logMatch;
	    	  }
	      }
          // logMatch was already applied, so replace it with logMiss
	      loglikelihoodPositions[refPos] += logMiss - logMatch;

	      refPos++;
	      pos++;
	      matches--;
	      ////printf("MD %d miss  %d. %f\n", seqPos, 1, loglikelihood);
	    }

	    // deletions
	    if(MD[pos] == '^'){
	      pos++;
	      while(isalpha(MD[pos])){
	        pos++;
	        refPos++;
	      }
	    }

	    // sees if we are at the end
	    if(MD[pos] == '\0'){
	      stop = 1;
	      continue;
	    }
	  }
	  if (refPos != alignmentLength) fprintf(stderr, "WARNING: CIGAR and MD field disagree on match region for %s\n", bam1_qname(read));
  } else {
	  printf("WARNING: could not find the MD tag for %s\n", bam1_qname(read));
  }

  double identity = ((double)matches) / ((double) readlen);
  setLeastIdentity(identity);

  return softclipContribution;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4eeb
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x4edc
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movb $0x0, %al
callq 0xbdf0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4ea5
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x58b8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x4f07
jmp 0x4f26
leaq 0x2afd9(%rip), %rdi     # 0x2fee7
leaq 0x2aeb0(%rip), %rsi     # 0x2fdc5
movl $0x209, %edx            # imm = 0x209
leaq 0x2afea(%rip), %rcx     # 0x2ff0b
callq 0x3220
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rax
movzbl 0xb(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rax
movq 0x8(%rcx), %rdx
movq %rdx, %rsi
shrq $0x30, %rsi
leaq (%rax,%rsi,4), %rax
shrl $0x18, %edx
addq %rdx, %rax
movl 0x10(%rcx), %ecx
incl %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x4800
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
movl %eax, -0x74(%rbp)
movl -0x20(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x80(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x100(%rbp)
movq %rcx, %rsp
movq %rax, -0x88(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x4fda
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4fb7
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x5489
movq -0x60(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x90(%rbp)
movl -0x8c(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x94(%rbp)
movl -0x90(%rbp), %eax
movq %rax, -0x108(%rbp)
subq $0x8, %rax
ja 0x5479
movq -0x108(%rbp), %rax
leaq 0x26b77(%rip), %rcx     # 0x2bbb8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x94(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x94(%rbp), %eax
jae 0x50d4
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
addl -0x38(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x1, %edx
callq 0x49f0
movq -0x100(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x40(%rbp), %edx
addl -0x38(%rbp), %edx
movslq %edx, %rdx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movq -0x28(%rbp), %rcx
movl -0x40(%rbp), %edx
addl -0x38(%rbp), %edx
movslq %edx, %rdx
movss 0x2acfe(%rip), %xmm0    # 0x2fdb0
movss %xmm0, (%rcx,%rdx,4)
movl -0x3c(%rbp), %edx
addl -0x38(%rbp), %edx
movl -0x40(%rbp), %ecx
addl -0x38(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x505d
movl -0x94(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x94(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x5479
movl -0x40(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x5164
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x94(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x4a90
movsd 0x2696b(%rip), %xmm1    # 0x2ba88
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd -0xa0(%rbp), %xmm0
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x518b
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x94(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x4a90
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x94(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x5479
movl -0x40(%rbp), %eax
addl -0x94(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x51b0
jmp 0x51cf
leaq 0x2adb0(%rip), %rdi     # 0x2ff67
leaq 0x2ac07(%rip), %rsi     # 0x2fdc5
movl $0x235, %edx            # imm = 0x235
leaq 0x2ad41(%rip), %rcx     # 0x2ff0b
callq 0x3220
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x94(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x48(%rbp), %r8d
callq 0x4ad0
movl -0x94(%rbp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
addl -0x94(%rbp), %ecx
cmpl %ecx, %eax
jae 0x525b
movq -0x100(%rbp), %rax
movsd -0xa8(%rbp), %xmm0
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movq -0x28(%rbp), %rcx
movslq -0x38(%rbp), %rdx
xorps %xmm0, %xmm0
movss %xmm0, (%rcx,%rdx,4)
movl -0x3c(%rbp), %edx
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5205
movl -0x94(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x5479
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
addl -0x94(%rbp), %ecx
cmpl %ecx, %eax
jae 0x52ae
movq -0x100(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x38(%rbp), %rdx
xorps %xmm0, %xmm0
movss %xmm0, (%rcx,%rdx,4)
movl -0x3c(%rbp), %edx
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5272
movl -0x94(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x5479
jmp 0x5479
cmpl $0x0, -0x3c(%rbp)
jne 0x5399
movl -0x40(%rbp), %eax
subl -0x94(%rbp), %eax
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jge 0x52f0
movl $0x0, -0xac(%rbp)
movl -0x40(%rbp), %eax
subl -0xac(%rbp), %eax
movl %eax, -0xb0(%rbp)
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
addl -0x94(%rbp), %esi
subl -0xb0(%rbp), %esi
movl -0xb0(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x4950
movsd %xmm0, -0xb8(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x5382
movl -0xac(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x5380
movsd -0xb8(%rbp), %xmm1
cvtsi2sdl -0xb0(%rbp), %xmm0
divsd %xmm0, %xmm1
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5337
jmp 0x5382
movsd -0xb8(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x545f
movl -0x40(%rbp), %eax
addl -0x94(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jl 0x53c7
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0xc0(%rbp)
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0xc0(%rbp), %edx
movl -0x1c(%rbp), %ecx
callq 0x4950
movsd %xmm0, -0xc8(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x544d
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0x544b
movsd -0xc8(%rbp), %xmm1
cvtsi2sdl -0xc0(%rbp), %xmm0
divsd %xmm0, %xmm1
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x53ff
jmp 0x544d
movsd -0xc8(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x94(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x94(%rbp), %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x48(%rbp)
jmp 0x547b
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4fe1
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x549d
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x54f4
movq 0x33b54(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movl -0x3c(%rbp), %r8d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %r9d
movl -0x40(%rbp), %r10d
movl -0x20(%rbp), %eax
leaq 0x2aaab(%rip), %rsi     # 0x2ff88
subq $0x10, %rsp
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x3350
addq $0x10, %rsp
movl $0x0, -0x40(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x586e
movq -0x70(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5a, %eax
jne 0x586e
movl $0x0, -0xcc(%rbp)
movl $0x1, -0xd0(%rbp)
cmpl $0x0, -0xcc(%rbp)
jne 0x5844
movl $0x0, -0xd4(%rbp)
callq 0x36a0
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movslq -0xd0(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x559b
imull $0xa, -0xd4(%rbp), %eax
movq -0x70(%rbp), %rcx
movslq -0xd0(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
subl $0x30, %eax
movl %eax, -0xd4(%rbp)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x5541
movl -0xd4(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0xec(%rbp)
movq -0x70(%rbp), %rax
movslq -0xd0(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x4bb0
movl %eax, -0xec(%rbp)
cmpl $0x0, %eax
jle 0x57b5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rdx
addl 0x4(%rdx), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0xed(%rbp)
movsbl -0xed(%rbp), %eax
movq -0x70(%rbp), %rcx
movslq -0xd0(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x567a
movq 0x339e5(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, %ecx
movl -0x40(%rbp), %r8d
movq -0x10(%rbp), %rax
addl 0x4(%rax), %r8d
movl -0xd0(%rbp), %r9d
movsbl -0xed(%rbp), %r10d
movq -0x70(%rbp), %rax
movslq -0xd0(%rbp), %rsi
movsbl (%rax,%rsi), %eax
leaq 0x2a9ad(%rip), %rsi     # 0x30010
subq $0x10, %rsp
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x3350
addq $0x10, %rsp
movq -0x100(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x1, %edx
callq 0x49f0
movsd %xmm0, -0xe0(%rbp)
cmpl $0x1, -0xec(%rbp)
jne 0x56d1
movq -0x68(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x1c(%rbp), %ecx
movl $0x1, %edx
callq 0x4950
movsd %xmm0, -0xe8(%rbp)
jmp 0x576d
cmpl $0x4, -0xec(%rbp)
je 0x572b
movb -0xed(%rbp), %dl
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movslq -0x3c(%rbp), %rcx
movsbl %dl, %edi
movsbl (%rax,%rcx), %esi
callq 0x4c20
cmpl $0x0, %eax
jne 0x5752
cvtsi2ssl -0xec(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x26301(%rip), %xmm0    # 0x2ba40
divsd %xmm1, %xmm0
callq 0x3280
movsd %xmm0, -0xe8(%rbp)
jmp 0x576b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
jmp 0x576d
movsd -0xe8(%rbp), %xmm0
subsd -0xe0(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x55b1
movq -0x70(%rbp), %rax
movslq -0xd0(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5e, %eax
jne 0x581c
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
callq 0x36a0
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movslq -0xd0(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x581a
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x57d8
jmp 0x581c
movq -0x70(%rbp), %rax
movslq -0xd0(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x583f
movl $0x1, -0xcc(%rbp)
jmp 0x552a
jmp 0x552a
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x586c
movq 0x337a5(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0x2a81b(%rip), %rsi     # 0x30080
movb $0x0, %al
callq 0x3350
jmp 0x5884
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
leaq 0x2a840(%rip), %rdi     # 0x300bd
movb $0x0, %al
callq 0x3200
cvtsi2sdl -0x44(%rbp), %xmm0
cvtsi2sdl -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0xf8(%rbp), %xmm0
callq 0xbee0
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, %rsp
movsd -0x8(%rbp), %xmm0
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)