// File: /workspace/github_c_makefile_star2_O1/sc932[P]ALE/src/GCcompFinder.c
// Function: main
int main(int argc, char **argv){
  
  if (argc < 4) {
    printf("Usage: %s assemblyFile.fasta runningWindow output\n(C) 2011 Scott Clark\nFinds the running window GC content in a fasta file\nJust sequence! No gene name/info!\n", argv[0]);
    return 0;
  }
  
  // attempt to open the first input file
  FILE *ins = fopen(argv[argc - 3], "r");
  if(ins == NULL){
      printf("Error! Could not open the first input file: %s\n", argv[argc - 3]);
      return 1;
  }
  
  // attempt to open the output file
  FILE *fout = fopen(argv[argc - 1], "w");
  if(fout == NULL){
      printf("Error! Could not open the output file: %s\n", argv[argc - 1]);
      return 1;
  }
  
  int runningWindow = atoi(argv[argc - 2]);
  int i;
  char base;
  char *backTrace = malloc(sizeof(char)*runningWindow);
  int gcTot = 0;
  int keepGoing;
  
  for(i = 0; i < runningWindow; i++){
    keepGoing = fscanf(ins, "%c", &base);
//     if(base == '\0' || base == '\n'){
//       i--;
//     }
    backTrace[i] = base;
    if(base == 'G' || base == 'g' || base == 'C' || base == 'c'){
      gcTot++;
    }
  }
  
  printf("%f\n", (float)gcTot/((float)runningWindow));
  
  while(keepGoing > 0){
    keepGoing = fscanf(ins, "%c", &base);
    if(base == '\0' || base == '\n'){
      i--;
    }
    if(base == 'G' || base == 'g' || base == 'C' || base == 'c'){
      gcTot++;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
cmpl $0x3, %edi
jg 0x1197
movq (%r14), %rsi
leaq 0xe7b(%rip), %rdi       # 0x2004
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
jmp 0x12bd
movl %edi, %r15d
movq -0x18(%r14,%r15,8), %rdi
leaq 0xefc(%rip), %rsi       # 0x20a2
callq 0x1050
testq %rax, %rax
je 0x1273
movq %rax, %rbx
movq -0x8(%r14,%r15,8), %rdi
leaq 0xf11(%rip), %rsi       # 0x20d4
callq 0x1050
testq %rax, %rax
je 0x1281
movq -0x10(%r14,%r15,8), %rdi
callq 0x1060
testl %eax, %eax
jle 0x129b
leaq 0xf17(%rip), %r14       # 0x2101
leaq 0x3(%rsp), %r15
movl %eax, 0x4(%rsp)
movl %eax, %r13d
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1030
movl %eax, %r12d
movb 0x3(%rsp), %al
addb $-0x43, %al
rolb $0x6, %al
cmpb $0x9, %al
ja 0x1227
movzbl %al, %eax
movl $0x303, %ecx            # imm = 0x303
btl %eax, %ecx
jae 0x1227
incl %ebp
decl %r13d
jne 0x11f8
cvtsi2ss %ebp, %xmm0
cvtsi2ssl 0x4(%rsp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xebf(%rip), %rdi       # 0x2104
movb $0x1, %al
callq 0x1040
testl %r12d, %r12d
jle 0x12bb
leaq 0xea9(%rip), %r14       # 0x2101
leaq 0x3(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1030
testl %eax, %eax
jg 0x125d
jmp 0x12bb
movq -0x18(%r14,%r15,8), %rsi
leaq 0xe25(%rip), %rdi       # 0x20a4
jmp 0x128d
movq -0x8(%r14,%r15,8), %rsi
leaq 0xe49(%rip), %rdi       # 0x20d6
xorl %eax, %eax
callq 0x1040
movl $0x1, %ebx
jmp 0x12bd
cvtsi2ss %eax, %xmm0
xorps %xmm1, %xmm1
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0xe50(%rip), %rdi       # 0x2104
movb $0x1, %al
callq 0x1040
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq