// File: /workspace/github_c_makefile_star2_O2/sc932[P]ALE/src/ALEhelpers.c
// Function: importLibraryParameters
int importLibraryParameters(libraryParametersT *libParams, char paramFile[256]){
  FILE *in = fopen(paramFile, "r");
  int temp;
  if(in == NULL){
    printf("Could not open parameter file: %s\n", paramFile);
    libParams = NULL;
    return 0;
  }else{
    
    // read in the file the same way we outputed it
    char comments[256];
    int j;
    temp = fscanf(in, "%s", comments);
    for(j=0; j < MATE_ORIENTATION_MAX; j++) {
        temp = fscanf(in, "%lf", &libParams->mateParameters[j].insertLength);
        temp = fscanf(in, "%lf", &libParams->mateParameters[j].insertStd);
        temp = fscanf(in, "%lf", &libParams->mateParameters[j].libraryFraction);
        temp = fscanf(in, "%ld", &libParams->mateParameters[j].count);
        temp = fscanf(in, "%ld", &libParams->mateParameters[j].mapped);
        // placed is always calculated
        temp = fscanf(in, "%d", &libParams->mateParameters[j].isValid);

        // These are not stored, but calculated
        libParams->mateParameters[j].placed = 0;
        if (libParams->mateParameters[j].isValid && j <= MAPPED_PAIRED_ORIENTATION) {
        	libParams->mateParameters[j].zNormalizationInsert = zNormalizationInsertStd(libParams->mateParameters[j].insertStd);
        } else {
        	libParams->mateParameters[j].zNormalizationInsert = 1.0;
        }
    }
    temp = fscanf(in, "%ld", &libParams->avgReadSize);
    temp = fscanf(in, "%ld", &libParams->numReads);
    temp = fscanf(in, "%lf", &libParams->totalValidSingleFraction);
    temp = fscanf(in, "%lf", &libParams->totalValidMateFraction);
    temp = fscanf(in, "%lf", &libParams->totalChimerMateFraction);
    temp = fscanf(in, "%lf", &libParams->totalUnmappedFraction);
    temp = fscanf(in, "%d", &libParams->qOff);
    temp = fscanf(in, "%d", &libParams->isSortedByName);
    temp = fscanf(in, "%u", &libParams->primaryOrientation);
    fclose(in);
    printf("Read in library parameters.\n");
    return 1;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x1776c(%rip), %rsi     # 0x21917
movq %r15, %rdi
callq 0x3530
testq %rax, %rax
je 0xa3c1
movq %rax, %r14
leaq 0xee4b(%rip), %rsi      # 0x19011
movq %rsp, %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x30f0
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpq $0x380, %r12            # imm = 0x380
je 0xa2d8
leaq (%rbx,%r12), %rdx
movq %r14, %rdi
leaq 0x15f5f(%rip), %r13     # 0x20153
movq %r13, %rsi
xorl %eax, %eax
callq 0x30f0
leaq (%rbx,%r12), %rbp
addq $0x8, %rbp
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x30f0
leaq (%rbx,%r12), %rdx
addq $0x18, %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x30f0
leaq (%rbx,%r12), %rdx
addq $0x20, %rdx
movq %r14, %rdi
leaq 0x15f1a(%rip), %r13     # 0x20157
movq %r13, %rsi
xorl %eax, %eax
callq 0x30f0
leaq (%rbx,%r12), %rdx
addq $0x28, %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x30f0
leaq (%rbx,%r12), %r13
addq $0x38, %r13
movq %r14, %rdi
leaq 0x14191(%rip), %rsi     # 0x1e3ff
movq %r13, %rdx
xorl %eax, %eax
callq 0x30f0
movsd 0xf7b0(%rip), %xmm3     # 0x19a30
andq $0x0, -0x8(%r13)
movapd %xmm3, %xmm0
cmpq $0x5, %r15
ja 0xa2c5
cmpl $0x0, 0x38(%rbx,%r12)
movapd %xmm3, %xmm0
je 0xa2c5
movsd (%rbp), %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm1, %xmm0
mulsd 0x14f27(%rip), %xmm1    # 0x1f1d8
movapd %xmm3, %xmm2
divsd %xmm1, %xmm2
andpd %xmm0, %xmm2
andnpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movsd %xmm0, 0x10(%rbx,%r12)
incq %r15
addq $0x40, %r12
jmp 0xa1d9
leaq 0x380(%rbx), %rdx
leaq 0x15e71(%rip), %r15     # 0x20157
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x388(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x390(%rbx), %rdx
leaq 0x15e3e(%rip), %r15     # 0x20153
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x398(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x3a0(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x3a8(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x3b0(%rbx), %rdx
leaq 0x14093(%rip), %r15     # 0x1e3ff
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
leaq 0x3b4(%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x30f0
addq $0x3b8, %rbx            # imm = 0x3B8
leaq 0x15dc0(%rip), %rsi     # 0x2015b
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30f0
movq %r14, %rdi
callq 0x31c0
leaq 0x15fbf(%rip), %rdi     # 0x20376
callq 0x3120
pushq $0x1
popq %rbx
jmp 0xa3d4
leaq 0x15d68(%rip), %rdi     # 0x20130
xorl %ebx, %ebx
movq %r15, %rsi
xorl %eax, %eax
callq 0x3210
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq