// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x11bd
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xe5a(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1040
movl $0x0, -0x4(%rbp)
jmp 0x138d
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xecd(%rip), %rsi       # 0x20a2
callq 0x1060
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1210
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xea7(%rip), %rdi       # 0x20a4
movb $0x0, %al
callq 0x1040
movl $0x1, -0x4(%rbp)
jmp 0x138d
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xeac(%rip), %rsi       # 0x20d4
callq 0x1060
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1263
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq 0xe86(%rip), %rdi       # 0x20d6
movb $0x0, %al
callq 0x1040
movl $0x1, -0x4(%rbp)
jmp 0x138d
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movslq -0x24(%rbp), %rdi
shlq $0x0, %rdi
callq 0x1050
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1304
movq -0x18(%rbp), %rdi
leaq 0xe53(%rip), %rsi       # 0x2101
leaq -0x29(%rbp), %rdx
movb $0x0, %al
callq 0x1030
movl %eax, -0x40(%rbp)
movb -0x29(%rbp), %dl
movq -0x38(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb %dl, (%rax,%rcx)
movsbl -0x29(%rbp), %eax
cmpl $0x47, %eax
je 0x12ee
movsbl -0x29(%rbp), %eax
cmpl $0x67, %eax
je 0x12ee
movsbl -0x29(%rbp), %eax
cmpl $0x43, %eax
je 0x12ee
movsbl -0x29(%rbp), %eax
cmpl $0x63, %eax
jne 0x12f7
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x12f9
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x129b
cvtsi2ssl -0x3c(%rbp), %xmm0
cvtsi2ssl -0x24(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0xde7(%rip), %rdi       # 0x2104
movb $0x1, %al
callq 0x1040
cmpl $0x0, -0x40(%rbp)
jle 0x138d
movq -0x18(%rbp), %rdi
leaq 0xdcc(%rip), %rsi       # 0x2101
leaq -0x29(%rbp), %rdx
movb $0x0, %al
callq 0x1030
movl %eax, -0x40(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x0, %eax
je 0x1355
movsbl -0x29(%rbp), %eax
cmpl $0xa, %eax
jne 0x135e
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
movsbl -0x29(%rbp), %eax
cmpl $0x47, %eax
je 0x1382
movsbl -0x29(%rbp), %eax
cmpl $0x67, %eax
je 0x1382
movsbl -0x29(%rbp), %eax
cmpl $0x43, %eax
je 0x1382
movsbl -0x29(%rbp), %eax
cmpl $0x63, %eax
jne 0x138b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1324
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq