// File: /workspace/github_c_makefile_star2_O1/sc932[P]ALE/src/ALEhelpers.c
// Function: calculateContigGCcont
unsigned char *calculateContigGCcont(contig_t *contig, int windowSize) {
	int j, baseGC;
	int *GCpast = malloc(sizeof(int) * windowSize);
	unsigned char *GCcont = (unsigned char*) malloc(sizeof(unsigned char) * contig->seqLen);
	if (contig->seqLen < 2 * windowSize) {
		// contig is too small to estimate per-base windowing
		baseGC = getGCtotal(contig->seq, contig->seqLen);
		baseGC = floor(100.0*(double)baseGC / (double) contig->seqLen);
		for(j=0; j < contig->seqLen ; j++) {
			GCcont[j] = baseGC;
		}
	} else {
		baseGC = getGCtotal(contig->seq, windowSize);
		GCpast[0] = baseGC;
		for(j = 0; j < windowSize - 1; j++){
			GCcont[j] = floor(100.0*(double)baseGC/(double)((j+1)*windowSize));
			if (GCcont[j] > 100)
				printf("GC correction out of range %d %s %d len %d '%c'\n", baseGC, contig->name, j, contig->seqLen, contig->seq[j]);
			GCpast[(j+1)%windowSize] = GCpast[j%windowSize];
			if(isGC(contig->seq[j])){
				GCpast[(j+1)%windowSize]--;
			}
			if(isGC(contig->seq[j+windowSize])){
				GCpast[(j+1)%windowSize]++;
			}
			baseGC += GCpast[(j+1)%windowSize];
		}
		for(j = windowSize - 1; j < contig->seqLen - windowSize; j++){
			GCcont[j] = floor(100.0*(double)baseGC/(double)(windowSize*windowSize));
			if (GCcont[j] > 100)
				printf("GC correction out of range %d %s %d len %d '%c'\n", baseGC, contig->name, j, contig->seqLen, contig->seq[j]);
			baseGC -= GCpast[(j+1)%windowSize];
			GCpast[(j+1)%windowSize] = GCpast[j%windowSize];
			if(isGC(contig->seq[j])){
				GCpast[(j+1)%windowSize]--;
			}
			if(isGC(contig->seq[j+windowSize])) {
				GCpast[(j+1)%windowSize]++;
			}
			baseGC += GCpast[(j+1)%windowSize];
		}
		for(j = contig->seqLen - windowSize; j < contig->seqLen; j++){
			GCcont[j] = floor(100.0*(double)baseGC/(double)((contig->seqLen - j)*windowSize));
			if (GCcont[j] > 100)
				printf("GC correction out of range %d %s %d len %d '%c'\n", baseGC, contig->name, j, contig->seqLen, contig->seq[j]);
			baseGC -= GCpast[(j+1)%windowSize];
		}
	}
	free(GCpast);
	return GCcont;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %r12d
movq %rdi, %r14
movslq %esi, %r13
leaq (,%r13,4), %rdi
callq 0x3420
movq %rax, %rbx
movslq 0x8(%r14), %r15
movq %r15, %rdi
callq 0x3420
movq %rax, 0x10(%rsp)
movq %r13, 0x30(%rsp)
leal (,%r13,2), %ecx
movq %r14, 0x8(%rsp)
movq 0x10(%r14), %rax
cmpl %ecx, %r15d
jge 0xb6c3
testl %r15d, %r15d
jle 0xb70b
xorl %ecx, %ecx
movabsq $0x1000000011, %rdx     # imm = 0x1000000011
xorl %esi, %esi
movzbl (%rax,%rcx), %edi
leal -0x43(%rdi), %r9d
cmpl $0x24, %r9d
ja 0xb69f
movl $0x1, %r8d
btq %r9, %rdx
jb 0xb6aa
xorl %r8d, %r8d
cmpb $0x63, %dil
sete %r8b
addl %r8d, %esi
incq %rcx
cmpq %rcx, %r15
jne 0xb685
cvtsi2sd %esi, %xmm0
mulsd 0x17a97(%rip), %xmm0    # 0x23158
jmp 0xb70f
movl %r12d, %r14d
testl %r12d, %r12d
movq %r12, %r9
jle 0xb73c
xorl %ecx, %ecx
movabsq $0x1000000011, %rdx     # imm = 0x1000000011
xorl %ebp, %ebp
movzbl (%rax,%rcx), %esi
leal -0x43(%rsi), %r8d
cmpl $0x24, %r8d
ja 0xb6f5
movl $0x1, %edi
btq %r8, %rdx
jb 0xb6ff
xorl %edi, %edi
cmpb $0x63, %sil
sete %dil
addl %edi, %ebp
incq %rcx
cmpq %rcx, %r14
jne 0xb6dc
jmp 0xb73e
xorpd %xmm0, %xmm0
testl %r15d, %r15d
jle 0xb9fa
cvtsi2sd %r15d, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %esi
movq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0x3260
jmp 0xb9fa
xorl %ebp, %ebp
movl %ebp, (%rbx)
leal -0x1(%r9), %eax
cmpl $0x2, %r9d
movq %r9, 0x18(%rsp)
movl %eax, 0x24(%rsp)
jl 0xb830
movl %eax, %r12d
movl %r9d, %r13d
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x179e9(%rip), %xmm0    # 0x23158
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r15)
cmpb $0x65, %al
jb 0xb7b9
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movl 0x8(%rax), %r8d
movq 0x10(%rax), %rax
movsbl (%rax,%r15), %r9d
leaq 0x18565(%rip), %rdi     # 0x23d12
movl %ebp, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3210
movl %r15d, %eax
xorl %edx, %edx
movq 0x18(%rsp), %r9
divl %r9d
movl (%rbx,%rdx,4), %ecx
movl %ecx, 0x4(%rbx,%r15,4)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movb (%rax,%r15), %dl
addb $-0x43, %dl
rolb $0x6, %dl
cmpb $0x9, %dl
ja 0xb7fa
movzbl %dl, %edx
movl $0x303, %esi            # imm = 0x303
btl %edx, %esi
jae 0xb7fa
decl %ecx
movl %ecx, 0x4(%rbx,%r15,4)
movb (%rax,%r14), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0xb819
movzbl %al, %eax
movl $0x303, %ecx            # imm = 0x303
btl %eax, %ecx
jae 0xb819
incl 0x4(%rbx,%r15,4)
addl 0x4(%rbx,%r15,4), %ebp
incq %r15
incq %r14
addl %r9d, %r13d
cmpq %r15, %r12
jne 0xb760
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r14d
movl %r14d, %r12d
subl %r9d, %r12d
cmpl %r9d, %r12d
jl 0xb94f
movl %r9d, %eax
imull %r9d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x24(%rsp), %r13
movl %r9d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x178e5(%rip), %xmm0    # 0x23158
divsd 0x28(%rsp), %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r13)
cmpb $0x65, %al
jb 0xb8b7
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rax
movsbl (%rax,%r13), %r9d
leal -0x1(%r15), %ecx
leaq 0x18467(%rip), %rdi     # 0x23d12
movl %ebp, %esi
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3210
movl %r15d, %eax
cltd
movq 0x18(%rsp), %r9
idivl %r9d
movslq %edx, %rcx
subl (%rbx,%rcx,4), %ebp
leal -0x1(%r15), %eax
cltd
idivl %r9d
movslq %edx, %rax
movl (%rbx,%rax,4), %edx
movl %edx, (%rbx,%rcx,4)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movb (%rax,%r13), %sil
addb $-0x43, %sil
rolb $0x6, %sil
cmpb $0x9, %sil
ja 0xb908
movzbl %sil, %esi
movl $0x303, %edi            # imm = 0x303
btl %esi, %edi
jae 0xb908
decl %edx
movl %edx, (%rbx,%rcx,4)
addq 0x30(%rsp), %rax
movb (%r13,%rax), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0xb92b
movzbl %al, %eax
movl $0x303, %edx            # imm = 0x303
btl %eax, %edx
jae 0xb92b
incl (%rbx,%rcx,4)
incq %r13
addl (%rbx,%rcx,4), %ebp
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r14d
movl %r14d, %r12d
subl %r9d, %r12d
movslq %r12d, %rax
incl %r15d
cmpq %rax, %r13
jl 0xb864
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r14d
cmpl %r14d, %r12d
jge 0xb9fa
movslq %r12d, %r15
negl %r12d
leaq 0x183a4(%rip), %r13     # 0x23d12
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x177db(%rip), %xmm0    # 0x23158
leal (%r14,%r12), %eax
imull %r9d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r15)
cmpb $0x65, %al
jb 0xb9c9
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rax
movsbl (%rax,%r15), %r9d
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3210
leal 0x1(%r15), %eax
movq %r15, %rcx
incq %rcx
cltd
movq 0x18(%rsp), %r9
idivl %r9d
movslq %edx, %rax
subl (%rbx,%rax,4), %ebp
movq 0x8(%rsp), %rax
movslq 0x8(%rax), %r14
decl %r12d
movq %rcx, %r15
cmpq %r14, %rcx
jl 0xb96e
movq %rbx, %rdi
callq 0x3070
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq