// File: /workspace/github_c_makefile_star2_O0/gmcvicker[P]check_fastq/check_fastq.c
// Function: main
int main(int argc, char **argv) {
  ReadSeq read;
  gzFile gzf, out_gzf;
  long rec_num, line_num, n_err;
  char min_qual, max_qual;

  if(argc == 3) {
    if(util_file_exists(argv[2])) {
      fprintf(stderr, "output file '%s' already exists\n", argv[2]);
      fprintf(stderr, "usage: %s <fastq_file.txt.gz> "
	      "[<repaired_output_file.txt.gz>]\n", argv[0]);
      exit(2);
    }
	
    out_gzf = util_must_gzopen(argv[2], "wb");
    fprintf(stderr, "writing repaired fastq to '%s'\n", argv[2]);
  } else {
    if(argc != 2) {
      fprintf(stderr, "usage: %s <fastq_file.txt.gz> "
	      "[<repaired_output_file.txt.gz>]\n", argv[0]);
      exit(2);
    }
    out_gzf = NULL;
  }

  gzf = util_must_gzopen(argv[1], "rb");

  rec_num = 0;
  line_num = 1;
  n_err = 0;
  min_qual = max_qual = -1;

  while(TRUE) {
    long r = 0;

    r = parse_fastq_read(&read, gzf);

    if(r == FASTQ_END) {
      /* we have reached the end of the file */
      break;
    }

    if(r == FASTQ_ERR) {
      if(warn_count < MAX_WARN) {
	warn_count += 1;
	my_warn("%s:%d: invalid fastq record starting on line %ld:\n", 
		__FILE__, __LINE__, line_num);
	fprintf(stderr, "  %s\n  %s\n  %s\n  %s\n", read.line1, 
		read.line2, read.line3, read.line4);
      }
      n_err += 1;
    }

    if(r == FASTQ_OK) {
      /* record max and min quality values observed */
      if((min_qual == -1) || (min_qual > read.min_qual)) {
	min_qual = read.min_qual;
      }
      if((max_qual == -1) || (max_qual < read.max_qual)) {
	max_qual = read.max_qual;
      }      

      if(out_gzf) {
	int n_written;
	/* write record to file */
	n_written = gzprintf(out_gzf, "%s\n%s\n%s\n%s\n", read.line1,
			     read.line2, read.line3, read.line4);
	if(n_written == 0) {
	  my_err("%s:%d: failed to write to output file", __FILE__, __LINE__);
	}
      }
    }
	
    rec_num += 1;
    line_num += 4;

    if((rec_num % 1000000) == 0) {
      fprintf(stderr, ".");
    }
  }

  report_qual_type(min_qual, max_qual);

  fprintf(stderr, "\n");
  fprintf(stderr, "fastq records: %ld, errors: %ld\n", rec_num, n_err);

  gzclose(gzf);
  if(out_gzf) {
    gzclose(out_gzf);
  }

  if((n_err > 0) && !out_gzf) {
    /* return error if there were errors found and we are not writing 
     * a repaired version of the file 
     */
    exit(2);
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1480, %rsp           # imm = 0x1480
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jne 0x146b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x29d0
cmpl $0x0, %eax
je 0x142e
movq 0x6c0c(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x3c06(%rip), %rsi      # 0x5004
movb $0x0, %al
callq 0x1180
movq 0x6bec(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x3c08(%rip), %rsi      # 0x5025
movb $0x0, %al
callq 0x1180
movl $0x2, %edi
callq 0x1260
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x3c27(%rip), %rsi      # 0x5064
callq 0x39d0
movq %rax, -0x1448(%rbp)
movq 0x6ba8(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x3c05(%rip), %rsi      # 0x5067
movb $0x0, %al
callq 0x1180
jmp 0x14a5
cmpl $0x2, -0x8(%rbp)
je 0x149a
movq 0x6b80(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x3b9c(%rip), %rsi      # 0x5025
movb $0x0, %al
callq 0x1180
movl $0x2, %edi
callq 0x1260
movq $0x0, -0x1448(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x3bd3(%rip), %rsi      # 0x5087
callq 0x39d0
movq %rax, -0x1440(%rbp)
movq $0x0, -0x1450(%rbp)
movq $0x1, -0x1458(%rbp)
movq $0x0, -0x1460(%rbp)
movb $-0x1, -0x1462(%rbp)
movb $-0x1, -0x1461(%rbp)
movq $0x0, -0x1470(%rbp)
movq -0x1440(%rbp), %rsi
leaq -0x1434(%rbp), %rdi
callq 0x17c0
cltq
movq %rax, -0x1470(%rbp)
cmpq $-0x1, -0x1470(%rbp)
jne 0x1525
jmp 0x1713
cmpq $0x1, -0x1470(%rbp)
jne 0x15d5
cmpl $0x3e8, 0x6c37(%rip)    # imm = 0x3E8
jge 0x15c3
movl 0x6c2b(%rip), %eax      # 0x8174
addl $0x1, %eax
movl %eax, 0x6c22(%rip)      # 0x8174
movq -0x1458(%rbp), %rcx
leaq 0x3b2a(%rip), %rdi      # 0x508a
leaq 0x3b56(%rip), %rsi      # 0x50bd
movl $0x1d0, %edx            # imm = 0x1D0
movb $0x0, %al
callq 0x3e60
movq 0x6a7e(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq -0x1434(%rbp), %rdx
addq $0x41e, %rdx            # imm = 0x41E
leaq -0x1434(%rbp), %rcx
addq $0x81e, %rcx            # imm = 0x81E
leaq -0x1434(%rbp), %r8
addq $0xc1e, %r8             # imm = 0xC1E
leaq -0x1434(%rbp), %r9
addq $0x101e, %r9            # imm = 0x101E
leaq 0x3b0f(%rip), %rsi      # 0x50cb
movb $0x0, %al
callq 0x1180
movq -0x1460(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1460(%rbp)
cmpq $0x0, -0x1470(%rbp)
jne 0x16bb
movsbl -0x1461(%rbp), %eax
cmpl $-0x1, %eax
je 0x1601
movsbl -0x1461(%rbp), %eax
movsbl -0x1018(%rbp), %ecx
cmpl %ecx, %eax
jle 0x160d
movb -0x1018(%rbp), %al
movb %al, -0x1461(%rbp)
movsbl -0x1462(%rbp), %eax
cmpl $-0x1, %eax
je 0x162b
movsbl -0x1462(%rbp), %eax
movsbl -0x1017(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1637
movb -0x1017(%rbp), %al
movb %al, -0x1462(%rbp)
cmpq $0x0, -0x1448(%rbp)
je 0x16b9
movq -0x1448(%rbp), %rdi
leaq -0x1434(%rbp), %rdx
addq $0x41e, %rdx            # imm = 0x41E
leaq -0x1434(%rbp), %rcx
addq $0x81e, %rcx            # imm = 0x81E
leaq -0x1434(%rbp), %r8
addq $0xc1e, %r8             # imm = 0xC1E
leaq -0x1434(%rbp), %r9
addq $0x101e, %r9            # imm = 0x101E
leaq 0x3a59(%rip), %rsi      # 0x50e0
movb $0x0, %al
callq 0x1110
movl %eax, -0x1474(%rbp)
cmpl $0x0, -0x1474(%rbp)
jne 0x16b7
leaq 0x3a49(%rip), %rdi      # 0x50ed
leaq 0x3a12(%rip), %rsi      # 0x50bd
movl $0x1e6, %edx            # imm = 0x1E6
movb $0x0, %al
callq 0x3d60
jmp 0x16b9
jmp 0x16bb
movq -0x1450(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1450(%rbp)
movq -0x1458(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1458(%rbp)
movq -0x1450(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x170e
movq 0x68fb(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x3dbd(%rip), %rsi      # 0x54c4
movb $0x0, %al
callq 0x1180
jmp 0x14ef
movb -0x1461(%rbp), %al
movsbl %al, %edi
movsbl -0x1462(%rbp), %esi
callq 0x1990
movq 0x68c9(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
leaq 0x3b71(%rip), %rsi      # 0x52aa
movb $0x0, %al
callq 0x1180
movq 0x68b1(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x1450(%rbp), %rdx
movq -0x1460(%rbp), %rcx
leaq 0x39b4(%rip), %rsi      # 0x5113
movb $0x0, %al
callq 0x1180
movq -0x1440(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x1448(%rbp)
je 0x1788
movq -0x1448(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x1460(%rbp)
jle 0x17a6
cmpq $0x0, -0x1448(%rbp)
jne 0x17a6
movl $0x2, %edi
callq 0x1260
xorl %eax, %eax
addq $0x1480, %rsp           # imm = 0x1480
popq %rbp
retq
nopw %cs:(%rax,%rax)