// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %esi, 0x40(%rsp)
movsd %xmm0, 0x38(%rsp)
movq %rdi, 0x98(%rsp)
xorl %ebx, %ebx
movl $0xc3500, %edi          # imm = 0xC3500
callq 0x3420
movq %rax, 0xc0(%rsp,%rbx,8)
incq %rbx
cmpq $0xe, %rbx
jne 0xc9bc
movl $0x3c0, %edi            # imm = 0x3C0
callq 0x3420
movq %rax, %r15
xorl %ebx, %ebx
movabsq $0x3ff0000000000000, %r14 # imm = 0x3FF0000000000000
movq 0xc0(%rsp,%rbx), %rdi
movl $0xc3500, %edx          # imm = 0xC3500
xorl %esi, %esi
callq 0x3260
xorps %xmm0, %xmm0
movups %xmm0, (%r15,%rbx,8)
movq %r14, 0x10(%r15,%rbx,8)
movups %xmm0, 0x20(%r15,%rbx,8)
movups %xmm0, 0x2c(%r15,%rbx,8)
addq $0x8, %rbx
cmpq $0x70, %rbx
jne 0xc9f0
movapd 0x167e1(%rip), %xmm0    # 0x23210
movupd %xmm0, 0x2c8(%r15)
movl 0x40(%rsp), %eax
movl %eax, 0x3b0(%r15)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x380(%r15)
movabsq $0xbffffffff, %rax      # imm = 0xBFFFFFFFF
movq %r15, 0x50(%rsp)
movq %rax, 0x3b4(%r15)
movl $0x1, %ebx
movl $0x1, %edi
movl $0x38, %esi
callq 0x3310
movq %rax, %r15
leaq 0x17da8(%rip), %rdi     # 0x2482c
callq 0x3630
movq %rax, 0x28(%rsp)
movq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0xbed2
cmpl $0xd, %eax
jne 0xcb18
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x0, %r10d
movl $0x0, %r9d
movl $0x0, %r8d
movl $0x0, %r11d
movl $0x0, %esi
movl $0x0, %ebp
movl $0x0, %edi
movl $0x0, %eax
movl $0x0, %ecx
movq %r15, %r12
movl $0x0, %edx
movq %rdx, 0x8(%rsp)
movl $0x0, %r13d
movl $0x0, %ebx
movl $0x0, %r14d
movl $0x0, %edx
testq %r15, %r15
jne 0xcdba
jmp 0xcdfd
movl %eax, %ebp
xorl %r14d, %r14d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x60(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x90(%rsp)
movq %r15, 0xb8(%rsp)
movq %rbx, 0xa0(%rsp)
movq %rbx, %rax
movabsq $0x431bde82d7b634db, %rcx # imm = 0x431BDE82D7B634DB
mulq %rcx
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
cmpl $0xc, %ebp
movq 0x48(%rsp), %r13
movq 0x78(%rsp), %rax
movq 0x70(%rsp), %rbx
movq %r12, 0x20(%rsp)
movq %rdx, 0x88(%rsp)
ja 0xcd63
movl $0x3f, %ecx
btl %ebp, %ecx
jb 0xcbd6
movl $0x1b40, %ecx           # imm = 0x1B40
btl %ebp, %ecx
jb 0xcbea
cmpl $0x7, %ebp
jne 0xcd63
incq %rax
movq %rax, 0x78(%rsp)
jmp 0xcbea
movq %r15, %rdi
callq 0xbd04
movl %eax, 0x8(%rsp)
incq 0x90(%rsp)
movl %ebp, %r12d
movq %r12, 0x80(%rsp)
shlq $0x6, %r12
movq 0x50(%rsp), %rbx
addq %rbx, %r12
movq %r14, 0x58(%rsp)
leaq 0x1(%r14), %rcx
incq 0x20(%r12)
movslq 0x10(%r15), %rax
movq 0x18(%rsp), %r14
addq %rax, %r14
movq %r14, 0x380(%rbx)
movq %rcx, 0x30(%rsp)
movq %rcx, 0x388(%rbx)
cmpl $0x0, 0x40(%rsp)
jns 0xcc47
movq %r15, %rdi
callq 0x8cc0
movl %eax, 0x40(%rsp)
movl %eax, 0x3b0(%rbx)
movq 0x8(%r15), %rbx
btq $0x22, %rbx
movq %r14, 0x18(%rsp)
jb 0xcc5e
incq 0x28(%r12)
jmp 0xcc66
incq %r13
movq %r13, 0x48(%rsp)
movq 0x60(%rsp), %rax
btq $0x20, %rbx
adcq $0x0, %rax
movq %rax, 0x60(%rsp)
movq 0x30(%r15), %rbp
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3330
xorl %r13d, %r13d
testl %eax, %eax
setne %r15b
movq %r14, %rdi
callq 0x3070
movq %rbp, %rdi
callq 0x3630
movq %rax, 0x28(%rsp)
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
jle 0xcce1
cvtsi2sd %ecx, %xmm0
addsd (%r12), %xmm0
movsd %xmm0, (%r12)
cmpl $0x1869f, %ecx          # imm = 0x1869F
ja 0xcce1
movq 0x80(%rsp), %rax
movq 0xc0(%rsp,%rax,8), %rax
movl %ecx, %ecx
incq (%rax,%rcx,8)
movq 0x88(%rsp), %rax
shrq $0x12, %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
decq %rax
cmpq 0x58(%rsp), %rax
movq 0x30(%rsp), %r14
movq 0x10(%rsp), %r12
jne 0xcd19
leaq 0x15f03(%rip), %rdi     # 0x22c12
movq %r14, %rsi
xorl %eax, %eax
callq 0x3210
shrq $0x20, %rbx
movb %r15b, %r13b
addq %r13, %r12
movq %r12, 0x10(%rsp)
andl %r13d, %ebx
movq 0x20(%rsp), %r12
addq %rbx, %r12
movq 0x98(%rsp), %rdi
movq 0xb8(%rsp), %r15
movq %r15, %rsi
callq 0xbed2
movl %eax, %ebp
movq 0xa0(%rsp), %rbx
incq %rbx
cmpl $0xd, %eax
jne 0xcb6a
jmp 0xcd83
leaq 0x17471(%rip), %rdi     # 0x241db
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x3210
incq %rbx
movq %rbx, 0x70(%rsp)
jmp 0xcbea
xorps %xmm0, %xmm0
cvtsi2sdq 0x90(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r12, %rsi
movq %r15, %r12
movq 0x18(%rsp), %rdi
movq 0x48(%rsp), %r10
movq 0x78(%rsp), %r9
movq 0x70(%rsp), %r8
movq 0x60(%rsp), %r11
movq 0x10(%rsp), %rbp
movq %rbp, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movq 0x30(%r12), %rdi
movq %rsi, %rbx
movq %r8, %r14
movq %r9, %r13
movq %r10, %r15
movq %r11, %rbp
callq 0x3070
movq %r12, %rdi
callq 0x3070
movq %r15, %rax
movq %r13, %rcx
movq %r14, 0x8(%rsp)
movq %rbp, %r13
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %rax, 0x88(%rsp)
movq 0x28(%rsp), %rdi
callq 0x3070
xorl %eax, %eax
testq %r13, %r13
movq 0x50(%rsp), %r12
movq %r13, 0x80(%rsp)
jle 0xd24d
movq 0x30(%rsp), %rcx
shrq %rcx
cmpq %rcx, %r14
movsd 0x38(%rsp), %xmm4
ja 0xce70
movq %r13, %rcx
shrq %rcx
cmpq %rcx, %rbx
jne 0xce70
leaq 0x173b9(%rip), %rdi     # 0x2420f
movq %r14, %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3210
movsd 0x38(%rsp), %xmm4
movl $0x1, %eax
movl %eax, 0x3b4(%r12)
cvtsi2sdq 0x30(%rsp), %xmm6
movsd 0x20(%rsp), %xmm5
divsd %xmm6, %xmm5
movsd 0x10b9f(%rip), %xmm7    # 0x1da30
mulsd 0x16337(%rip), %xmm5    # 0x231d0
subsd %xmm4, %xmm7
xorl %r13d, %r13d
xorpd %xmm8, %xmm8
xorl %ebp, %ebp
movq $0x0, 0x58(%rsp)
movsd %xmm5, 0x20(%rsp)
movq 0x8(%rsp), %rbx
movapd %xmm6, 0x60(%rsp)
movapd %xmm7, 0xa0(%rsp)
movq %r13, %rax
shlq $0x6, %rax
leaq (%r12,%rax), %r15
movq 0x20(%r12,%rax), %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movapd %xmm7, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm0, %xmm2
mulsd %xmm4, %xmm2
movq 0xc0(%rsp,%r13,8), %rax
xorl %esi, %esi
xorl %ecx, %ecx
xorl %edx, %edx
xorl %edi, %edi
xorps %xmm3, %xmm3
cvtsi2sd %rdi, %xmm3
ucomisd %xmm1, %xmm3
movq (%rax,%rsi,8), %r8
jbe 0xcf24
addq %r8, %rdx
movq $0x0, (%rax,%rsi,8)
xorl %r8d, %r8d
jmp 0xcf39
addq %r8, %rdi
movq %r8, %r9
imulq %rsi, %r9
addq %r9, %rcx
xorps %xmm3, %xmm3
cvtsi2sd %rdi, %xmm3
ucomisd %xmm3, %xmm2
jbe 0xcf4a
addq %r8, %rdx
movq $0x0, (%rax,%rsi,8)
incq %rsi
cmpq $0x186a0, %rsi          # imm = 0x186A0
jne 0xcf02
divsd %xmm6, %xmm0
movsd %xmm0, 0x18(%r15)
cmpq $0x5, %r13
ja 0xcf7a
ucomisd %xmm8, %xmm0
jbe 0xcf7a
movl %r13d, 0x3b8(%r12)
movapd %xmm0, %xmm8
cmpq $0x6, %r13
setae %sil
testq %r14, %r14
setle %dil
orb %sil, %dil
jne 0xd043
ucomisd %xmm5, %xmm0
jbe 0xd061
movl $0x1, 0x38(%r15)
cmpq $0x5, %r13
ja 0xd06c
movq %rbp, 0x18(%rsp)
movq %r14, %rbp
subq %rdx, %rbp
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, (%r15)
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
testq %rdx, %rdx
jle 0xd004
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x8(%r15), %xmm0
movsd %xmm0, 0x8(%r15)
incq %rcx
cmpq $0x186a0, %rcx          # imm = 0x186A0
jne 0xcfd4
movsd %xmm2, 0x8(%rsp)
leaq -0x1(%rbp), %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x8(%r15), %xmm0
divsd %xmm1, %xmm0
ucomisd 0x10a5c(%rip), %xmm0    # 0x1da90
movsd %xmm8, 0x10(%rsp)
jb 0xd07e
sqrtsd %xmm0, %xmm0
jmp 0xd083
testq %r14, %r14
jle 0xd061
cmpl $0xb, %r13d
je 0xd054
cmpl $0x8, %r13d
jne 0xd061
addq %r14, %rbp
movl $0x1, 0x38(%r15)
jmp 0xd06c
addq %r14, %rbx
movl $0x0, 0x38(%r15)
incq %r13
cmpq $0xe, %r13
jne 0xceca
jmp 0xd171
callq 0x3600
movsd %xmm0, 0x8(%r15)
movapd %xmm0, %xmm3
movsd %xmm0, 0x28(%rsp)
mulsd 0x1612d(%rip), %xmm0    # 0x231c8
movsd 0x1098d(%rip), %xmm2    # 0x1da30
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm3, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movlpd %xmm0, 0x10(%r15)
leaq 0x1ec73(%rip), %rax     # 0x2bd40
movq (%rax,%r13,8), %r12
leaq 0x17185(%rip), %rdi     # 0x2425d
movq %r12, %rsi
movsd 0x8(%rsp), %xmm0
movq %rbp, %rdx
movb $0x1, %al
callq 0x3210
leaq 0x171ae(%rip), %rdi     # 0x242a0
movq %r12, %rsi
movsd 0x28(%rsp), %xmm0
movb $0x1, %al
callq 0x3210
movsd 0x160ce(%rip), %xmm0    # 0x231d8
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x28(%rsp), %xmm1
ucomisd %xmm2, %xmm1
jbe 0xd13b
movl $0x0, 0x38(%r15)
addq %r14, %rbx
leaq 0x1719b(%rip), %rdi     # 0x242cd
movb $0x1, %al
callq 0x3210
jmp 0xd140
addq %r14, 0x58(%rsp)
movq 0x50(%rsp), %r12
movsd 0x38(%rsp), %xmm4
movsd 0x20(%rsp), %xmm5
movapd 0x60(%rsp), %xmm6
movq 0x18(%rsp), %rbp
movapd 0xa0(%rsp), %xmm7
movsd 0x10(%rsp), %xmm8
jmp 0xd06c
leaq 0x1719f(%rip), %rdi     # 0x24317
movq %rbx, %r9
movq %rbx, 0x8(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp), %r14
movq %r14, %rsi
movq 0x80(%rsp), %rdx
movq 0x58(%rsp), %r13
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
movq 0x88(%rsp), %r15
pushq %r15
pushq 0x50(%rsp)
callq 0x3210
addq $0x10, %rsp
movq 0x40(%rsp), %rax
cqto
idivq %r14
movq %rax, 0x380(%r12)
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movapd 0x60(%rsp), %xmm2
divsd %xmm2, %xmm0
movsd %xmm0, 0x398(%r12)
xorps %xmm0, %xmm0
cvtsi2sd %rbp, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, 0x390(%r12)
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x8(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm1
movupd %xmm1, 0x3a0(%r12)
movq 0xc0(%rsp,%rbx,8), %rdi
callq 0x3070
incq %rbx
cmpq $0xe, %rbx
jne 0xd222
movq %r12, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x38(%rsp), %xmm4
jmp 0xce70