// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/ALElike.c
// Function: applyUnmapped
void applyUnmapped(bam1_t *read, assemblyT *theAssembly, libraryParametersT *libParams) {
	libraryMateParametersT *primaryMateParameters = &libParams->mateParameters[libParams->primaryOrientation];

	// Pinsert
	double loglikelihoodInsert = log(GetCappedInsertProbNormal(SIGMA_RANGE+1.0, primaryMateParameters->insertStd) / primaryMateParameters->zNormalizationInsert);
	loglikelihoodInsert = validateLogLikelihood( loglikelihoodInsert );

	theAssembly->totalScore += loglikelihoodInsert; // match contribution to totalScore from insert
	theAssembly->insertAvgSum += loglikelihoodInsert;
	theAssembly->insertAvgNorm += 1.0;

	// add placement to total for this unmapped read
	double avgQual = getAverageQualityScoreRead(read, libParams->qOff);
	if (avgQual < 0.25)
		avgQual = 0.25;

	// unplaced likelihood is calculated as having matched bases 1 less than the worst read that mapped (by % identity)
	double logunplacedReadPlacement = ( getLeastIdentity() * read->core.l_qseq - 1.0) * log(avgQual)  // bases that would have matched
			+ ((1.0 - getLeastIdentity()) * read->core.l_qseq + 1.0 )* log((1.0-avgQual)*avgQual); // bases that would have mis-matched

	double logznorm = logzNormalizationReadQual(read, libParams->qOff);
	//printf("Pplacement and Zplacement for unmapped %lf%% identity %lf %lf %lf, %s\n", getLeastIdentity()*100.0, logunplacedReadPlacement, logznorm, logunplacedReadPlacement - logznorm, bam1_qname(read));

	theAssembly->totalScore += validateLogLikelihood( logunplacedReadPlacement - logznorm ); // Pmatch - Zmatch
	//// previously
	//   theAssembly->totalScore += getMinLogLike();

	if (libParams->totalUnmappedFraction > 0) // happens if a read is mapped but not placed...
		theAssembly->totalScore += log(libParams->totalUnmappedFraction); // Porientation
	else
		theAssembly->totalScore += log(0.001); // 0.1%
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x3b8(%rcx), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsd 0x8(%rax), %xmm1
movsd 0x249f2(%rip), %xmm0    # 0x2baa0
callq 0x47d0
movq -0x20(%rbp), %rax
divsd 0x10(%rax), %xmm0
callq 0x3280
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0xbe00
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movq -0x10(%rbp), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x28(%rbp), %xmm0
movq -0x10(%rbp), %rax
addsd 0x38(%rax), %xmm0
movsd %xmm0, 0x38(%rax)
movq -0x10(%rbp), %rax
movsd 0x24939(%rip), %xmm0    # 0x2ba40
addsd 0x40(%rax), %xmm0
movsd %xmm0, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x3b0(%rax), %esi
callq 0x7280
movsd %xmm0, -0x30(%rbp)
movsd 0x24967(%rip), %xmm0    # 0x2ba98
ucomisd -0x30(%rbp), %xmm0
jbe 0x7145
movsd 0x24958(%rip), %xmm0    # 0x2ba98
movsd %xmm0, -0x30(%rbp)
movb $0x0, %al
callq 0xbf10
movq -0x8(%rbp), %rax
cvtsi2sdl 0x10(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x24947(%rip), %xmm1    # 0x2baa8
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x3280
movsd %xmm0, -0x50(%rbp)
movb $0x0, %al
callq 0xbf10
movaps %xmm0, %xmm1
movsd 0x248b5(%rip), %xmm0    # 0x2ba40
subsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
cvtsi2sdl 0x10(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x2489c(%rip), %xmm1    # 0x2ba40
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x2488b(%rip), %xmm0    # 0x2ba40
subsd -0x30(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
callq 0x3280
movsd -0x58(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x48(%rbp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x3b0(%rax), %esi
callq 0x6f20
movsd %xmm0, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
callq 0xbe00
movq -0x10(%rbp), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movsd 0x3a8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x7252
movq -0x18(%rbp), %rax
movsd 0x3a8(%rax), %xmm0
callq 0x3280
movq -0x10(%rbp), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
jmp 0x726d
movsd 0x24856(%rip), %xmm0    # 0x2bab0
callq 0x3280
movq -0x10(%rbp), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)