// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movq %rdi, %r15
movslq %esi, %r12
leaq (,%r12,4), %rdi
callq 0x3420
movq %rax, (%rsp)
movl 0x8(%r15), %r13d
movslq %r13d, %r14
movq %r14, %rdi
callq 0x3420
movq %rax, 0x10(%rsp)
movq %r12, 0x30(%rsp)
leal (%r12,%r12), %eax
movq %r15, 0x8(%rsp)
movq 0x10(%r15), %r12
cmpl %eax, %r14d
jge 0xb95f
testl %r13d, %r13d
jle 0xbc7c
xorl %ecx, %ecx
movabsq $0x1000000011, %rdx     # imm = 0x1000000011
xorl %eax, %eax
movzbl (%r12,%rcx), %esi
leal -0x43(%rsi), %r8d
cmpl $0x24, %r8d
ja 0xb912
movl $0x1, %edi
btq %r8, %rdx
jb 0xb91c
xorl %edi, %edi
cmpb $0x63, %sil
sete %dil
addl %edi, %eax
incq %rcx
cmpq %rcx, %r13
jne 0xb8f8
testl %r13d, %r13d
jle 0xbc7c
cvtsi2sd %eax, %xmm0
mulsd 0x17885(%rip), %xmm0    # 0x231c0
cvtsi2sd %r13d, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %esi
movq 0x10(%rsp), %rdi
movq %r13, %rdx
callq 0x3260
jmp 0xbc7c
testl %ebx, %ebx
movq %rbx, %r8
movq %rbx, 0x18(%rsp)
jle 0xbabb
movl %r8d, %r15d
xorl %eax, %eax
movabsq $0x1000000011, %rcx     # imm = 0x1000000011
xorl %ebp, %ebp
movzbl (%r12,%rax), %edx
leal -0x43(%rdx), %edi
cmpl $0x24, %edi
ja 0xb998
movl $0x1, %esi
btq %rdi, %rcx
jb 0xb9a1
xorl %esi, %esi
cmpb $0x63, %dl
sete %sil
addl %esi, %ebp
incq %rax
cmpq %rax, %r15
jne 0xb980
movq (%rsp), %rax
movl %ebp, (%rax)
leal -0x1(%r8), %ecx
cmpl $0x1, %r8d
je 0xbacb
movl %ecx, 0x2c(%rsp)
movl %ecx, %eax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movl %ebp, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x177df(%rip), %xmm0    # 0x231c0
leal (%r15,%rbx), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r13)
cmpb $0x64, %al
jbe 0xba30
movq 0x8(%rsp), %rbp
movq (%rbp), %rdx
movl 0x8(%rbp), %r8d
movsbl (%r12,%r13), %r9d
leaq 0x18383(%rip), %rdi     # 0x23da2
movl %r14d, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x3210
movq 0x10(%rbp), %r12
movq 0x18(%rsp), %r8
movl %r13d, %eax
xorl %edx, %edx
divl %r8d
movq (%rsp), %rax
movl (%rax,%rdx,4), %ebp
movl %ebp, 0x4(%rax,%r13,4)
movb (%r12,%r13), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0xba6e
movzbl %al, %eax
movl $0x303, %ecx            # imm = 0x303
btl %eax, %ecx
jae 0xba6e
decl %ebp
movq (%rsp), %rax
movl %ebp, 0x4(%rax,%r13,4)
leaq (%r12,%r15), %rax
movb (%r13,%rax), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0xba98
movzbl %al, %eax
movl $0x303, %ecx            # imm = 0x303
btl %eax, %ecx
jae 0xba98
incl %ebp
movq (%rsp), %rax
movl %ebp, 0x4(%rax,%r13,4)
incq %r13
addl %r14d, %ebp
addq %r15, %rbx
cmpq %r13, 0x20(%rsp)
jne 0xb9cf
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r13d
movl 0x2c(%rsp), %ecx
jmp 0xbacb
movq (%rsp), %rax
movl $0x0, (%rax)
leal -0x1(%r8), %ecx
xorl %ebp, %ebp
movl %r13d, %ebx
subl %r8d, %ebx
cmpl %r8d, %ebx
jl 0xbbda
movl %r8d, %eax
imull %r8d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
movslq %ecx, %r14
movl $0x303, %r15d           # imm = 0x303
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x176ba(%rip), %xmm0    # 0x231c0
divsd 0x20(%rsp), %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r14)
cmpb $0x65, %al
jb 0xbb49
movq 0x8(%rsp), %rbx
movq (%rbx), %rdx
movsbl (%r12,%r14), %r9d
leaq 0x1826c(%rip), %rdi     # 0x23da2
movl %ebp, %esi
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3210
movq 0x10(%rbx), %r12
leal 0x1(%r14), %eax
cltd
movq 0x18(%rsp), %r8
idivl %r8d
movslq %edx, %rcx
movq (%rsp), %rsi
subl (%rsi,%rcx,4), %ebp
movl %r14d, %eax
cltd
idivl %r8d
movslq %edx, %rax
movl (%rsi,%rax,4), %eax
movl %eax, (%rsi,%rcx,4)
movb (%r12,%r14), %dl
addb $-0x43, %dl
rolb $0x6, %dl
cmpb $0x9, %dl
ja 0xbb91
movzbl %dl, %edx
btl %edx, %r15d
jae 0xbb91
decl %eax
movq (%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
movq 0x30(%rsp), %rdx
addq %r12, %rdx
movb (%r14,%rdx), %dl
addb $-0x43, %dl
rolb $0x6, %dl
cmpb $0x9, %dl
ja 0xbbba
movzbl %dl, %edx
btl %edx, %r15d
jae 0xbbba
incl %eax
movq (%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
addl %eax, %ebp
incq %r14
movq 0x8(%rsp), %rax
movl 0x8(%rax), %r13d
movl %r13d, %ebx
subl %r8d, %ebx
movslq %ebx, %rax
cmpq %rax, %r14
jl 0xbaf7
cmpl %r13d, %ebx
jge 0xbc7c
movslq %ebx, %r14
negl %ebx
leaq 0x181b3(%rip), %r12     # 0x23da2
movq 0x8(%rsp), %r15
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
mulsd 0x175bd(%rip), %xmm0    # 0x231c0
leal (%rbx,%r13), %eax
imull %r8d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x3580
cvttsd2si %xmm0, %eax
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r14)
cmpb $0x65, %al
jb 0xbc4e
movq (%r15), %rdx
movq 0x10(%r15), %rax
movsbl (%rax,%r14), %r9d
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3210
movl 0x8(%r15), %r13d
leal 0x1(%r14), %eax
movq %r14, %rcx
incq %rcx
cltd
movq 0x18(%rsp), %r8
idivl %r8d
movslq %edx, %rax
movq (%rsp), %rdx
subl (%rdx,%rax,4), %ebp
movslq %r13d, %rax
decl %ebx
movq %rcx, %r14
cmpq %rax, %rcx
jl 0xbbf4
movq (%rsp), %rdi
callq 0x3070
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq