// File: /workspace/github_c_makefile_star2_O2/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
movq %rdi, %rbx
movq %rsi, %rbp
movslq %esi, %r12
leaq (,%r12,4), %rdi
callq 0x3420
movq %rax, (%rsp)
movl 0x8(%rbx), %r14d
movslq %r14d, %r15
movq %r15, %rdi
callq 0x3420
movq %rax, 0x8(%rsp)
movq %r12, 0x28(%rsp)
leal (%r12,%r12), %eax
movq %rbx, 0x10(%rsp)
movq 0x10(%rbx), %r13
cmpl %eax, %r15d
jge 0x969b
movq %r13, %rdi
movl %r14d, %esi
callq 0x91b5
cvtsi2sd %eax, %xmm0
mulsd 0x15b6a(%rip), %xmm0    # 0x1f1d0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
cmpq %rcx, %r14
je 0x993a
movb %al, (%rdx,%rcx)
incq %rcx
jmp 0x968a
movq %r13, %rdi
movq %rbp, %rbx
movl %ebp, %esi
callq 0x91b5
movq (%rsp), %rdi
movl %eax, %ebp
movl %eax, (%rdi)
leal -0x1(%rbx), %eax
movq %rbx, %r8
testl %eax, %eax
movl $0x0, %ebx
movl %eax, 0x24(%rsp)
cmovgl %eax, %ebx
movl $0x303, %r12d           # imm = 0x303
movl %r8d, %r14d
xorl %r15d, %r15d
movq %r8, 0x18(%rsp)
cmpq %r15, %rbx
je 0x97a5
cvtsi2sd %ebp, %xmm0
mulsd 0x15ae6(%rip), %xmm0    # 0x1f1d0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x8(%rsp), %rcx
movb %al, (%rcx,%r15)
cmpb $0x64, %al
jbe 0x973b
movq 0x10(%rsp), %r12
movq (%r12), %rdx
movl 0x8(%r12), %r8d
movsbl (%r13,%r15), %r9d
leaq 0x1664e(%rip), %rdi     # 0x1fd72
movl %ebp, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3210
movq 0x10(%r12), %r13
movl $0x303, %r12d           # imm = 0x303
movq (%rsp), %rdi
movl %r15d, %eax
cltd
movq 0x18(%rsp), %r8
idivl %r8d
movl (%rdi,%rdx,4), %ecx
leal 0x1(%r15), %eax
cltd
idivl %r8d
movl %ecx, (%rdi,%rdx,4)
movb (%r13,%r15), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0x9775
movzbl %al, %eax
btl %eax, %r12d
jae 0x9775
decl %ecx
movl %ecx, (%rdi,%rdx,4)
movq 0x28(%rsp), %rax
addq %r13, %rax
movb (%r15,%rax), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0x9798
movzbl %al, %eax
btl %eax, %r12d
jae 0x9798
incl %ecx
movl %ecx, (%rdi,%rdx,4)
addl %ecx, %ebp
addl %r8d, %r14d
incq %r15
jmp 0x96d5
movl %r8d, %eax
imull %r8d, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x24(%rsp), %rbx
movl %r8d, %r15d
movq 0x10(%rsp), %rax
movl 0x8(%rax), %r12d
movl %r12d, %eax
subl %r8d, %eax
movslq %eax, %r14
cmpq %r14, %rbx
jge 0x98ad
cvtsi2sd %ebp, %xmm0
mulsd 0x159eb(%rip), %xmm0    # 0x1f1d0
divsd 0x30(%rsp), %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x8(%rsp), %rcx
movb %al, (%rcx,%rbx)
cmpb $0x64, %al
jbe 0x982d
movq 0x10(%rsp), %r14
movq (%r14), %rdx
movsbl (%r13,%rbx), %r9d
leal -0x1(%r15), %ecx
leaq 0x16559(%rip), %rdi     # 0x1fd72
movl %ebp, %esi
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3210
movq 0x10(%r14), %r13
movl %ebx, %ecx
jmp 0x9831
leal -0x1(%r15), %ecx
movq (%rsp), %rdi
movl %r15d, %eax
cltd
movq 0x18(%rsp), %r8
idivl %r8d
movslq %edx, %rsi
subl (%rdi,%rsi,4), %ebp
movl %ecx, %eax
cltd
idivl %r8d
movslq %edx, %rax
movl (%rdi,%rax,4), %eax
movl %eax, (%rdi,%rsi,4)
movb (%r13,%rbx), %cl
addb $-0x43, %cl
rolb $0x6, %cl
cmpb $0x9, %cl
ja 0x9878
movzbl %cl, %ecx
movl $0x303, %edx            # imm = 0x303
btl %ecx, %edx
jae 0x9878
decl %eax
movl %eax, (%rdi,%rsi,4)
movq 0x28(%rsp), %rcx
addq %r13, %rcx
movb (%rbx,%rcx), %cl
addb $-0x43, %cl
rolb $0x6, %cl
cmpb $0x9, %cl
ja 0x98a0
movzbl %cl, %ecx
movl $0x303, %edx            # imm = 0x303
btl %ecx, %edx
jae 0x98a0
incl %eax
movl %eax, (%rdi,%rsi,4)
addl %eax, %ebp
incl %r15d
incq %rbx
jmp 0x97be
movl %r8d, %ebx
subl %r12d, %ebx
leaq 0x164b8(%rip), %r15     # 0x1fd72
movq 0x10(%rsp), %r13
movslq %r12d, %rax
cmpq %rax, %r14
jge 0x993a
cvtsi2sd %ebp, %xmm0
mulsd 0x158fd(%rip), %xmm0    # 0x1f1d0
leal (%r12,%rbx), %eax
imull %r8d, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x8(%rsp), %rcx
movb %al, (%rcx,%r14)
cmpb $0x65, %al
jb 0x991c
movq (%r13), %rdx
movq 0x10(%r13), %rax
movsbl (%rax,%r14), %r9d
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3210
movl 0x8(%r13), %r12d
leal 0x1(%r14), %eax
incq %r14
cltd
movq 0x18(%rsp), %r8
idivl %r8d
movslq %edx, %rax
movq (%rsp), %rdi
subl (%rdi,%rax,4), %ebp
decl %ebx
jmp 0x98bf
callq 0x3070
movq 0x8(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq