// File: /workspace/github_c_makefile_star2_O3/sc932[P]ALE/src/readFileSplitter.c
// Function: main
int main(int argc, char **argv){
    static char *prog;
    char *p;
    prog = argv[0];
    if((p = strrchr(prog, '/')) != NULL)
        prog = ++p;
    if (argc < 2) { usage(prog); return 1; }
    if (strcmp(argv[1], "-h") ==  0) { usage(prog); return 0; }
    if (strcmp(argv[1], "--helph")  == 0) { usage(prog); return 0; }
    printf("Input file to split: %s\n", argv[argc - 1]);
    
    int hasQualityInfo = 1;
    
    if (argc == 3) {
        if(strcmp(argv[1], "-ro")==0){
            hasQualityInfo = 0;
        }else{
            printf("Could not find option %s\n", argv[1]);
            return 0;
        }
    }
    
    // attempt to open the input file
    FILE *ins = fopen(argv[argc - 1], "r");
    if(ins == NULL){
        printf("Error! Could not open input file: %s\n", argv[argc - 1]);
        return 1;
    }
    
    
    
    // open up output file
    FILE *fo1, *fo2;
    char fileName1[100] = "part1_", fileName2[100] = "part2_";
    strcat(fileName1, argv[argc - 1]);
    strcat(fileName2, argv[argc - 1]);
    fo1 = fopen(fileName1, "w");
    fo2 = fopen(fileName2, "w");
    if(fo1 == NULL || fo2 == NULL){
        printf("Error! Could not open output files: %s or %s\n", fileName1, fileName2);
    }
    
    // read in and output the files
    int keepGoing = 1;
    char seqName[256];
    char seq[256];
    char qual[256];
    char temp[5];
    if(hasQualityInfo == 1){
        while(keepGoing > 0){
            // first read
            keepGoing = fscanf( ins, "%255s%255s%5s%255s", seqName, seq, temp, qual);
            if(keepGoing > 0){
                fprintf(fo1, "%s\n%s\n+\n%s\n", seqName, seq, qual);
                keepGoing = fscanf( ins, "%255s%255s%5s%255s", seqName, seq, temp, qual);
                fprintf(fo2, "%s\n%s\n+\n%s\n", seqName, seq, qual);
            }
        }
        fclose(fo1);
        fclose(fo2);
        fclose(ins);
    }else{
        while(keepGoing > 0){
            // first read
            keepGoing = fscanf( ins, "%255s%255s", seqName, seq);
            if(keepGoing > 0){
                fprintf(fo1, "%s\n%s\n", seqName, seq);
                keepGoing = fscanf( ins, "%255s%255s", seqName, seq);
                fprintf(fo2, "%s\n%s\n", seqName, seq);
            }
        }
        fclose(fo1);
        fclose(fo2);
        fclose(ins);
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rsi, %r14
movl %edi, %ebp
movq (%rsi), %rbx
movq %rbx, 0x2e93(%rip)      # 0x4070
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x1060
testq %rax, %rax
je 0x11fc
incq %rax
movq %rax, 0x2e77(%rip)      # 0x4070
movq %rax, %rbx
cmpl $0x1, %ebp
jg 0x1219
leaq 0xdfc(%rip), %rdi       # 0x2004
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1050
movl $0x1, %ebp
jmp 0x128c
movq 0x8(%r14), %rdi
cmpb $0x2d, (%rdi)
jne 0x122e
cmpb $0x68, 0x1(%rdi)
jne 0x122e
cmpb $0x0, 0x2(%rdi)
je 0x1279
leaq 0xe5d(%rip), %rsi       # 0x2092
callq 0x1070
testl %eax, %eax
je 0x1279
movl %ebp, %r13d
movq -0x8(%r14,%r13,8), %rsi
leaq 0xe4d(%rip), %rdi       # 0x209a
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
jne 0x12a0
movq 0x8(%r14), %rbx
leaq 0xe4f(%rip), %rsi       # 0x20b3
movq %rbx, %rdi
callq 0x1070
testl %eax, %eax
je 0x12a0
leaq 0xe40(%rip), %rdi       # 0x20b7
jmp 0x1280
leaq 0xd84(%rip), %rdi       # 0x2004
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1050
movl %ebp, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x8(%r14,%r13,8), %rdi
leaq 0xe25(%rip), %rsi       # 0x20d1
callq 0x1090
testq %rax, %rax
je 0x142f
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %r15
movaps %xmm0, (%r15)
xorl %eax, %eax
movl %eax, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movl $0x74726170, %ecx       # imm = 0x74726170
movl %ecx, (%r15)
movw $0x5f31, 0x4(%r15)      # imm = 0x5F31
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movl %eax, 0x60(%r12)
movaps %xmm0, 0x50(%r12)
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movl %ecx, (%r12)
movw $0x5f32, 0x4(%r12)      # imm = 0x5F32
movq -0x8(%r14,%r13,8), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x10a0
movq %r12, %rdi
movq %r14, %rsi
callq 0x10a0
leaq 0xda4(%rip), %r13       # 0x20f9
movq %r15, %rdi
movq %r13, %rsi
callq 0x1090
movq %rax, %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x1090
movq %r14, 0x10(%rsp)
testq %r14, %r14
setne %dl
movq %rax, 0x8(%rsp)
testq %rax, %rax
setne %cl
testb %cl, %dl
jne 0x13a3
leaq 0xd6c(%rip), %rdi       # 0x20fb
leaq 0x90(%rsp), %rsi
leaq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1050
cmpl $0x3, %ebp
jne 0x1440
leaq 0xd95(%rip), %r15       # 0x2148
leaq 0x300(%rsp), %r13
leaq 0x200(%rsp), %rbp
leaq 0xd89(%rip), %r12       # 0x2153
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1030
testl %eax, %eax
jle 0x1508
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1080
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1030
movl %eax, %r14d
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1080
testl %r14d, %r14d
jg 0x13ca
jmp 0x1508
movq -0x8(%r14,%r13,8), %rsi
leaq 0xc98(%rip), %rdi       # 0x20d3
jmp 0x120b
leaq 0xce2(%rip), %r14       # 0x2129
leaq 0x1b(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x300(%rsp), %rdx
leaq 0x200(%rsp), %rcx
movq %r15, %r8
leaq 0x100(%rsp), %r9
xorl %eax, %eax
callq 0x1030
testl %eax, %eax
jle 0x1508
movq 0x10(%rsp), %rdi
leaq 0xcb4(%rip), %rsi       # 0x213c
leaq 0x300(%rsp), %rbp
movq %rbp, %rdx
leaq 0x200(%rsp), %r12
movq %r12, %rcx
leaq 0x100(%rsp), %r13
movq %r13, %r8
xorl %eax, %eax
callq 0x1080
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x1030
movq %rbx, %r13
movq %r15, %rbx
movq %r14, %r15
movl %eax, %r14d
movq 0x8(%rsp), %rdi
leaq 0xc5b(%rip), %rsi       # 0x213c
movq %rbp, %rdx
movq %r12, %rcx
leaq 0x100(%rsp), %r8
xorl %eax, %eax
callq 0x1080
testl %r14d, %r14d
movq %r15, %r14
movq %rbx, %r15
movq %r13, %rbx
jg 0x144c
movq 0x10(%rsp), %rdi
callq 0x1040
movq 0x8(%rsp), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x1040
jmp 0x1212