// File: /workspace/github_c_makefile_star2_O1/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 0x195ea(%rip), %rsi     # 0x258e7
movq %r15, %rdi
callq 0x3530
testq %rax, %rax
je 0xc513
movq %rax, %r14
leaq 0x10cf9(%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 0x17dba(%rip), %r13     # 0x240f3
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 0x17d75(%rip), %r13     # 0x240f7
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 0x1601c(%rip), %rsi     # 0x223cf
movq %r13, %rdx
xorl %eax, %eax
callq 0x30f0
movsd 0x11673(%rip), %xmm3    # 0x1da38
movq $0x0, -0x8(%r13)
movapd %xmm3, %xmm0
cmpq $0x5, %r15
ja 0xc40d
cmpl $0x0, 0x38(%rbx,%r12)
movapd %xmm3, %xmm0
je 0xc40d
movsd (%rbp), %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm1, %xmm0
mulsd 0x16d67(%rip), %xmm1    # 0x23160
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 0xc32b
leaq 0x380(%rbx), %rdx
leaq 0x17cc1(%rip), %r15     # 0x240f7
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 0x17c8e(%rip), %r15     # 0x240f3
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 0x15f13(%rip), %r15     # 0x223cf
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 0x17c10(%rip), %rsi     # 0x240fb
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30f0
movq %r14, %rdi
callq 0x31c0
leaq 0x17e0f(%rip), %rdi     # 0x24316
callq 0x3120
movl $0x1, %ebx
jmp 0xc526
leaq 0x17bb6(%rip), %rdi     # 0x240d0
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