// File: /workspace/github_c_makefile_star2_O2/gmcvicker[P]check_fastq/split_fastq.c
// Function: main
int main(int argc, char **argv) {
  ReadSeq read;
  gzFile gzf, out_gzf;
  long rec_num, line_num, n_err;
  int file_num = 0;
  char min_qual, max_qual;
  char *input_filename, *output_dir, *prefix;
  char output_filename[MAX_LINE];
  int n_written;
  
  if(argc != 3) {
    fprintf(stderr, "usage: %s <fastq_file.txt.gz> <output_dir>\n", argv[0]);
    exit(2);
  }

  input_filename = argv[1];
  output_dir = argv[2];

  gzf = util_must_gzopen(input_filename, "rb");

  prefix = get_prefix(output_dir, input_filename);

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

  out_gzf = NULL;

  rec_num = 0;

  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) {
      my_warn("%s:%d: invalid fastq record starting on line %ld:\n", 
	      __FILE__, __LINE__, line_num);
      n_err += 1;
      fprintf(stderr, "  %s\n  %s\n  %s\n  %s\n", read.line1, 
	      read.line2, read.line3, read.line4);
    }
    
    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 == NULL || rec_num > READS_PER_FILE) {
	if(out_gzf) {
	  /* close old output file */
	  fprintf(stderr, "\n");
	  gzclose(out_gzf);
	}
	
	file_num += 1;
	
	n_written = snprintf(output_filename, MAX_LINE, "%s.%d.txt.gz", 
			     prefix, file_num);

	if(n_written > MAX_LINE) {
	  my_err("%s:%d: filename too long\n", __FILE__, __LINE__);
	}

	fprintf(stderr, "writing to file '%s'\n",  output_filename);
	out_gzf = util_must_gzopen(output_filename, "wb");

	rec_num = 0;
      }
      
      /* 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 % 100000) == 0) {
        fprintf(stderr, ".");
    }
  }

  report_qual_type(min_qual, max_qual);

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

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

  my_free(prefix);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1868, %rsp           # imm = 0x1868
cmpl $0x3, %edi
jne 0x1d1d
movq 0x8(%rsi), %r14
movq 0x10(%rsi), %r15
leaq 0x2c58(%rip), %rsi      # 0x4030
movq %r14, %rdi
callq 0x2ba4
movq %rax, %rbx
movq %r14, %rdi
callq 0x1110
movl %eax, %edx
movl %eax, %ecx
sarl $0x1f, %ecx
andl %eax, %ecx
incl %eax
testl %edx, %edx
jle 0x140a
decl %eax
cmpb $0x2f, -0x1(%r14,%rdx)
leaq -0x1(%rdx), %rdx
jne 0x13f6
jmp 0x140c
movl %ecx, %eax
cltq
addq %rax, %r14
movq 0x5be0(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2d02(%rip), %rsi      # 0x4124
movq %r14, %rdx
xorl %eax, %eax
callq 0x1170
leaq 0x2d06(%rip), %rsi      # 0x4139
movq %r15, %rdi
callq 0x29dd
testl %eax, %eax
jne 0x1457
leaq 0x2cf3(%rip), %rsi      # 0x4139
movq %r15, %rdi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x232a
jmp 0x1466
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x232a
movq %rax, %r12
movq %rax, %rdi
callq 0x1110
movq %rax, %r14
leaq 0x2c13(%rip), %rsi      # 0x408e
movq %r12, %rdi
callq 0x29dd
testl %eax, %eax
jne 0x14b9
leaq 0x2c04(%rip), %rsi      # 0x4092
movq %r12, %rdi
callq 0x29dd
testl %eax, %eax
jne 0x14c5
leaq 0x2c9a(%rip), %rsi      # 0x413b
movq %r12, %rdi
callq 0x29dd
testl %eax, %eax
je 0x14df
movabsq $-0x400000000, %rax     # imm = 0xFFFFFFFC00000000
jmp 0x14cf
movabsq $-0x700000000, %rax     # imm = 0xFFFFFFF900000000
jmp 0x14cf
movabsq $-0x300000000, %rax     # imm = 0xFFFFFFFD00000000
shlq $0x20, %r14
addq %rax, %r14
sarq $0x20, %r14
movb $0x0, (%r12,%r14)
movq 0x5b12(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2c50(%rip), %rsi      # 0x4140
movq %r12, -0x48(%rbp)
movq %r12, %rdx
xorl %eax, %eax
callq 0x1170
leaq -0xc66(%rbp), %r13
leaq -0x866(%rbp), %r12
movb $-0x1, %al
movl %eax, -0x30(%rbp)
pushq $0x1
popq %rax
movq %rax, -0x60(%rbp)
leaq -0x1484(%rbp), %r14
movq $0x0, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x3c(%rbp)
movb $-0x1, %al
movl %eax, -0x2c(%rbp)
movq $0x0, -0x58(%rbp)
andl $0x0, -0x64(%rbp)
movq %rbx, %rdi
leaq -0x1066(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10c0
testq %rax, %rax
je 0x1b7a
cmpb $0x40, -0x1066(%rbp)
jne 0x1863
movq %r12, %r15
movq %r14, %rdi
movq %r13, %r12
leaq -0x1066(%rbp), %r13
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1d40
movq %r13, %rdi
movq %r12, %r13
callq 0x2974
movq %rbx, %rdi
movq %r12, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10c0
testq %rax, %rax
je 0x18b2
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1d40
movq %r13, %rdi
callq 0x2974
movq %rbx, %rdi
movq %r15, %r12
movq %r15, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10c0
testq %rax, %rax
je 0x18ec
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x1d40
movq %r12, %rdi
callq 0x2974
movq %rbx, %rdi
leaq -0x466(%rbp), %r15
movq %r15, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x10c0
testq %rax, %rax
je 0x1927
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1d40
movq %r15, %rdi
callq 0x2974
movl -0x64(%rbp), %eax
testl %eax, %eax
jne 0x17ac
cmpb $0x2b, -0x866(%rbp)
jne 0x1aa8
movq %r13, %rdi
callq 0x1110
movq %rax, %r14
movl %r14d, -0x106c(%rbp)
movq %r15, %rdi
callq 0x1110
testl %r14d, %r14d
jle 0x178f
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %rax, %rcx
jne 0x1ac4
xorl %edx, %edx
leaq 0x2cd5(%rip), %rdi      # 0x4359
cmpq %rax, %rdx
je 0x1b73
movsbl -0xc66(%rbp,%rdx), %ecx
xorl %esi, %esi
cmpb (%rsi,%rdi), %cl
je 0x16a7
incq %rsi
cmpq $0x17, %rsi
jne 0x1697
jmp 0x16ac
incq %rdx
jmp 0x1684
leaq 0x2cbd(%rip), %rdi      # 0x4370
leaq 0x29ac(%rip), %rsi      # 0x4066
movl $0xf8, %edx
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
movl -0x106c(%rbp), %r14d
pushq $0x1
popq %rax
orw $-0x1, -0x1068(%rbp)
testl %r14d, %r14d
movl $0x0, %ecx
cmovlel %ecx, %r14d
movb $-0x1, %cl
movb $-0x1, %dl
xorl %esi, %esi
cmpq %rsi, %r14
je 0x172f
movb -0x466(%rbp,%rsi), %dil
cmpb $-0x1, %dl
je 0x1718
cmpb %dl, %dil
jge 0x1711
movb %dil, -0x1068(%rbp)
movl %edi, %edx
cmpb %cl, %dil
jg 0x1721
jmp 0x172a
movb %dil, -0x1068(%rbp)
movl %edi, %edx
movb %dil, -0x1067(%rbp)
movl %edi, %ecx
incq %rsi
jmp 0x16f1
cmpb $0x20, %dl
jg 0x1761
movsbl %dl, %ecx
leaq 0x2c59(%rip), %rdi      # 0x4397
leaq 0x2921(%rip), %rsi      # 0x4066
movl $0x126, %edx            # imm = 0x126
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
movb -0x1067(%rbp), %cl
pushq $0x1
popq %rax
cmpb $0x7f, %cl
leaq -0x466(%rbp), %r15
jne 0x17ac
leaq 0x2c23(%rip), %rdi      # 0x4397
leaq 0x28eb(%rip), %rsi      # 0x4066
movl $0x12b, %edx            # imm = 0x12B
pushq $0x7f
popq %rcx
xorl %eax, %eax
callq 0x2efd
jmp 0x1ae4
leaq 0x29e0(%rip), %rdi      # 0x4176
leaq 0x28c9(%rip), %rsi      # 0x4066
movl $0x155, %edx            # imm = 0x155
xorl %eax, %eax
callq 0x2efd
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x17c7
cmpl $0x1, %eax
je 0x1aeb
cmpl $-0x1, %eax
jne 0x1b35
jmp 0x1b98
movl -0x1068(%rbp), %eax
movzbl -0x30(%rbp), %ecx
cmpb %al, %cl
movl %ecx, %edx
cmovgel %eax, %edx
cmpb $-0x1, %cl
cmovel %eax, %edx
movl %edx, -0x30(%rbp)
movzbl -0x1067(%rbp), %eax
movzbl -0x2c(%rbp), %ecx
cmpb %al, %cl
movl %ecx, %edx
cmovlel %eax, %edx
cmpb $-0x1, %cl
cmovel %eax, %edx
movl %edx, -0x2c(%rbp)
cmpq $0x4c4b40, -0x38(%rbp)  # imm = 0x4C4B40
movq -0x58(%rbp), %rdi
jg 0x19fb
testq %rdi, %rdi
je 0x19fb
movq %rdi, -0x58(%rbp)
leaq 0x28a7(%rip), %rsi      # 0x40c9
leaq -0x1066(%rbp), %rdx
movq %r13, %rcx
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x1100
testl %eax, %eax
jne 0x1857
leaq 0x2892(%rip), %rdi      # 0x40d6
leaq 0x281b(%rip), %rsi      # 0x4066
movl $0x211, %edx            # imm = 0x211
xorl %eax, %eax
callq 0x2e2c
movq -0x38(%rbp), %rax
incq %rax
jmp 0x1b39
leaq 0x2963(%rip), %rdi      # 0x41cd
leaq 0x27f5(%rip), %rsi      # 0x4066
movl $0x8d, %edx
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
xorl %eax, %eax
movb %al, -0xc66(%rbp)
movb %al, -0x866(%rbp)
movb %al, -0x466(%rbp)
movl (%rbx), %eax
testl %eax, %eax
jne 0x1954
movq %rbx, %rdi
callq 0x10f0
movl %eax, %r15d
jmp 0x196b
leaq 0x2945(%rip), %rdi      # 0x41fe
leaq 0x27a6(%rip), %rsi      # 0x4066
movl $0x9e, %edx
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
xorl %eax, %eax
movb %al, -0xc66(%rbp)
movb %al, -0x866(%rbp)
movb %al, -0x466(%rbp)
movq %r15, %r12
jmp 0x191b
leaq 0x290b(%rip), %rdi      # 0x41fe
leaq 0x276c(%rip), %rsi      # 0x4066
movl $0xac, %edx
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
xorl %eax, %eax
movb %al, -0x866(%rbp)
movb %al, -0x466(%rbp)
leaq -0x466(%rbp), %r15
jmp 0x1aeb
leaq 0x28d0(%rip), %rdi      # 0x41fe
leaq 0x2731(%rip), %rsi      # 0x4066
movl $0xb8, %edx
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
movb $0x0, -0x466(%rbp)
jmp 0x1aeb
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movb (%rax), %r15b
movb $0xa, %cl
xorl %r14d, %r14d
cmpb $-0x1, %r15b
je 0x19b3
xorb $0xa, %cl
movl %r15d, %eax
xorb $0x40, %al
orb %cl, %al
je 0x19c6
movl (%rbx), %eax
testl %eax, %eax
je 0x19a0
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movb (%rax), %al
jmp 0x19a8
movq %rbx, %rdi
callq 0x10f0
incq %r14
movl %r15d, %ecx
movl %eax, %r15d
jmp 0x1970
movq 0x563e(%rip), %r15      # 0x6ff8
movq (%r15), %rdi
leaq 0x2890(%rip), %rsi      # 0x4254
jmp 0x19e5
movq %rbx, %rdi
pushq $-0x1
popq %rsi
pushq $0x1
popq %rdx
callq 0x1120
movq 0x561d(%rip), %r15      # 0x6ff8
movq (%r15), %rdi
leaq 0x283d(%rip), %rsi      # 0x4222
movq %r14, %rdx
xorl %eax, %eax
callq 0x1170
leaq -0x466(%rbp), %r15
jmp 0x162e
testq %rdi, %rdi
je 0x1a1d
movq %rdi, %r14
movq 0x55ee(%rip), %rax      # 0x6ff8
movq (%rax), %rsi
pushq $0xa
popq %rdi
callq 0x1150
movq %r14, %rdi
callq 0x1040
movl -0x3c(%rbp), %r8d
incl %r8d
movl $0x400, %esi            # imm = 0x400
leaq -0x1890(%rbp), %rdi
leaq 0x2652(%rip), %rdx      # 0x4089
movq -0x48(%rbp), %rcx
movl %r8d, -0x3c(%rbp)
xorl %eax, %eax
callq 0x1130
cmpl $0x401, %eax            # imm = 0x401
jl 0x1a67
leaq 0x2642(%rip), %rdi      # 0x4096
leaq 0x260b(%rip), %rsi      # 0x4066
movl $0x204, %edx            # imm = 0x204
xorl %eax, %eax
callq 0x2e2c
movq 0x558a(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2638(%rip), %rsi      # 0x40b0
leaq -0x1890(%rbp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x1170
movq %r14, %rdi
leaq 0x2633(%rip), %rsi      # 0x40c6
callq 0x2ba4
movq %rax, %rdi
movq $0x0, -0x38(%rbp)
jmp 0x1817
leaq 0x269d(%rip), %rdi      # 0x414c
leaq 0x25b0(%rip), %rsi      # 0x4066
movl $0x14b, %edx            # imm = 0x14B
xorl %eax, %eax
callq 0x2efd
jmp 0x1ae4
leaq 0x26c5(%rip), %rdi      # 0x4190
leaq 0x2594(%rip), %rsi      # 0x4066
movl $0x15c, %edx            # imm = 0x15C
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x2efd
movl $0x1, -0x64(%rbp)
leaq 0x2541(%rip), %rdi      # 0x4033
leaq 0x256d(%rip), %rsi      # 0x4066
movl $0x1e8, %edx            # imm = 0x1E8
movq -0x60(%rbp), %rcx
xorl %eax, %eax
callq 0x2efd
incq -0x50(%rbp)
movq 0x54e4(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2556(%rip), %rsi      # 0x4074
leaq -0x1066(%rbp), %rdx
movq %r13, %rcx
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x1170
movq -0x38(%rbp), %rax
leaq -0x1484(%rbp), %r14
addq $0x4, -0x60(%rbp)
movq %rax, -0x38(%rbp)
cqto
movl $0x186a0, %ecx          # imm = 0x186A0
idivq %rcx
testq %rdx, %rdx
jne 0x1543
movq 0x5495(%rip), %rax      # 0x6ff8
movq (%rax), %rsi
pushq $0x2e
popq %rdi
callq 0x1150
jmp 0x1543
xorl %eax, %eax
jmp 0x16d7
orl $-0x1, -0x64(%rbp)
xorl %eax, %eax
movb %al, -0x1066(%rbp)
movb %al, -0xc66(%rbp)
movb %al, -0x866(%rbp)
movb %al, -0x466(%rbp)
movq 0x5459(%rip), %r14      # 0x6ff8
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x1150
movq (%r14), %rcx
leaq 0x281c(%rip), %rdi      # 0x43d0
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x1260
movl -0x30(%rbp), %eax
movsbl %al, %r14d
movsbl -0x2c(%rbp), %r15d
cmpb $-0x1, %al
je 0x1bd5
cmpb $-0x1, -0x2c(%rbp)
jne 0x1bf1
movq 0x541c(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x2804(%rip), %rdi      # 0x43ea
pushq $0x35
popq %rsi
pushq $0x1
popq %rdx
callq 0x1260
movq 0x5400(%rip), %r12      # 0x6ff8
movq (%r12), %rdi
leaq 0x281d(%rip), %rsi      # 0x4420
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1170
movl -0x30(%rbp), %eax
cmpb $0x3a, %al
jg 0x1c5a
movq (%r12), %rcx
leaq 0x281a(%rip), %rdi      # 0x443c
pushq $0x42
popq %rsi
pushq $0x1
popq %rdx
callq 0x1260
cmpb $0x68, -0x2c(%rbp)
movq %r12, %r14
movq -0x48(%rbp), %r15
movq -0x50(%rbp), %r12
jl 0x1cbc
leaq 0x283a(%rip), %rdi      # 0x447f
leaq 0x241a(%rip), %rsi      # 0x4066
movl $0x178, %edx            # imm = 0x178
xorl %eax, %eax
callq 0x2efd
jmp 0x1cbc
cmpb $0x3f, %al
ja 0x1c89
leaq 0x2879(%rip), %rdi      # 0x44de
leaq 0x23fa(%rip), %rsi      # 0x4066
movl $0x17d, %edx            # imm = 0x17D
xorl %eax, %eax
callq 0x2efd
movq 0x5379(%rip), %r14      # 0x6ff8
movq -0x48(%rbp), %r15
movq -0x50(%rbp), %r12
jmp 0x1cbc
movq 0x5368(%rip), %r14      # 0x6ff8
movq (%r14), %rcx
cmpb $0x41, %al
movq -0x48(%rbp), %r15
movq -0x50(%rbp), %r12
ja 0x1ca8
leaq 0x2896(%rip), %rdi      # 0x453c
jmp 0x1caf
leaq 0x2919(%rip), %rdi      # 0x45c8
pushq $0x1
popq %rdx
movl $0x8b, %esi
callq 0x1260
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x1150
movq (%r14), %rdi
leaq 0x242b(%rip), %rsi      # 0x40fc
movq -0x38(%rbp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x1170
movq %rbx, %rdi
callq 0x1040
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x1cf5
callq 0x1040
leaq 0x236a(%rip), %rsi      # 0x4066
movq %r15, %rdi
movl $0x228, %edx            # imm = 0x228
callq 0x3029
xorl %eax, %eax
addq $0x1868, %rsp           # imm = 0x1868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x52d4(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0x22d3(%rip), %rsi      # 0x4004
xorl %eax, %eax
callq 0x1170
pushq $0x2
popq %rdi
callq 0x1250