// File: /workspace/github_c_makefile_star2_O3/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 0x19457(%rip), %rsi     # 0x259c7
movq %r15, %rdi
callq 0x3530
testq %rax, %rax
je 0xc786
movq %rax, %r14
leaq 0x10a86(%rip), %rsi     # 0x1d011
movq %rsp, %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x30f0
xorl %r12d, %r12d
xorl %r15d, %r15d
leaq (%rbx,%r12), %rdx
movq %r14, %rdi
leaq 0x17bd7(%rip), %r13     # 0x24183
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 0x17b92(%rip), %r13     # 0x24187
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 0x15e09(%rip), %rsi     # 0x2242f
movq %r13, %rdx
xorl %eax, %eax
callq 0x30f0
movsd 0x113f8(%rip), %xmm3    # 0x1da30
movq $0x0, -0x8(%r13)
movapd %xmm3, %xmm0
cmpq $0x5, %r15
ja 0xc680
cmpl $0x0, 0x38(%rbx,%r12)
movapd %xmm3, %xmm0
je 0xc680
movsd (%rbp), %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm1, %xmm0
mulsd 0x16b5c(%rip), %xmm1    # 0x231c8
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
cmpq $0x380, %r12            # imm = 0x380
jne 0xc59e
leaq 0x380(%rbx), %rdx
leaq 0x17ade(%rip), %r15     # 0x24187
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 0x17aab(%rip), %r15     # 0x24183
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 0x15d00(%rip), %r15     # 0x2242f
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 0x17a2d(%rip), %rsi     # 0x2418b
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30f0
movq %r14, %rdi
callq 0x31c0
leaq 0x17c2c(%rip), %rdi     # 0x243a6
callq 0x3120
movl $0x1, %ebx
jmp 0xc799
leaq 0x179d3(%rip), %rdi     # 0x24160
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