// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/ALEhelpers.c
// Function: computeLibraryParameters
libraryParametersT *computeLibraryParameters(samfile_t *ins, double outlierFraction, int qOff) {

  int i,j;
  long *mapLens[MATE_ORIENTATION_MAX];

  // allocate memory
  for(i=0; i < MATE_ORIENTATION_MAX; i++)
    mapLens[i] = malloc(sizeof(long)*mapLens_MAX);
  libraryParametersT *libParams = malloc(sizeof(libraryParametersT));

  // initialize
  for(j=0; j < MATE_ORIENTATION_MAX; j++) {
    for(i = 0; i < mapLens_MAX; i++)
      mapLens[j][i] = 0;
    libParams->mateParameters[j].insertLength = 0.0;
    libParams->mateParameters[j].insertStd = 0.0;
    libParams->mateParameters[j].zNormalizationInsert = 1.0;
    libParams->mateParameters[j].count = 0;
    libParams->mateParameters[j].mapped = 0;
    libParams->mateParameters[j].placed = 0;
    libParams->mateParameters[j].isValid = 0;
  }
  // set SINGLE_READ insert parameters
  libParams->mateParameters[SINGLE_READ].insertStd = 1.0;
  libParams->mateParameters[SINGLE_READ].zNormalizationInsert = zNormalizationInsertStd(1.0);

  libParams->qOff = qOff;
  libParams->avgReadSize = 0;
  libParams->numReads = 0;
  libParams->isSortedByName = -1; // undefined
  libParams->primaryOrientation = SINGLE_READ;  // can be only SINGLE_READ or the most abundant of the MAPPED_PAIRED_ORIENTATION


  bam1_t *thisRead = bam_init1();
  long readCount = 0;
  long unmappedReads = 0;
  long chimericReads = 0;
  long improperReads = 0;
  long mappedPairedReads = 0;
  long newNames = 0;
  long newPairedNames = 0;
  long pairedReads = 0;
  char *lastName = strdup("");

  while(1){
    enum MATE_ORIENTATION orientation = readNextBAM(ins, thisRead);

    if (orientation == NO_READS){
      break;
    }

    libraryMateParametersT *mateParams = &libParams->mateParameters[orientation];

    int mapLen = -1;
    switch(orientation) {
      case(VALID_FR):
      case(VALID_RF):
      case(VALID_FF):
      case(NOT_PROPER_FR):
      case(NOT_PROPER_RF):
      case(NOT_PROPER_FF):
        mapLen = getFragmentMapLenBAM(thisRead);
        mappedPairedReads++;
        break;

      case(SINGLE_READ):
      case(UNMAPPED_SINGLE):
        break;

      case(SINGLE_UNMAPPED_MATE):
        break;

      case(CHIMER):
        chimericReads++;
        break;

      case(UNMAPPED_PAIR):
      case(UNMAPPED_MATE):
        break;

      default:
        // should never get here
        printf("Improper read with invalid orientation/pairing: %s\n", lastName);
        improperReads++;
    }

    readCount++;
    mateParams->count++;
    libParams->avgReadSize += thisRead->core.l_qseq;
    libParams->numReads++;
    if (libParams->qOff < 0) {
      libParams->qOff = guessQualityOffset(thisRead);
    }

    if ( (thisRead->core.flag & BAM_FUNMAP) == BAM_FUNMAP ) {
        unmappedReads++;
    } else {
    	mateParams->mapped++;
    }

    if ( (thisRead->core.flag & BAM_FPAIRED) == BAM_FPAIRED ) {
    	pairedReads++;
    }
    if (strcmp(lastName, bam1_qname(thisRead)) != 0){
        newNames++;
        if ( (thisRead->core.flag & BAM_FPAIRED) == BAM_FPAIRED ) {
        	newPairedNames++;
        }
    }
    free(lastName);
    lastName = strdup(bam1_qname(thisRead));

    if (mapLen > 0) {
      mateParams->insertLength += mapLen;
      if (mapLen < mapLens_MAX){
        ++mapLens[orientation][mapLen];
      }
    }

    if (readCount%1000000 == 0){
      printf("Read %ld reads...\n", readCount);
    }
  }
  bam_destroy1(thisRead);
  free(lastName);

  if (pairedReads > 0 && newNames <= readCount/2 && newPairedNames == pairedReads / 2) {
    libParams->isSortedByName = 1;
    printf("Setting library to be sorted by name (%ld new sequential names vs %ld reads)\n", newNames, readCount);
  } else {
    libParams->isSortedByName = 0;
  }

  // zero out top and bottom outliers
  long totalValidMateReads = 0;
  long totalValidSingleReads = 0;
  double maximumFraction = 0.0;
  double pairedReadsFraction = (double) mappedPairedReads / (double) libParams->numReads;
  for(j = 0; j < MATE_ORIENTATION_MAX; j++) {
    libraryMateParametersT *mateParams = &libParams->mateParameters[j];
    //printf("Evaluating %s orientation with %ld reads\n", MATE_ORIENTATION_LABELS[j], mateParams->count);
    long observed = 0;
    long purged = 0;
    long lengthTotal = 0;
    for(i = 0; i < mapLens_MAX; i++) {
      if (observed > (1.0-outlierFraction) * mateParams->count) {
        purged += mapLens[j][i];
        mapLens[j][i] = 0;
      } else {
        observed += mapLens[j][i];
        lengthTotal += i*mapLens[j][i];
      }
      if (observed < outlierFraction * mateParams->count) {
        purged += mapLens[j][i];
        mapLens[j][i] = 0;
      }
    }
    mateParams->libraryFraction = (double) mateParams->count / (double) libParams->numReads;
    if (mateParams->libraryFraction > maximumFraction && j <= MAPPED_PAIRED_ORIENTATION) {
        maximumFraction = mateParams->libraryFraction;
        libParams->primaryOrientation = j;
    }

    if (mateParams->count > 0 && (j == VALID_FR || j == VALID_RF || j == VALID_FF || j == NOT_PROPER_FR || j == NOT_PROPER_RF || j == NOT_PROPER_FF )) {

      // TODO better test for significance and normal distribution for a valid orientation
      if (mateParams->libraryFraction > SIGNIFICANT_LIBRARY_FRACTION * pairedReadsFraction ) {
        mateParams->isValid = 1;
      } else {
        improperReads += mateParams->count;
        mateParams->isValid = 0;
      }

    } else if (mateParams->count > 0 && (j == SINGLE_READ || j == SINGLE_UNMAPPED_MATE)) {
        totalValidSingleReads += mateParams->count;
        mateParams->isValid = 1;
    } else {
        improperReads += mateParams->count;
        mateParams->isValid = 0;
    }

    if (mateParams->isValid == 1) {
      /*printf("Read %ld %s oriented sequences and purged %ld %0.1lf%% & %0.1lf%% outliers.  This %s a valid orientation (%01lf%%)\n",
          mateParams->count,
          MATE_ORIENTATION_LABELS[j],
          purged,
          (outlierFraction*100.0),
          ((1.0-outlierFraction)*100.0),
          mateParams->isValid ? "is" : "is NOT",
          mateParams->libraryFraction*100.0);*/
    }

    long modifiedReadCount = mateParams->count - purged;

    if (mateParams->isValid && j <= MAPPED_PAIRED_ORIENTATION) {
      mateParams->insertLength = (double)lengthTotal/(double)modifiedReadCount;
      for(i = 0; i < mapLens_MAX; i++){
        if(mapLens[j][i] > 0){
          double tmp = mapLens[j][i]*((double)i - mateParams->insertLength)*((double)i - mateParams->insertLength);
          mateParams->insertStd += tmp;
          //printf("i : %s mapLens[i] :: %i : %ld\n", MATE_ORIENTATION_LABELS[j], i, mapLens[j][i]);
        }
      }
      mateParams->insertStd = sqrt(mateParams->insertStd/(double)(modifiedReadCount-1));
      mateParams->zNormalizationInsert = zNormalizationInsertStd(mateParams->insertStd);
      printf("Found %s sample avg insert length to be %lf from %ld mapped reads\n", MATE_ORIENTATION_LABELS[j], mateParams->insertLength, modifiedReadCount);
      printf("Found %s sample insert length std to be %lf\n", MATE_ORIENTATION_LABELS[j], mateParams->insertStd);
      if (mateParams->insertStd > MAXIMUM_STD_DEV_FRACTION * mateParams->insertLength) {
    	  mateParams->isValid = 0;
    	  improperReads += mateParams->count;
    	  printf("stddev is too large (> %lf * insertLength).  This orientation is invalid\n", MAXIMUM_STD_DEV_FRACTION );
      } else {
          totalValidMateReads += mateParams->count;
      }
    }
  }
  printf("There were %ld total reads, %ld paired (%ld properly mated), %ld proper singles, %ld improper reads (%ld chimeric). (%ld reads were unmapped)\n", readCount, pairedReads, totalValidMateReads, totalValidSingleReads, improperReads, chimericReads, unmappedReads);

  libParams->avgReadSize = libParams->avgReadSize / libParams->numReads;

  libParams->totalValidMateFraction = (double) (totalValidMateReads) / (double) libParams->numReads;
  libParams->totalValidSingleFraction = (double) totalValidSingleReads / (double) libParams->numReads;
  libParams->totalChimerMateFraction = (double) (improperReads) / (double) libParams->numReads;
  libParams->totalUnmappedFraction = (double) unmappedReads / (double) libParams->numReads;

  /*printf("ValidMates %0.3lf%%, Single(+half-mapped mate pairs) %0.3lf%%, Improper/ChimerMates %0.3lf%% (Unmapped %0.3lf%%)\n",
          libParams->totalValidMateFraction*100,
          libParams->totalValidSingleFraction*100,
          libParams->totalChimerMateFraction*100,
          libParams->totalUnmappedFraction*100);*/

  // release memory
  for(i=0; i < MATE_ORIENTATION_MAX; i++)
    free(mapLens[i]);

  return libParams;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0xe, -0x18(%rbp)
jge 0xf288
movl $0xc3500, %edi          # imm = 0xC3500
callq 0x3420
movq %rax, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x90(%rbp,%rax,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf25e
movl $0x3c0, %edi            # imm = 0x3C0
callq 0x3420
movq %rax, -0x98(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xe, -0x1c(%rbp)
jge 0xf3a4
movl $0x0, -0x18(%rbp)
cmpl $0x186a0, -0x18(%rbp)   # imm = 0x186A0
jge 0xf2dd
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf2b1
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movsd 0x1c716(%rip), %xmm0    # 0x2ba40
movsd %xmm0, 0x10(%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq $0x0, 0x28(%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq $0x0, 0x30(%rax)
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl $0x0, 0x38(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf2a0
movq -0x98(%rbp), %rax
movsd 0x1c68d(%rip), %xmm0    # 0x2ba40
movsd %xmm0, 0x2c8(%rax)
movsd 0x1c67d(%rip), %xmm0    # 0x2ba40
callq 0xeb70
movq -0x98(%rbp), %rax
movsd %xmm0, 0x2d0(%rax)
movl -0x14(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x3b0(%rax)
movq -0x98(%rbp), %rax
movq $0x0, 0x380(%rax)
movq -0x98(%rbp), %rax
movq $0x0, 0x388(%rax)
movq -0x98(%rbp), %rax
movl $0xffffffff, 0x3b4(%rax) # imm = 0xFFFFFFFF
movq -0x98(%rbp), %rax
movl $0xb, 0x3b8(%rax)
movl $0x1, %edi
movl $0x38, %esi
callq 0x3310
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
leaq 0x22e0e(%rip), %rdi     # 0x322b0
callq 0x3620
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0xe250
movl %eax, -0xec(%rbp)
cmpl $0xd, -0xec(%rbp)
jne 0xf4d2
jmp 0xf786
movq -0x98(%rbp), %rax
movl -0xec(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0xf8(%rbp)
movl $0xffffffff, -0xfc(%rbp) # imm = 0xFFFFFFFF
movl -0xec(%rbp), %eax
movq %rax, -0x158(%rbp)
subq $0xc, %rax
ja 0xf561
movq -0x158(%rbp), %rax
leaq 0x21e18(%rip), %rcx     # 0x31330
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0xa0(%rbp), %rdi
callq 0xddf0
movl %eax, -0xfc(%rbp)
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0xf588
jmp 0xf588
jmp 0xf588
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0xf588
jmp 0xf588
movq -0xe8(%rbp), %rsi
leaq 0x227f9(%rip), %rdi     # 0x31d68
movb $0x0, %al
callq 0x3200
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xf8(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0xa0(%rbp), %rax
movslq 0x10(%rax), %rcx
movq -0x98(%rbp), %rax
addq 0x380(%rax), %rcx
movq %rcx, 0x380(%rax)
movq -0x98(%rbp), %rax
movq 0x388(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x388(%rax)
movq -0x98(%rbp), %rax
cmpl $0x0, 0x3b0(%rax)
jge 0xf611
movq -0xa0(%rbp), %rdi
callq 0x8af0
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x3b0(%rax)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x4, %eax
cmpl $0x4, %eax
jne 0xf642
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb0(%rbp)
jmp 0xf655
movq -0xf8(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x1, %eax
cmpl $0x1, %eax
jne 0xf684
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x3330
cmpl $0x0, %eax
je 0xf6e3
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
andl $0x1, %eax
cmpl $0x1, %eax
jne 0xf6e1
movq -0xd8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
jmp 0xf6e3
movq -0xe8(%rbp), %rdi
callq 0x3050
movq -0xa0(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3620
movq %rax, -0xe8(%rbp)
cmpl $0x0, -0xfc(%rbp)
jle 0xf755
cvtsi2sdl -0xfc(%rbp), %xmm0
movq -0xf8(%rbp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
cmpl $0x186a0, -0xfc(%rbp)   # imm = 0x186A0
jge 0xf753
movl -0xec(%rbp), %eax
movq -0x90(%rbp,%rax,8), %rax
movslq -0xfc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0xf755
movq -0xa8(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0xf781
movq -0xa8(%rbp), %rsi
leaq 0x21525(%rip), %rdi     # 0x30c9f
movb $0x0, %al
callq 0x3200
jmp 0xf4ae
jmp 0xf788
cmpq $0x0, -0xa0(%rbp)
je 0xf7ae
movq -0xa0(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3050
movq -0xa0(%rbp), %rdi
callq 0x3050
jmp 0xf7b0
movq -0xe8(%rbp), %rdi
callq 0x3050
cmpq $0x0, -0xe0(%rbp)
jle 0xf855
movq -0xd0(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0xa8(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jg 0xf855
movq -0xd8(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0xe0(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jne 0xf855
movq -0x98(%rbp), %rax
movl $0x1, 0x3b4(%rax)
movq -0xd0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq 0x22550(%rip), %rdi     # 0x31d9c
movb $0x0, %al
callq 0x3200
jmp 0xf866
movq -0x98(%rbp), %rax
movl $0x0, 0x3b4(%rax)
movq $0x0, -0x108(%rbp)
movq $0x0, -0x110(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x118(%rbp)
cvtsi2sdq -0xc8(%rbp), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x120(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xe, -0x1c(%rbp)
jge 0xfdc5
movq -0x98(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq $0x0, -0x130(%rbp)
movq $0x0, -0x138(%rbp)
movq $0x0, -0x140(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x186a0, -0x18(%rbp)   # imm = 0x186A0
jge 0xfa2c
cvtsi2sdq -0x130(%rbp), %xmm0
movsd 0x1c124(%rip), %xmm1    # 0x2ba40
subsd -0x10(%rbp), %xmm1
movq -0x128(%rbp), %rax
cvtsi2sdq 0x20(%rax), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xf974
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x138(%rbp), %rax
movq %rax, -0x138(%rbp)
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xf9bd
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x130(%rbp), %rax
movq %rax, -0x130(%rbp)
movslq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq -0x90(%rbp,%rcx,8), %rcx
movslq -0x18(%rbp), %rdx
imulq (%rcx,%rdx,8), %rax
addq -0x140(%rbp), %rax
movq %rax, -0x140(%rbp)
cvtsi2sdq -0x130(%rbp), %xmm1
movsd -0x10(%rbp), %xmm0
movq -0x128(%rbp), %rax
cvtsi2sdq 0x20(%rax), %xmm2
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xfa1c
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x138(%rbp), %rax
movq %rax, -0x138(%rbp)
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xfa1e
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf8fe
movq -0x128(%rbp), %rax
cvtsi2sdq 0x20(%rax), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x128(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x128(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd -0x118(%rbp), %xmm0
jbe 0xfa99
cmpl $0x5, -0x1c(%rbp)
ja 0xfa99
movq -0x128(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x3b8(%rax)
movq -0x128(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jle 0xfb26
cmpl $0x0, -0x1c(%rbp)
je 0xfacb
cmpl $0x1, -0x1c(%rbp)
je 0xfacb
cmpl $0x2, -0x1c(%rbp)
je 0xfacb
cmpl $0x3, -0x1c(%rbp)
je 0xfacb
cmpl $0x4, -0x1c(%rbp)
je 0xfacb
cmpl $0x5, -0x1c(%rbp)
jne 0xfb26
movq -0x128(%rbp), %rax
movsd 0x18(%rax), %xmm0
movsd 0x21839(%rip), %xmm1    # 0x31318
mulsd -0x120(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xfafd
movq -0x128(%rbp), %rax
movl $0x1, 0x38(%rax)
jmp 0xfb24
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x128(%rbp), %rax
movl $0x0, 0x38(%rax)
jmp 0xfb92
movq -0x128(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jle 0xfb69
cmpl $0xb, -0x1c(%rbp)
je 0xfb40
cmpl $0x8, -0x1c(%rbp)
jne 0xfb69
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
addq -0x110(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x128(%rbp), %rax
movl $0x1, 0x38(%rax)
jmp 0xfb90
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x128(%rbp), %rax
movl $0x0, 0x38(%rax)
jmp 0xfb92
movq -0x128(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0xfba1
jmp 0xfba1
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
subq -0x138(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x128(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0xfdb5
cmpl $0x5, -0x1c(%rbp)
ja 0xfdb5
cvtsi2sdq -0x140(%rbp), %xmm0
cvtsi2sdq -0x148(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x128(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x18(%rbp)
cmpl $0x186a0, -0x18(%rbp)   # imm = 0x186A0
jge 0xfc90
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jle 0xfc80
movslq -0x1c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movslq -0x18(%rbp), %rcx
cvtsi2sdq (%rax,%rcx,8), %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
movq -0x128(%rbp), %rax
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
movq -0x128(%rbp), %rax
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x150(%rbp), %xmm0
movq -0x128(%rbp), %rax
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
jmp 0xfc82
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xfbfd
movq -0x128(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x148(%rbp), %rax
subq $0x1, %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
callq 0x35f0
movq -0x128(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x128(%rbp), %rax
movsd 0x8(%rax), %xmm0
callq 0xeb70
movq -0x128(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movslq -0x1c(%rbp), %rcx
leaq 0x29e87(%rip), %rax     # 0x39b70
movq (%rax,%rcx,8), %rsi
movq -0x128(%rbp), %rax
movsd (%rax), %xmm0
movq -0x148(%rbp), %rdx
leaq 0x220e4(%rip), %rdi     # 0x31dea
movb $0x1, %al
callq 0x3200
movslq -0x1c(%rbp), %rcx
leaq 0x29e58(%rip), %rax     # 0x39b70
movq (%rax,%rcx,8), %rsi
movq -0x128(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq 0x220fe(%rip), %rdi     # 0x31e2d
movb $0x1, %al
callq 0x3200
movq -0x128(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x128(%rbp), %rax
movsd 0x215cf(%rip), %xmm1    # 0x31320
mulsd (%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xfd9a
movq -0x128(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq 0x220d1(%rip), %rdi     # 0x31e5a
movsd 0x2158f(%rip), %xmm0    # 0x31320
movb $0x1, %al
callq 0x3200
jmp 0xfdb3
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
addq -0x108(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0xfdb5
jmp 0xfdb7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf8b3
movq -0xa8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
movq -0x108(%rbp), %rcx
movq -0x110(%rbp), %r8
movq -0xc0(%rbp), %r9
movq -0xb8(%rbp), %r10
movq -0xb0(%rbp), %rax
leaq 0x220a7(%rip), %rdi     # 0x31ea4
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x3200
movq -0x98(%rbp), %rax
movq 0x380(%rax), %rax
movq -0x98(%rbp), %rcx
cqto
idivq 0x388(%rcx)
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x380(%rax)
cvtsi2sdq -0x108(%rbp), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x98(%rbp), %rax
movsd %xmm0, 0x398(%rax)
cvtsi2sdq -0x110(%rbp), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x98(%rbp), %rax
movsd %xmm0, 0x390(%rax)
cvtsi2sdq -0xc0(%rbp), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x98(%rbp), %rax
movsd %xmm0, 0x3a0(%rax)
cvtsi2sdq -0xb0(%rbp), %xmm0
movq -0x98(%rbp), %rax
cvtsi2sdq 0x388(%rax), %xmm1
divsd %xmm1, %xmm0
movq -0x98(%rbp), %rax
movsd %xmm0, 0x3a8(%rax)
movl $0x0, -0x18(%rbp)
cmpl $0xe, -0x18(%rbp)
jge 0xff15
movslq -0x18(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rdi
callq 0x3050
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xfef3
movq -0x98(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopw %cs:(%rax,%rax)